Skip to content

Commit

Permalink
do not allow *.path options to be null
Browse files Browse the repository at this point in the history
Allowing the values to be null disables setting the values in the settings UI.
  • Loading branch information
Vexu committed Apr 15, 2024
1 parent 658d245 commit 9ef473c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
12 changes: 2 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@
},
"zig.path": {
"scope": "machine-overridable",
"type": [
"string",
"null"
],
"default": null,
"type": "string",
"description": "Set a custom path to the Zig binary. The string \"zig\" means lookup zig in PATH."
},
"zig.checkForUpdate": {
Expand Down Expand Up @@ -162,11 +158,7 @@
},
"zig.zls.path": {
"scope": "machine-overridable",
"type": [
"string",
"null"
],
"default": null,
"type": "string",
"description": "Path to `zls` executable. Example: `C:/zls/zig-cache/bin/zls.exe`. The string \"zls\" means lookup ZLS in PATH.",
"format": "path"
},
Expand Down
3 changes: 0 additions & 3 deletions src/zigSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ async function initialSetup(context: vscode.ExtensionContext): Promise<boolean>
await zigConfig.update("path", "zig", true);
break;
case undefined:
await zigConfig.update("path", undefined, true);
return false;
}
}
Expand Down Expand Up @@ -342,8 +341,6 @@ async function initialSetup(context: vscode.ExtensionContext): Promise<boolean>
await zlsConfig.update("path", "zls", true);
break;
case undefined:
// explicitly set `zig.zls.path` to null so it is visible in the `settings.json`
await zlsConfig.update("path", null, true);
break;
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/zigUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export function handleConfigOption(input: string): string {
return input;
}

export function getExePath(exePath: string | null, exeName: string, optionName: string): string {
export function getExePath(exePath: string | null | undefined, exeName: string, optionName: string): string {
if (exePath === null) {
exePath = which.sync(exeName, { nothrow: true });
} else {
} else if (exePath !== undefined) {
// allow passing predefined variables
exePath = handleConfigOption(exePath);

Expand All @@ -64,7 +64,9 @@ export function getExePath(exePath: string | null, exeName: string, optionName:
}

let message;
if (exePath === null) {
if (exePath === undefined) {
message = `\`${optionName}\` has not been set; set it to \`"${exeName}"\` to use \`${exeName}\` in PATH`;
} else if (exePath === null) {
message = `Could not find ${exeName} in PATH`;
} else if (!fs.existsSync(exePath)) {
message = `\`${optionName}\` ${exePath} does not exist`;
Expand All @@ -82,7 +84,7 @@ export function getExePath(exePath: string | null, exeName: string, optionName:

export function getZigPath(): string {
const configuration = vscode.workspace.getConfiguration("zig");
const zigPath = configuration.get<string | null>("path", null);
const zigPath = configuration.get<string>("path");
const exePath = zigPath !== "zig" ? zigPath : null; // the string "zig" means lookup in PATH
return getExePath(exePath, "zig", "zig.path");
}
Expand Down
7 changes: 3 additions & 4 deletions src/zls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function stopClient() {
// returns the file system path to the zls executable
export function getZLSPath(): string {
const configuration = vscode.workspace.getConfiguration("zig.zls");
const zlsPath = configuration.get<string | null>("path", null);
const zlsPath = configuration.get<string>("path");
const exePath = zlsPath !== "zls" ? zlsPath : null; // the string "zls" means lookup in PATH
return getExePath(exePath, "zls", "zig.zls.path");
}
Expand Down Expand Up @@ -203,8 +203,7 @@ async function checkUpdate(context: vscode.ExtensionContext) {
const configuration = vscode.workspace.getConfiguration("zig.zls");
const zlsPath = configuration.get<string | null>("path", null);
const zlsBinPath = vscode.Uri.joinPath(context.globalStorageUri, "zls_install", "zls").fsPath;
if (!zlsPath) return;
if (!zlsPath.startsWith(zlsBinPath)) return;
if (!zlsPath?.startsWith(zlsBinPath)) return;

// get current version
const version = getVersion(zlsPath, "--version");
Expand Down Expand Up @@ -239,7 +238,7 @@ export async function install(context: vscode.ExtensionContext, ask: boolean) {
}
// Zig 0.9.0 was the first version to have a tagged zls release
if (semver.lt(zigVersion, "0.9.0")) {
if (zlsConfiguration.get("path")) {
if (zlsConfiguration.get("path") !== undefined) {
void vscode.window.showErrorMessage(`ZLS is not available for Zig version ${zigVersion.version}`);
}
await zlsConfiguration.update("path", undefined, true);
Expand Down

0 comments on commit 9ef473c

Please sign in to comment.