diff --git a/eslint.config.mjs b/eslint.config.mjs index fbb3cb9..8ea94dd 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -9,6 +9,7 @@ export default tseslint.config({ rules: { ...prettierConfig.rules, "@typescript-eslint/naming-convention": "error", + "@typescript-eslint/switch-exhaustiveness-check": "error", eqeqeq: "error", "no-throw-literal": "off", "@typescript-eslint/only-throw-error": "error", diff --git a/src/zigSetup.ts b/src/zigSetup.ts index 0d14829..51f2832 100644 --- a/src/zigSetup.ts +++ b/src/zigSetup.ts @@ -163,8 +163,13 @@ async function checkUpdate(context: vscode.ExtensionContext) { "Install", "Ignore", ); - if (response === "Install") { - await install(context, update); + switch (response) { + case "Install": + await install(context, update); + break; + case "Ignore": + case undefined: + break; } } catch (err) { if (err instanceof Error) { @@ -235,31 +240,34 @@ async function initialSetup(context: vscode.ExtensionContext): Promise "Specify path", "Use Zig in PATH", ); - - if (zigResponse === "Install") { - await selectVersionAndInstall(context); - const path = zigConfig.get("path"); - if (!path) return false; - void vscode.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 vscode.window.showOpenDialog({ - canSelectFiles: true, - canSelectFolders: false, - canSelectMany: false, - title: "Select Zig executable", - }); - if (!uris) return false; - - const version = getVersion(uris[0].path, "version"); - 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 false; + switch (zigResponse) { + case "Install": + await selectVersionAndInstall(context); + const path = zigConfig.get("path"); + if (!path) return false; + void vscode.window.showInformationMessage( + `Zig was installed at '${path}', add it to PATH to use it from the terminal`, + ); + break; + case "Specify path": + const uris = await vscode.window.showOpenDialog({ + canSelectFiles: true, + canSelectFolders: false, + canSelectMany: false, + title: "Select Zig executable", + }); + if (!uris) return false; + + const version = getVersion(uris[0].path, "version"); + if (!version) return false; + + await zigConfig.update("path", uris[0].path, true); + break; + case "Use Zig in PATH": + await zigConfig.update("path", "", true); + break; + case undefined: + return false; } } @@ -274,20 +282,25 @@ async function initialSetup(context: vscode.ExtensionContext): Promise "Use ZLS in PATH", ); - if (zlsResponse === "Install") { - await installZLS(context, false); - } else if (zlsResponse === "Specify path") { - const uris = await vscode.window.showOpenDialog({ - canSelectFiles: true, - canSelectFolders: false, - canSelectMany: false, - title: "Select Zig Language Server (ZLS) executable", - }); - if (!uris) return true; - - await zlsConfig.update("path", uris[0].path, true); - } else if (zlsResponse === "Use ZLS in PATH") { - await zlsConfig.update("path", "", true); + switch (zlsResponse) { + case "Install": + await installZLS(context, false); + break; + case "Specify path": + const uris = await vscode.window.showOpenDialog({ + canSelectFiles: true, + canSelectFolders: false, + canSelectMany: false, + title: "Select Zig Language Server (ZLS) executable", + }); + if (!uris) return true; + + await zlsConfig.update("path", uris[0].path, true); + case "Use ZLS in PATH": + await zlsConfig.update("path", "", true); + break; + case undefined: + break; } } diff --git a/src/zls.ts b/src/zls.ts index 7a83a17..4697571 100644 --- a/src/zls.ts +++ b/src/zls.ts @@ -145,8 +145,13 @@ async function checkUpdate(context: vscode.ExtensionContext) { if (semver.gte(version, latestVersion)) return; const response = await vscode.window.showInformationMessage("New version of ZLS available", "Install", "Ignore"); - if (response === "Install") { - await installVersion(context, latestVersion); + switch (response) { + case "Install": + await installVersion(context, latestVersion); + break; + case "Ignore": + case undefined: + break; } } @@ -174,11 +179,14 @@ export async function install(context: vscode.ExtensionContext, ask: boolean) { "Install", "Ignore", ); - - if (result === undefined) return; - if (result === "Ignore") { - await zlsConfiguration.update("path", undefined, true); - return; + switch (result) { + case "Install": + break; + case "Ignore": + await zlsConfiguration.update("path", undefined, true); + return; + case undefined: + return; } } let zlsVersion: semver.SemVer;