Skip to content

Commit

Permalink
feat: Use a status bar item instead of a notification for missing tools
Browse files Browse the repository at this point in the history
  • Loading branch information
hverlin committed Jan 14, 2025
1 parent c9ef8ab commit e92824e
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 19 deletions.
8 changes: 8 additions & 0 deletions docs/src/content/docs/reference/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ Check if a new mise version is available on startup.

---

##### `mise.showNotificationIfMissingTools`
- **Type:** `boolean`
- **Default:** `true`

Show notification if tools are not installed.

---

##### `mise.updateEnvAutomatically`
- **Type:** `boolean`
- **Default:** `true`
Expand Down
25 changes: 20 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,36 +188,43 @@
"default": true,
"markdownDescription": "Check if a new mise version is available on startup."
},
"mise.updateEnvAutomatically": {
"mise.showNotificationIfMissingTools": {
"order": 11,
"type": "boolean",
"title": "Show notification if missing tools",
"default": true,
"markdownDescription": "Show notification if tools are not installed."
},
"mise.updateEnvAutomatically": {
"order": 12,
"type": "boolean",
"title": "Update environment variables automatically",
"default": true,
"markdownDescription": "Update VSCode and terminal environment variables automatically based on the mise configuration. Note that depending on the extensions loading order, other extensions might not see all mise environment variables."
},
"mise.updateOpenTerminalsEnvAutomatically": {
"order": 12,
"order": 13,
"type": "boolean",
"title": "Update terminal environment variables automatically",
"default": false,
"markdownDescription": "Update terminal environment variables automatically based on the mise configuration. This will send `unset` and `eval $(mise env)` commands to the terminal. If you don't enable this, you will need to restart the integrated terminals to get the new environment variables."
},
"mise.teraAutoCompletion": {
"order": 13,
"order": 14,
"type": "boolean",
"title": "Enable Tera auto-completion",
"default": true,
"markdownDescription": "Enable experimental Tera auto-completion in `mise.toml` files."
},
"mise.automaticallyTrustMiseConfigFiles": {
"order": 14,
"order": 15,
"type": "boolean",
"title": "Automatically trust mise config files",
"default": true,
"markdownDescription": "Automatically trust mise config files when opening them in a trusted worskspace."
},
"mise.commandTTLCacheSeconds": {
"order": 15,
"order": 16,
"type": "number",
"title": "Command TTL cache seconds",
"default": 2,
Expand Down Expand Up @@ -319,6 +326,10 @@
"command": "mise.openMenu",
"title": "Mise: Open Menu"
},
{
"command": "mise.openMissingToolsMenu",
"title": "Mise: Open Missing Tools Menu"
},
{
"command": "mise.openToolRepository",
"title": "Mise: Open Tool Repository"
Expand Down Expand Up @@ -474,6 +485,10 @@
{
"command": "mise.useToolTopMenu",
"when": "false"
},
{
"command": "mise.openMissingToolsMenu",
"when": "false"
}
],
"view/title": [
Expand Down
1 change: 1 addition & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const MISE_OPEN_ENV_VAR_DEFINITION = "mise.openEnvVariableDefinition";
export const MISE_OPEN_FILE = "mise.openFile";
export const MISE_OPEN_LOGS = "mise.openLogs";
export const MISE_OPEN_MENU = "mise.openMenu";
export const MISE_MISSING_TOOLS_MENU = "mise.openMissingToolsMenu";
export const MISE_OPEN_EXTENSION_SETTINGS = "mise.openExtensionSettings";
export const MISE_OPEN_TASK_DEFINITION = "mise.openTaskDefinition";
export const MISE_OPEN_TOOL_DEFINITION = "mise.openToolDefinition";
Expand Down
8 changes: 8 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const CONFIGURATION_FLAGS = {
teraAutoCompletion: "teraAutoCompletion",
automaticallyTrustMiseConfigFiles: "automaticallyTrustMiseConfigFiles",
commandTTLCacheSeconds: "commandTTLCacheSeconds",
showNotificationIfMissingTools: "showNotificationIfMissingTools",
} as const;

const getExtensionConfig = () => {
Expand Down Expand Up @@ -131,6 +132,13 @@ export const shouldAutomaticallyTrustMiseConfigFiles = () => {
);
};

export const shouldShowNotificationIfMissingTools = () => {
return getConfOrElse(
CONFIGURATION_FLAGS.showNotificationIfMissingTools,
true,
);
};

export const isTeraAutoCompletionEnabled = () => {
return getConfOrElse(CONFIGURATION_FLAGS.teraAutoCompletion, false);
};
Expand Down
18 changes: 18 additions & 0 deletions src/extensionMenu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import vscode from "vscode";
import {
MISE_INSTALL_ALL,
MISE_LIST_ALL_TOOLS,
MISE_MISSING_TOOLS_MENU,
MISE_OPEN_EXTENSION_SETTINGS,
MISE_OPEN_MENU,
MISE_RELOAD,
Expand Down Expand Up @@ -110,3 +112,19 @@ export function createMenu(miseService: MiseService) {
}
});
}

export const createMissingToolsMenu = () =>
vscode.commands.registerCommand(MISE_MISSING_TOOLS_MENU, async () => {
const pick = await vscode.window.showQuickPick(
[{ label: "Install all missing tools" }],
{ title: "Mise - Missing tools" },
);

switch (pick?.label) {
case "Install all missing tools":
await vscode.commands.executeCommand(MISE_INSTALL_ALL);
break;
default:
break;
}
});
57 changes: 43 additions & 14 deletions src/miseExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
MISE_CONFIGURE_ALL_SKD_PATHS,
MISE_EDIT_SETTING,
MISE_FMT,
MISE_INSTALL_ALL,
MISE_LIST_ALL_TOOLS,
MISE_MISSING_TOOLS_MENU,
MISE_OPEN_EXTENSION_SETTINGS,
MISE_OPEN_FILE,
MISE_OPEN_LOGS,
Expand All @@ -24,8 +24,9 @@ import {
isMiseExtensionEnabled,
shouldAutomaticallyTrustMiseConfigFiles,
shouldConfigureExtensionsAutomatically,
shouldShowNotificationIfMissingTools,
} from "./configuration";
import { createMenu } from "./extensionMenu";
import { createMenu, createMissingToolsMenu } from "./extensionMenu";
import { MiseFileWatcher } from "./miseFileWatcher";
import { MiseService } from "./miseService";
import { TaskDefinitionProvider } from "./providers/TaskDefinitionProvider";
Expand Down Expand Up @@ -58,6 +59,7 @@ import {
} from "./providers/toolsProvider";
import { VsCodeTaskProvider } from "./providers/vsCodeTaskProvider";
import { displayPathRelativeTo } from "./utils/fileUtils";
import { truncateStr } from "./utils/fn";
import { logger } from "./utils/logger";
import { allowedFileTaskDirs } from "./utils/miseUtilts";
import WebViewPanel from "./webviewPanel";
Expand All @@ -69,6 +71,11 @@ export class MiseExtension {
vscode.StatusBarAlignment.Left,
0,
);
private missingToolBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Left,
0,
);

private miseFileWatcher: MiseFileWatcher | undefined;

async activate(context: vscode.ExtensionContext) {
Expand Down Expand Up @@ -105,7 +112,10 @@ export class MiseExtension {
);
this.miseFileWatcher.initialize();

context.subscriptions.push(createMenu(this.miseService));
context.subscriptions.push(
createMenu(this.miseService),
createMissingToolsMenu(),
);
this.statusBarItem.command = MISE_OPEN_MENU;

const tasksProvider = new MiseTasksProvider(this.miseService);
Expand Down Expand Up @@ -622,21 +632,40 @@ export class MiseExtension {
}

private checkForMissingMiseTools() {
if (!isMiseExtensionEnabled()) {
return;
}

if (!shouldShowNotificationIfMissingTools()) {
return;
}

this.miseService.getCurrentTools().then(async (tools) => {
const missingTools = tools.filter((tool) => !tool.installed);
if (missingTools.length > 0) {
const selection = await vscode.window.showWarningMessage(
`Mise: Missing tools: ${missingTools
.map(
(tool) => tool.name + (tool.version ? ` (${tool.version})` : ""),
)
.join(", ")}`,
{ title: "Install missing tools", command: MISE_INSTALL_ALL },
);
if (selection?.command) {
await vscode.commands.executeCommand(selection.command);

if (!missingTools.length) {
if (this.missingToolBarItem) {
this.missingToolBarItem.hide();
}
return;
}

if (!this.missingToolBarItem) {
this.missingToolBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Left,
0,
);
}
const list = missingTools
.map((tool) => tool.name + (tool.version ? ` (${tool.version})` : ""))
.join(", ");

this.missingToolBarItem.text = `Missing tools: ${truncateStr(list, 50)}`;
this.missingToolBarItem.color = new vscode.ThemeColor("errorForeground");
this.missingToolBarItem.show();

this.missingToolBarItem.tooltip = "Mise: Click to install missing tools";
this.missingToolBarItem.command = MISE_MISSING_TOOLS_MENU;
});
}
}
7 changes: 7 additions & 0 deletions src/utils/fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ export function uniqBy<T>(array: T[], iteratee: (value: T) => string): T[] {

return Array.from(seen.values());
}

export const truncateStr = (str: string, maxLen: number) => {
if (str.length <= maxLen) {
return str;
}
return `${str.slice(0, maxLen)}...`;
};

0 comments on commit e92824e

Please sign in to comment.