diff --git a/vscode/src/extension.ts b/vscode/src/extension.ts index 04d958d..aa673ee 100644 --- a/vscode/src/extension.ts +++ b/vscode/src/extension.ts @@ -21,9 +21,11 @@ export const warningDecorationType = vscode.window.createTextEditorDecorationTyp let currentDecoration = warningDecorationType; let ranges: ComposedSmell[] = []; let hovers: vscode.Disposable[] = []; +let collection: vscode.DiagnosticCollection; export function activate(context: vscode.ExtensionContext) { console.info('[SMELLY] smelly-test is now active!'); + collection = vscode.languages.createDiagnosticCollection("smelly"); vscode.window.onDidChangeActiveTextEditor(() => { generateHighlighting(); @@ -55,9 +57,13 @@ function drawHover(context: vscode.ExtensionContext) { ranges.forEach(({ range, smell }) => { const disposableHover = vscode.languages.registerHoverProvider(['javascript'], { provideHover(document, position, token) { + const contents = new vscode.MarkdownString(smell.description); + contents.supportHtml = true; + contents.isTrusted = true; + if (range.contains(position)) { return { - contents: [smell.description], + contents: [contents], range }; } @@ -67,6 +73,26 @@ function drawHover(context: vscode.ExtensionContext) { hovers.push(disposableHover); context.subscriptions.push(disposableHover); }); + + populateDiagnosticPanel(); +} + +function populateDiagnosticPanel() { + const uri = vscode.window.activeTextEditor?.document.uri; + + if (uri) { + const diagnosticCollection = ranges.map((smell) => { + const diagnostic: vscode.Diagnostic = { + severity: vscode.DiagnosticSeverity.Warning, + range: smell.range, + message: smell.smell.diagnostic, + source: 'smelly-test' + }; + return diagnostic; + }); + + collection.set(uri, diagnosticCollection); + } } function generateHighlighting() { diff --git a/vscode/src/modules/smells-detector.ts b/vscode/src/modules/smells-detector.ts index 8cde392..f7fba89 100644 --- a/vscode/src/modules/smells-detector.ts +++ b/vscode/src/modules/smells-detector.ts @@ -23,8 +23,8 @@ export class SmellDetector { lineEnd: statement.loc.end.line, startAt: statement.loc.start.column, endsAt: statement.loc.end.column, - description: `Smelly: Avoid Conditional Test Logic in the test. Having conditional logic points to a test case that - requires different context to run. Split the test case to fit one context per test case.` + description: `Smelly: Avoid Conditional Test Logic in the test. Having conditional logic points to a test case that requires different context to run. Split the test case to fit one context per test case.`, + diagnostic: `Smelly: Avoid Conditional Test Logic in the test. Having conditional logic points to a test case that requires different context to run. Split the test case to fit one context per test case.`, }); } @@ -37,8 +37,8 @@ export class SmellDetector { lineEnd: statement.loc.end.line, startAt: statement.loc.start.column, endsAt: statement.loc.end.column, - description: `Smelly: Avoid Conditional Test Logic in the test. Having conditional logic points to a test case that - requires different context to run. Split the test case to fit one context per test case.` + description: `Smelly: Avoid Conditional Test Logic in the test. Having conditional logic points to a test case that requires different context to run. Split the test case to fit one context per test case.`, + diagnostic: `Smelly: Avoid Conditional Test Logic in the test. Having conditional logic points to a test case that requires different context to run. Split the test case to fit one context per test case.` }); } diff --git a/vscode/src/modules/types.ts b/vscode/src/modules/types.ts index d755471..9febbe5 100644 --- a/vscode/src/modules/types.ts +++ b/vscode/src/modules/types.ts @@ -5,4 +5,5 @@ export type Smell = { startAt: number; endsAt: number; description: string; //supports markdown + diagnostic: string; //no support for markdown }; \ No newline at end of file