Skip to content

Commit f39f7ed

Browse files
committed
src/goVulncheck: add "Current Module" option
When users need to scan vulnerabilities of a module located not in the workspace root, they can use this option - which infer the module root directory by running `go env GOMOD`. Change-Id: I70126de30fc4cc08a7207ab4a74a12f6290ccba1 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/429476 Reviewed-by: Suzy Mueller <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]> TryBot-Result: kokoro <[email protected]>
1 parent 62516a4 commit f39f7ed

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/goVulncheck.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export class VulncheckProvider {
223223
}
224224

225225
private async runInternal(goCtx: GoExtensionContext) {
226-
const pick = await vscode.window.showQuickPick(['Current Package', 'Workspace']);
226+
const pick = await vscode.window.showQuickPick(['Current Package', 'Current Module', 'Workspace']);
227227
let dir, pattern: string;
228228
const document = vscode.window.activeTextEditor?.document;
229229
switch (pick) {
@@ -241,6 +241,14 @@ export class VulncheckProvider {
241241
dir = path.dirname(document.fileName);
242242
pattern = '.';
243243
break;
244+
case 'Current Module':
245+
dir = await moduleDir(document);
246+
if (!dir) {
247+
vscode.window.showErrorMessage('vulncheck error: no current module');
248+
return;
249+
}
250+
pattern = './...';
251+
break;
244252
case 'Workspace':
245253
dir = await this.activeDir();
246254
pattern = './...';
@@ -308,6 +316,18 @@ export class VulncheckProvider {
308316
}
309317
}
310318

319+
async function moduleDir(document: vscode.TextDocument | undefined) {
320+
const docDir = document && document.fileName && path.dirname(document.fileName);
321+
if (!docDir) {
322+
return;
323+
}
324+
const modFile = await getGoModFile(vscode.Uri.file(docDir));
325+
if (!modFile) {
326+
return;
327+
}
328+
return path.dirname(modFile);
329+
}
330+
311331
// run `gopls vulncheck`.
312332
export async function vulncheck(
313333
goCtx: GoExtensionContext,

0 commit comments

Comments
 (0)