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

Commit 6b6ef1e

Browse files
committed
more accurately resolve the workspace folder in handleConfigOption
These changes may matter when there are none or multiple workspace folders.
1 parent 365690c commit 6b6ef1e

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/zigDiagnosticsProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export default class ZigDiagnosticsProvider {
160160
if (!buildFilePath) break;
161161
processArg.push("--build-file");
162162
try {
163-
processArg.push(path.resolve(handleConfigOption(buildFilePath)));
163+
processArg.push(path.resolve(handleConfigOption(buildFilePath, workspaceFolder)));
164164
} catch {
165165
//
166166
}

src/zigUtil.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ import which from "which";
1414
* Replace any references to predefined variables in config string.
1515
* https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables
1616
*/
17-
export function handleConfigOption(input: string): string {
17+
export function handleConfigOption(input: string, workspaceFolder: vscode.WorkspaceFolder | "none" | "guess"): string {
1818
if (input.includes("${userHome}")) {
1919
input = input.replaceAll("${userHome}", os.homedir());
2020
}
2121

22-
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
23-
input = input.replaceAll("${workspaceFolder}", vscode.workspace.workspaceFolders[0].uri.fsPath);
24-
input = input.replaceAll("${workspaceFolderBasename}", vscode.workspace.workspaceFolders[0].name);
22+
if (workspaceFolder === "guess") {
23+
workspaceFolder = vscode.workspace.workspaceFolders?.length ? vscode.workspace.workspaceFolders[0] : "none";
24+
}
25+
26+
if (workspaceFolder !== "none") {
27+
input = input.replaceAll("${workspaceFolder}", workspaceFolder.uri.fsPath);
28+
input = input.replaceAll("${workspaceFolderBasename}", workspaceFolder.name);
29+
} else {
30+
// This may end up reporting a confusing error message.
2531
}
2632

2733
const document = vscode.window.activeTextEditor?.document;
@@ -68,7 +74,7 @@ export function resolveExePathAndVersion(
6874
assert(cmd.length);
6975

7076
// allow passing predefined variables
71-
cmd = handleConfigOption(cmd);
77+
cmd = handleConfigOption(cmd, "guess");
7278

7379
if (cmd.startsWith("~")) {
7480
cmd = path.join(os.homedir(), cmd.substring(1));

src/zls.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ function configurationMiddleware(params: ConfigurationParams): LSPAny[] | Respon
169169
if (!param.section) return null;
170170

171171
let configuration: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("zig");
172+
let workspaceFolder: vscode.WorkspaceFolder | undefined;
172173
try {
173174
if (param.scopeUri) {
174175
const scopeUri = vscode.Uri.parse(param.scopeUri, true);
175176
configuration = vscode.workspace.getConfiguration("zig", scopeUri);
177+
workspaceFolder = vscode.workspace.getWorkspaceFolder(scopeUri);
176178
}
177179
} catch {}
178180

@@ -183,7 +185,7 @@ function configurationMiddleware(params: ConfigurationParams): LSPAny[] | Respon
183185

184186
if (typeof value === "string") {
185187
// Make sure that `""` gets converted to `undefined` and resolve predefined values
186-
value = value ? handleConfigOption(value) : undefined;
188+
value = value ? handleConfigOption(value, workspaceFolder ?? "guess") : undefined;
187189
} else if (typeof value === "object" && value !== null && !Array.isArray(value)) {
188190
// Recursively update the config options
189191
const newValue: Record<string, unknown> = {};

0 commit comments

Comments
 (0)