Skip to content

Commit e01cc4b

Browse files
committed
src/goVulncheck: prevent concurrent command execution
And fixed - The line number from gopls is 0-based. Fix that before printing in the output channel. - The file name may be missing if the file is a generated file, and most likely the line number is bogus too. - Adjust nesting to handle deep call stacks. For #2096 Change-Id: I37d067bcedfe5a5618388cb723a32d0b5c54d317 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/402194 Reviewed-by: Suzy Mueller <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 6a4ca67 commit e01cc4b

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/goVulncheck.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,22 @@ export class VulncheckProvider {
2525

2626
constructor(private channel: vscode.OutputChannel) {}
2727

28+
private running = false;
29+
2830
async run() {
31+
if (this.running) {
32+
vscode.window.showWarningMessage('another vulncheck is in progress');
33+
return;
34+
}
35+
try {
36+
this.running = true;
37+
await this.runInternal();
38+
} finally {
39+
this.running = false;
40+
}
41+
}
42+
43+
private async runInternal() {
2944
const pick = await vscode.window.showQuickPick(['Current Package', 'Workspace']);
3045
let dir, pattern: string;
3146
const filename = vscode.window.activeTextEditor?.document?.fileName;
@@ -112,22 +127,30 @@ ${renderStack(v)}`;
112127
const renderStack = (v: Vuln) => {
113128
const content = [];
114129
for (const stack of v.CallStacks ?? []) {
115-
for (const [i, line] of stack.entries()) {
116-
const pad = Array.from('\t\t'.repeat(i)).join('');
117-
content.push(`${pad}${line.Name}\n${pad}\t${renderUri(line)}`);
130+
for (const [, line] of stack.entries()) {
131+
content.push(`\t${line.Name}`);
132+
const loc = renderUri(line);
133+
if (loc) {
134+
content.push(`\t\t${loc}`);
135+
}
118136
}
119137
content.push('');
120138
}
121139
return content.join('\n');
122140
};
123141

124142
const renderUri = (stack: CallStack) => {
143+
if (!stack.URI) {
144+
// generated file or dummy location may not have a file name.
145+
return '';
146+
}
125147
const parsed = vscode.Uri.parse(stack.URI);
148+
const line = stack.Pos.line + 1; // Position uses 0-based line number.
126149
const folder = vscode.workspace.getWorkspaceFolder(parsed);
127150
if (folder) {
128-
return `${parsed.path}:${stack.Pos.line}:${stack.Pos.character}`;
151+
return `${parsed.path}:${line}:${stack.Pos.character}`;
129152
}
130-
return `${stack.URI}#${stack.Pos.line}:${stack.Pos.character}`;
153+
return `${stack.URI}#${line}:${stack.Pos.character}`;
131154
};
132155

133156
interface VulncheckReponse {

0 commit comments

Comments
 (0)