Skip to content

Commit

Permalink
src/goMain: use lint tool's name as the lint diagnostic collection name
Browse files Browse the repository at this point in the history
Fixes golang#948

Change-Id: I997d94eacd6b078da30174477700c5f2ee06c758
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/276972
Trust: Hyang-Ah Hana Kim <[email protected]>
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Suzy Mueller <[email protected]>
  • Loading branch information
hyangah committed Feb 18, 2021
1 parent e760407 commit 30b086f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/goLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function lintCode(scope?: string) {

goLint(documentUri, goConfig, scope)
.then((warnings) => {
handleDiagnosticErrors(editor ? editor.document : null, warnings, lintDiagnosticCollection);
handleDiagnosticErrors(editor ? editor.document : null, warnings, lintDiagnosticCollection, 'go-lint');
diagnosticsStatusBarItem.hide();
})
.catch((err) => {
Expand Down
20 changes: 19 additions & 1 deletion src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ If you would like additional configuration for diagnostics from gopls, please se

buildDiagnosticCollection = vscode.languages.createDiagnosticCollection('go');
ctx.subscriptions.push(buildDiagnosticCollection);
lintDiagnosticCollection = vscode.languages.createDiagnosticCollection('go-lint');
lintDiagnosticCollection = vscode.languages.createDiagnosticCollection(
lintDiagnosticCollectionName(getGoConfig()['lintTool'])
);
ctx.subscriptions.push(lintDiagnosticCollection);
vetDiagnosticCollection = vscode.languages.createDiagnosticCollection('go-vet');
ctx.subscriptions.push(vetDiagnosticCollection);
Expand Down Expand Up @@ -471,6 +473,15 @@ If you would like additional configuration for diagnostics from gopls, please se
});
}
}
if (e.affectsConfiguration('go.lintTool')) {
const lintTool = lintDiagnosticCollectionName(updatedGoConfig['lintTool']);
if (lintDiagnosticCollection && lintDiagnosticCollection.name !== lintTool) {
lintDiagnosticCollection.dispose();
lintDiagnosticCollection = vscode.languages.createDiagnosticCollection(lintTool);
ctx.subscriptions.push(lintDiagnosticCollection);
// TODO: actively maintain our own disposables instead of keeping pushing to ctx.subscription.
}
}
})
);

Expand Down Expand Up @@ -947,3 +958,10 @@ async function getConfiguredGoToolsCommand() {
}
}
}

function lintDiagnosticCollectionName(lintToolName: string) {
if (!lintToolName || lintToolName === 'golint') {
return 'go-lint';
}
return `go-${lintToolName}`;
}
6 changes: 4 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,8 @@ export function runTool(
export function handleDiagnosticErrors(
document: vscode.TextDocument,
errors: ICheckResult[],
diagnosticCollection: vscode.DiagnosticCollection
diagnosticCollection: vscode.DiagnosticCollection,
diagnosticSource?: string
) {
diagnosticCollection.clear();

Expand Down Expand Up @@ -891,7 +892,8 @@ export function handleDiagnosticErrors(
const range = new vscode.Range(error.line - 1, startColumn, error.line - 1, endColumn);
const severity = mapSeverityToVSCodeSeverity(error.severity);
const diagnostic = new vscode.Diagnostic(range, error.msg, severity);
diagnostic.source = diagnosticCollection.name;
// vscode uses source for deduping diagnostics.
diagnostic.source = diagnosticSource || diagnosticCollection.name;
let diagnostics = diagnosticMap.get(canonicalFile);
if (!diagnostics) {
diagnostics = [];
Expand Down

0 comments on commit 30b086f

Please sign in to comment.