Skip to content

Commit

Permalink
fix formatter initialization when Zig executable is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Sep 24, 2024
1 parent ff6fc57 commit 1c15fb0
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/zigFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,24 @@ function preCompileZigFmt() {
// This pre-compiles even if "zig.formattingProvider" is "zls".
if (vscode.workspace.getConfiguration("zig").get<string>("formattingProvider") === "off") return;

childProcess.execFile(getZigPath(), ["fmt", "--help"], {
timeout: 60000, // 60 seconds (this is a very high value because 'zig fmt' is just in time compiled)
});
let zigPath: string;
try {
zigPath = getZigPath();
} catch {
return;
}

try {
childProcess.execFile(zigPath, ["fmt", "--help"], {
timeout: 60000, // 60 seconds (this is a very high value because 'zig fmt' is just in time compiled)
});
} catch (err) {
if (err instanceof Error) {
void vscode.window.showErrorMessage(`Failed to run 'zig fmt': ${err.message}`);
} else {
throw err;
}
}
}

async function provideDocumentRangeFormattingEdits(
Expand Down

0 comments on commit 1c15fb0

Please sign in to comment.