Skip to content

Commit 5c0cf81

Browse files
committed
feat: add a way to dismiss missing tools warning
1 parent 1aac265 commit 5c0cf81

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export const MISE_OPEN_FILE = "mise.openFile";
1818
export const MISE_OPEN_LOGS = "mise.openLogs";
1919
export const MISE_OPEN_MENU = "mise.openMenu";
2020
export const MISE_MISSING_TOOLS_MENU = "mise.openMissingToolsMenu";
21+
export const MISE_DISMISS_MISSING_TOOLS_WARNING =
22+
"mise.dismissMissingToolsWarning";
2123
export const MISE_OPEN_EXTENSION_SETTINGS = "mise.openExtensionSettings";
2224
export const MISE_OPEN_TASK_DEFINITION = "mise.openTaskDefinition";
2325
export const MISE_OPEN_TOOL_DEFINITION = "mise.openToolDefinition";

src/extensionMenu.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import vscode from "vscode";
22
import {
3+
MISE_DISMISS_MISSING_TOOLS_WARNING,
34
MISE_DOCTOR,
45
MISE_INSTALL_ALL,
56
MISE_LIST_ALL_TOOLS,
@@ -127,14 +128,22 @@ export function createMenu(miseService: MiseService) {
127128
export const createMissingToolsMenu = () =>
128129
vscode.commands.registerCommand(MISE_MISSING_TOOLS_MENU, async () => {
129130
const pick = await vscode.window.showQuickPick(
130-
[{ label: "Install all missing tools" }],
131+
[
132+
{ label: "Install all missing tools" },
133+
{ label: "Ignore this warning" },
134+
],
131135
{ title: "Mise - Missing tools" },
132136
);
133137

134138
switch (pick?.label) {
135139
case "Install all missing tools":
136140
await vscode.commands.executeCommand(MISE_INSTALL_ALL);
137141
break;
142+
case "Ignore this warning":
143+
await vscode.commands.executeCommand(
144+
MISE_DISMISS_MISSING_TOOLS_WARNING,
145+
);
146+
break;
138147
default:
139148
break;
140149
}

src/miseExtension.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { createHash } from "node:crypto";
12
import { createCache } from "async-cache-dedupe";
23
import vscode, { MarkdownString } from "vscode";
34
import { version } from "../package.json";
45
import {
56
MISE_CONFIGURE_ALL_SKD_PATHS,
7+
MISE_DISMISS_MISSING_TOOLS_WARNING,
68
MISE_DOCTOR,
79
MISE_EDIT_SETTING,
810
MISE_FMT,
@@ -122,6 +124,33 @@ export class MiseExtension {
122124
);
123125
this.statusBarItem.command = MISE_OPEN_MENU;
124126

127+
context.subscriptions.push(
128+
vscode.commands.registerCommand(
129+
MISE_DISMISS_MISSING_TOOLS_WARNING,
130+
async () => {
131+
const tools = await this.miseService.getCurrentTools();
132+
const missingTools = tools.filter((tool) => !tool.installed);
133+
const hash = this.generateMissingToolsHash(missingTools);
134+
135+
const dismissedHashes = this.context.workspaceState.get<string[]>(
136+
"dismissedMissingToolsHashes",
137+
[],
138+
);
139+
140+
if (!dismissedHashes.includes(hash)) {
141+
dismissedHashes.push(hash);
142+
await context.workspaceState.update(
143+
"dismissedMissingToolsHashes",
144+
dismissedHashes,
145+
);
146+
}
147+
148+
this.missingToolBarItem.hide();
149+
logger.info("Dismissed missing tools warning");
150+
},
151+
),
152+
);
153+
125154
const tasksProvider = new MiseTasksProvider(this.miseService);
126155
const toolsProvider = new MiseToolsProvider(this.miseService);
127156
const envsProvider = new MiseEnvsProvider(this.miseService);
@@ -680,6 +709,19 @@ export class MiseExtension {
680709
return;
681710
}
682711

712+
const currentHash = this.generateMissingToolsHash(missingTools);
713+
const dismissedHashes = this.context.workspaceState.get<string[]>(
714+
"dismissedMissingToolsHashes",
715+
[],
716+
);
717+
718+
if (dismissedHashes.includes(currentHash)) {
719+
if (this.missingToolBarItem) {
720+
this.missingToolBarItem.hide();
721+
}
722+
return;
723+
}
724+
683725
if (!this.missingToolBarItem) {
684726
this.missingToolBarItem = vscode.window.createStatusBarItem(
685727
vscode.StatusBarAlignment.Left,
@@ -698,4 +740,12 @@ export class MiseExtension {
698740
this.missingToolBarItem.command = MISE_MISSING_TOOLS_MENU;
699741
});
700742
}
743+
744+
private generateMissingToolsHash(tools: MiseTool[]) {
745+
const hash = createHash("sha256");
746+
tools.forEach((tool) => {
747+
hash.update(tool.name + (tool.version || ""));
748+
});
749+
return hash.digest("hex");
750+
}
701751
}

0 commit comments

Comments
 (0)