Skip to content

Commit

Permalink
src/goLint: handle the case where no editor is active
Browse files Browse the repository at this point in the history
When lint runs in workspace scope, the editor doesn't have to
be open.  Rearranged the if conditions, so the extension does
not have to attempt to access editor.document.languageId
unnecessarily.

And, use the diagnostic collection names as the source names,
instead of `go-lint` - this was missed when fixing
#948.

Fixes #1520
Updates #948

Change-Id: I166a78604097c57ad64313c705a3c2ddce9736ca
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/321841
Trust: Hyang-Ah Hana Kim <[email protected]>
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Rebecca Stambler <[email protected]>
  • Loading branch information
hyangah committed May 25, 2021
1 parent c5070dc commit 4cb78f6
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/goLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ import { getWorkspaceFolderPath, handleDiagnosticErrors, ICheckResult, resolvePa
*/
export function lintCode(scope?: string) {
const editor = vscode.window.activeTextEditor;
if (!editor && scope !== 'workspace') {
vscode.window.showInformationMessage('No editor is active, cannot find current package to lint');
return;
}
if (editor.document.languageId !== 'go' && scope !== 'workspace') {
vscode.window.showInformationMessage(
'File in the active editor is not a Go file, cannot find current package to lint'
);
return;
if (scope !== 'workspace') {
if (!editor) {
vscode.window.showInformationMessage('No editor is active, cannot find current package to lint');
return;
}
if (editor.document.languageId !== 'go') {
vscode.window.showInformationMessage(
'File in the active editor is not a Go file, cannot find current package to lint'
);
return;
}
}

const documentUri = editor ? editor.document.uri : null;
Expand All @@ -37,7 +39,7 @@ export function lintCode(scope?: string) {

goLint(documentUri, goConfig, goplsConfig, scope)
.then((warnings) => {
handleDiagnosticErrors(editor ? editor.document : null, warnings, lintDiagnosticCollection, 'go-lint');
handleDiagnosticErrors(editor ? editor.document : null, warnings, lintDiagnosticCollection);
diagnosticsStatusBarItem.hide();
})
.catch((err) => {
Expand Down

0 comments on commit 4cb78f6

Please sign in to comment.