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

Commit 51ead57

Browse files
soorya-uVexu
authored andcommitted
fix: fixed codelens placement for main and test blocks
1 parent ecbd823 commit 51ead57

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/zigMainCodeLens.ts

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

19-
const mainRegex = /^(?!\s*\/\/\/?\s*)\s*pub\s+fn\s+main\s*\(/gm;
19+
const mainRegex = /^(?![ \t]*\/\/\/?\s*)[ \t]*pub\s+fn\s+main\s*\(/gm;
20+
2021
let match;
2122
while ((match = mainRegex.exec(text))) {
2223
const position = document.positionAt(match.index);
2324
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-
);
25+
26+
let targetLine = line.lineNumber + 1;
27+
const prevLineText = document.lineAt(targetLine - 1).text.trim();
28+
if (prevLineText) targetLine--;
29+
30+
const range = document.lineAt(targetLine).range;
31+
2932
codeLenses.push(
3033
new vscode.CodeLens(range, { title: "Run", command: "zig.run", arguments: [document.uri.fsPath] }),
3134
);

src/zigTestRunnerProvider.ts

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

73-
const regex = /^(?!\s*\/\/\/?\s*)\s*\btest\s+(?:"([^"]+)"|([A-Za-z0-9_][\w]*)|@"([^"]+)")\s*\{/gm;
73+
const regex = /^(?![ \t]*\/\/\/?\s*)[ \t]*\btest\s+(?:"([^"]+)"|([A-Za-z0-9_]\w*)|@"([^"]+)")\s*\{/gm;
74+
7475
const matches = Array.from(textDocument.getText().matchAll(regex));
7576
this.deleteTestForAFile(textDocument.uri);
7677

@@ -79,11 +80,7 @@ export default class ZigTestRunnerProvider {
7980
const isDocTest = !match[1];
8081
const position = textDocument.positionAt(match.index);
8182
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-
);
83+
const range = textDocument.lineAt(line.lineNumber).range;
8784

8885
const fileName = path.basename(textDocument.uri.fsPath);
8986

0 commit comments

Comments
 (0)