Skip to content

Commit

Permalink
Update README.md. Handle untrusted mise config files
Browse files Browse the repository at this point in the history
  • Loading branch information
hverlin committed Nov 12, 2024
1 parent 93ba734 commit 27786b5
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 12 deletions.
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2025 Hugues Verlin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
59 changes: 52 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
# mise-vscode
# mise-vscode 🛠️
[![VS Code Marketplace](https://img.shields.io/visual-studio-marketplace/v/hverlin.mise-vscode)](https://marketplace.visualstudio.com/items?itemName=hverlin.mise-vscode)
[![Open VSX](https://img.shields.io/open-vsx/v/hverlin/mise-vscode)](https://open-vsx.org/extension/hverlin/mise-vscode)

This is an extension for https://mise.jdx.dev/
VS Code extension for [mise](https://mise.jdx.dev/)

## Features
- Automatically detect `mise` tasks
- Run `mise` directly from `mise.toml` files, the command palette, or the mise sidebar
- Show tools in the sidebar. Clicking on a tool will show where the tool is defined
- Show mise environment variables
> [mise](https://mise.jdx.dev/) is a development environment setup tool that manages your project's tools, runtimes, environment variables, and tasks all in one place.
## 📥 Installation
- [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=hverlin.mise-vscode)
- [Open VSX Registry](https://open-vsx.org/extension/hverlin/mise-vscode)

## ✨ Features

### Task Management
- 🔍 Automatic detection of `mise` tasks
- ⚡ Run tasks directly from:
- `mise.toml` files
- Command palette
- Mise sidebar

### Tool Management
- 🧰 View all [mise tools](https://mise.jdx.dev/dev-tools/) (python, node, jq, etc.) in the sidebar
- 📍 Quick navigation to tool definitions
- 📱 Show tools which are not installed or active

### Environment Variables
- 🌍 View [mise environment variables](https://mise.jdx.dev/environments.html)

## 🚀 Getting Started

1. Install the extension from [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=hverlin.mise-vscode#overview) or [Open VSX](https://open-vsx.org/extension/hverlin/mise-vscode)
2. Open a project with a `mise.toml` file
3. Access mise features through:
- The sidebar icon `terminal` icon in the activity bar (usually on the left)
- Command palette (`Ctrl/Cmd + Shift + P`). Search for `Run Mise Task` or `Open Tool definition` or `Open Mise Task definition`
- The status bar at the bottom of the window

## 🐛 Bug Reports / Feature Requests / Contributing

- Found a bug? Please [open an issue](https://github.com/hverlin/mise-vscode/issues) with:
- Contributions are welcome! Please use the `discussions` tab before opening a PR.

## Roadmap

- [ ] Automatically setup SDKs based on mise tools
- [ ] Improve mise task integration
- [ ] Suggest to install missing tools
- [ ] UI to install tools
- ...

## 📄 License

This extension is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Mise VSCode",
"publisher": "hverlin",
"description": "VSCode extension for mise (manged dev tools, tasks and environment variables)",
"version": "0.0.12",
"version": "0.0.13",
"repository": {
"type": "git",
"url": "https://github.com/hverlin/mise-vscode"
Expand Down
47 changes: 47 additions & 0 deletions src/miseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,38 @@ export class MiseService {
return `${miseCommand} ${command}`;
}

private async handleUntrustedFile(error: Error): Promise<void> {
const match = error.message.match(/file (.*?) is not trusted/);
if (!match) {
logger.error(
"Could not extract filename from trust error message:",
error,
);
throw new Error("Invalid trust error message format");
}

const filename = match[1];
const trustAction = "Trust File";
const selection = await vscode.window.showErrorMessage(
`The Mise configuration file "${filename}" is not trusted. Would you like to trust it?`,
{ modal: true },
trustAction,
);

if (selection !== trustAction) {
throw new Error("User declined to trust file");
}

try {
await this.execMiseCommand("trust");
} catch (trustError) {
logger.error("Error trusting mise configuration:", trustError as Error);
throw new Error(
`Failed to trust the Mise configuration file "${filename}". Please try again or trust it manually.`,
);
}
}

async getTasks(): Promise<MiseTask[]> {
try {
const { stdout } = await this.execMiseCommand("tasks ls --json");
Expand All @@ -42,6 +74,11 @@ export class MiseService {
description: task.description,
}));
} catch (error: unknown) {
if (error instanceof Error && error.message.includes("is not trusted")) {
await this.handleUntrustedFile(error);
return this.getTasks();
}

logger.error("Error fetching mise tasks:", error as Error);
return [];
}
Expand Down Expand Up @@ -76,6 +113,11 @@ export class MiseService {
});
});
} catch (error) {
if (error instanceof Error && error.message.includes("is not trusted")) {
await this.handleUntrustedFile(error);
return this.getTools();
}

logger.error("Error fetching mise tools:", error as Error);
return [];
}
Expand All @@ -89,6 +131,11 @@ export class MiseService {
value: value as string,
}));
} catch (error) {
if (error instanceof Error && error.message.includes("is not trusted")) {
await this.handleUntrustedFile(error);
return this.getEnvs();
}

logger.error("Error fetching mise environments:", error as Error);
return [];
}
Expand Down
12 changes: 8 additions & 4 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ export class Logger {

// Show in Problem panel for warnings and errors
if (level >= LogLevel.WARN) {
const severity =
const notify =
level === LogLevel.WARN
? vscode.DiagnosticSeverity.Warning
: vscode.DiagnosticSeverity.Error;
? vscode.window.showWarningMessage
: vscode.window.showErrorMessage;

vscode.window.showErrorMessage(`Mise: ${message}`);
let errorMessage = message;
if (error) {
errorMessage = `${message}: ${error.message}`;
}
void notify(`Mise: ${errorMessage}`);
}
}

Expand Down

0 comments on commit 27786b5

Please sign in to comment.