diff --git a/src/zigSetup.ts b/src/zigSetup.ts index 61f2439..d363296 100644 --- a/src/zigSetup.ts +++ b/src/zigSetup.ts @@ -121,7 +121,7 @@ async function checkUpdate(context: ExtensionContext) { async function getUpdatedVersion(context: ExtensionContext): Promise { const configuration = workspace.getConfiguration("zig"); - const zigPath = configuration.get("path"); + const zigPath = configuration.get("path"); if (zigPath) { const zigBinPath = vscode.Uri.joinPath(context.globalStorageUri, "zig_install", "zig").fsPath; if (!zigPath.startsWith(zigBinPath)) return null; @@ -156,29 +156,31 @@ export async function setupZig(context: ExtensionContext) { }); if (!context.globalState.get("initialSetupDone")) { - await initialSetup(context); - await context.globalState.update("initialSetupDone", true); + await context.globalState.update("initialSetupDone", + await initialSetup(context) + ); } - const configuration = workspace.getConfiguration("zig", null); - if (configuration.get("path") === null) return; + const configuration = workspace.getConfiguration("zig"); + if (!configuration.get("path")) return; if (!configuration.get("checkForUpdate")) return; if (!shouldCheckUpdate(context, "zigUpdate")) return; await checkUpdate(context); } -async function initialSetup(context: ExtensionContext) { - const zigConfig = workspace.getConfiguration("zig", null); +async function initialSetup(context: ExtensionContext): Promise { + const zigConfig = workspace.getConfiguration("zig"); const zigResponse = await window.showInformationMessage( "Zig path hasn't been set, do you want to specify the path or install Zig?", + { modal: true }, "Install", "Specify path", "Use Zig in PATH" ); if (zigResponse === "Install") { await selectVersionAndInstall(context); - const configuration = workspace.getConfiguration("zig", null); - const path = configuration.get("path"); - if (!path) return; + const configuration = workspace.getConfiguration("zig"); + const path = configuration.get("path"); + if (!path) return false; window.showInformationMessage(`Zig was installed at '${path}', add it to PATH to use it from the terminal`); } else if (zigResponse === "Specify path") { const uris = await window.showOpenDialog({ @@ -187,21 +189,22 @@ async function initialSetup(context: ExtensionContext) { canSelectMany: false, title: "Select Zig executable", }); - if (!uris) return; + if (!uris) return false; const buffer = child_process.execFileSync(uris[0].path, ["version"]); const version = semver.parse(buffer.toString("utf8")); - if (!version) return; + if (!version) return false; await zigConfig.update("path", uris[0].path, true); } else if (zigResponse === "Use Zig in PATH") { await zigConfig.update("path", "", true); - } else return; + } else return false; - const zlsConfig = workspace.getConfiguration("zig.zls", null); + const zlsConfig = workspace.getConfiguration("zig.zls"); const zlsResponse = await window.showInformationMessage( "We recommend enabling ZLS (the Zig Language Server) for a better editing experience. Would you like to install it?", - "Install", "Specify path", "Use ZLS in PATH", "Ignore" + { modal: true }, + "Install", "Specify path", "Use ZLS in PATH" ); if (zlsResponse === "Install") { @@ -213,14 +216,16 @@ async function initialSetup(context: ExtensionContext) { canSelectMany: false, title: "Select Zig Language Server (ZLS) executable", }); - if (!uris) return; + if (!uris) return true; const buffer = child_process.execFileSync(uris[0].path, ["--version"]); const version = semver.parse(buffer.toString("utf8")); - if (!version) return; + if (!version) return true; await zlsConfig.update("path", uris[0].path, true); } else if (zlsResponse === "Use ZLS in PATH") { await zlsConfig.update("path", "", true); } + + return true; } diff --git a/src/zigUtil.ts b/src/zigUtil.ts index 9838a28..8bab7e3 100644 --- a/src/zigUtil.ts +++ b/src/zigUtil.ts @@ -186,7 +186,7 @@ export function getExePath(exePath: string | null, exeName: string, optionName: export function getZigPath(): string { const configuration = workspace.getConfiguration("zig"); - const zigPath = configuration.get("path"); + const zigPath = configuration.get("path"); return getExePath(zigPath, "zig", "zig.path"); } diff --git a/src/zls.ts b/src/zls.ts index 35d48f4..2b1093d 100644 --- a/src/zls.ts +++ b/src/zls.ts @@ -90,7 +90,7 @@ export async function stopClient() { // returns the file system path to the zls executable export function getZLSPath(): string { const configuration = workspace.getConfiguration("zig.zls"); - const zlsPath = configuration.get("path"); + const zlsPath = configuration.get("path"); return getExePath(zlsPath, "zls", "zig.zls.path"); } @@ -124,8 +124,8 @@ async function getVersionIndex(): Promise { async function checkUpdate(context: ExtensionContext) { const configuration = workspace.getConfiguration("zig.zls"); const zlsPath = configuration.get("path"); - const zigBinPath = vscode.Uri.joinPath(context.globalStorageUri, "zls_install", "zls").fsPath; - if (!zlsPath.startsWith(zigBinPath)) return; + const zlsBinPath = vscode.Uri.joinPath(context.globalStorageUri, "zls_install", "zls").fsPath; + if (!zlsPath.startsWith(zlsBinPath)) return; // get current version const buffer = child_process.execFileSync(zlsPath, ["--version"]); @@ -235,9 +235,9 @@ async function openConfig() { } function checkInstalled(): boolean { - const zlsPath = workspace.getConfiguration("zig.zls").get("path"); - if (zlsPath === null) window.showErrorMessage("This command cannot be run without setting 'zig.zls.path'."); - return zlsPath !== null; + const zlsPath = workspace.getConfiguration("zig.zls").get("path"); + if (!zlsPath) window.showErrorMessage("This command cannot be run without setting 'zig.zls.path'.", { modal: true }); + return !!zlsPath; } export async function activate(context: ExtensionContext) { @@ -246,7 +246,7 @@ export async function activate(context: ExtensionContext) { vscode.commands.registerCommand("zig.zls.install", async () => { const zigPath = workspace.getConfiguration("zig").get("path"); if (zigPath === null) { - window.showErrorMessage("This command cannot be run without setting 'zig.path'."); + window.showErrorMessage("This command cannot be run without setting 'zig.path'.", { modal: true }); return; }