Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/zigMainCodeLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ export default class ZigMainCodeLensProvider implements vscode.CodeLensProvider
const codeLenses: vscode.CodeLens[] = [];
const text = document.getText();

const mainRegex = /pub\s+fn\s+main\s*\(/g;
const mainRegex = /^(?!\s*\/\/\/?\s*)\s*pub\s+fn\s+main\s*\(/gm;
let match;
while ((match = mainRegex.exec(text))) {
const position = document.positionAt(match.index);
const range = new vscode.Range(position, position);
const line = document.lineAt(position.line);
const nextLine = Math.min(line.lineNumber + 1, document.lineCount - 1);
const range = new vscode.Range(
document.lineAt(nextLine).range.start,
document.lineAt(nextLine).range.start,
);
codeLenses.push(
new vscode.CodeLens(range, { title: "Run", command: "zig.run", arguments: [document.uri.fsPath] }),
);
Expand Down
10 changes: 8 additions & 2 deletions src/zigTestRunnerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,21 @@ export default class ZigTestRunnerProvider {
private _updateTestItems(textDocument: vscode.TextDocument) {
if (textDocument.languageId !== "zig") return;

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

for (const match of matches) {
const testDesc = match[1] || match[2] || match[3];
const isDocTest = !match[1];
const position = textDocument.positionAt(match.index);
const range = new vscode.Range(position, position.translate(0, match[0].length));
const line = textDocument.lineAt(position.line);
const nextLine = Math.min(line.lineNumber + 1, textDocument.lineCount - 1);
const range = new vscode.Range(
textDocument.lineAt(nextLine).range.start,
textDocument.lineAt(nextLine).range.start,
);

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

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