src/goVulncheck.ts: only run vulncheck for active editors of go files
Fixes golang/vscode-go#2223.
Change-Id: I8812b85d564e7f58880bcd94094bb4114cd36f3d
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/403774
TryBot-Result: kokoro <noreply+kokoro@google.com>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/src/goVulncheck.ts b/src/goVulncheck.ts
index 756e1af..fe173b4 100644
--- a/src/goVulncheck.ts
+++ b/src/goVulncheck.ts
@@ -43,14 +43,20 @@
private async runInternal() {
const pick = await vscode.window.showQuickPick(['Current Package', 'Workspace']);
let dir, pattern: string;
- const filename = vscode.window.activeTextEditor?.document?.fileName;
+ const document = vscode.window.activeTextEditor?.document;
switch (pick) {
case 'Current Package':
- if (!filename) {
+ if (!document) {
vscode.window.showErrorMessage('vulncheck error: no current package');
return;
}
- dir = path.dirname(filename);
+ if (document.languageId !== 'go') {
+ vscode.window.showErrorMessage(
+ 'File in the active editor is not a Go file, cannot find current package to check.'
+ );
+ return;
+ }
+ dir = path.dirname(document.fileName);
pattern = '.';
break;
case 'Workspace':