Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit ecbd823

Browse files
authored
fix: removes code lens for commented main functions (#462)
* fix: removes code lens for commented main functions * fix: fixed the reported issue * fix: commented tests doesnt show up in test explorer
1 parent 29e3a73 commit ecbd823

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/zigMainCodeLens.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ export default class ZigMainCodeLensProvider implements vscode.CodeLensProvider
1616
const codeLenses: vscode.CodeLens[] = [];
1717
const text = document.getText();
1818

19-
const mainRegex = /pub\s+fn\s+main\s*\(/g;
19+
const mainRegex = /^(?!\s*\/\/\/?\s*)\s*pub\s+fn\s+main\s*\(/gm;
2020
let match;
2121
while ((match = mainRegex.exec(text))) {
2222
const position = document.positionAt(match.index);
23-
const range = new vscode.Range(position, position);
23+
const line = document.lineAt(position.line);
24+
const nextLine = Math.min(line.lineNumber + 1, document.lineCount - 1);
25+
const range = new vscode.Range(
26+
document.lineAt(nextLine).range.start,
27+
document.lineAt(nextLine).range.start,
28+
);
2429
codeLenses.push(
2530
new vscode.CodeLens(range, { title: "Run", command: "zig.run", arguments: [document.uri.fsPath] }),
2631
);

src/zigTestRunnerProvider.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,21 @@ export default class ZigTestRunnerProvider {
7070
private _updateTestItems(textDocument: vscode.TextDocument) {
7171
if (textDocument.languageId !== "zig") return;
7272

73-
const regex = /\btest\s+(?:"([^"]+)"|([a-zA-Z0-9_][\w]*)|@"([^"]+)")\s*\{/g;
73+
const regex = /^(?!\s*\/\/\/?\s*)\s*\btest\s+(?:"([^"]+)"|([A-Za-z0-9_][\w]*)|@"([^"]+)")\s*\{/gm;
7474
const matches = Array.from(textDocument.getText().matchAll(regex));
7575
this.deleteTestForAFile(textDocument.uri);
7676

7777
for (const match of matches) {
7878
const testDesc = match[1] || match[2] || match[3];
7979
const isDocTest = !match[1];
8080
const position = textDocument.positionAt(match.index);
81-
const range = new vscode.Range(position, position.translate(0, match[0].length));
81+
const line = textDocument.lineAt(position.line);
82+
const nextLine = Math.min(line.lineNumber + 1, textDocument.lineCount - 1);
83+
const range = new vscode.Range(
84+
textDocument.lineAt(nextLine).range.start,
85+
textDocument.lineAt(nextLine).range.start,
86+
);
87+
8288
const fileName = path.basename(textDocument.uri.fsPath);
8389

8490
// Add doctest prefix to handle scenario where test name matches one with non doctest. E.g `test foo` and `test "foo"`

0 commit comments

Comments
 (0)