Skip to content

Commit

Permalink
chore: adds diagnose message to problems panel
Browse files Browse the repository at this point in the history
  • Loading branch information
marabesi committed Jun 28, 2024
1 parent a241af2 commit 5cde22b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
28 changes: 27 additions & 1 deletion vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
};
}
Expand All @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions vscode/src/modules/smells-detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
});
}

Expand All @@ -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.`
});
}

Expand Down
1 change: 1 addition & 0 deletions vscode/src/modules/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export type Smell = {
startAt: number;
endsAt: number;
description: string; //supports markdown
diagnostic: string; //no support for markdown
};

0 comments on commit 5cde22b

Please sign in to comment.