Skip to content

Commit

Permalink
enable switch-exhaustiveness-check
Browse files Browse the repository at this point in the history
This will ensure that when handling responses from the user,
all possible responses are exhaustiveness handled.
  • Loading branch information
Techatrix committed Apr 1, 2024
1 parent d7e48d7 commit 3a78297
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 48 deletions.
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
95 changes: 54 additions & 41 deletions src/zigSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -235,31 +240,34 @@ async function initialSetup(context: vscode.ExtensionContext): Promise<boolean>
"Specify path",
"Use Zig in PATH",
);

if (zigResponse === "Install") {
await selectVersionAndInstall(context);
const path = zigConfig.get<string>("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<string>("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;
}
}

Expand All @@ -274,20 +282,25 @@ async function initialSetup(context: vscode.ExtensionContext): Promise<boolean>
"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;
}
}

Expand Down
22 changes: 15 additions & 7 deletions src/zls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3a78297

Please sign in to comment.