Skip to content

Commit 3423c8b

Browse files
committed
feat: only provide snippets in files mise support
1 parent 271c3d9 commit 3423c8b

19 files changed

Lines changed: 922 additions & 74 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ The mise-vscode extension integrates mise's core functionality into VS Code, hel
104104

105105
### Snippets
106106

107-
- 📝 Snippets to create tasks in `mise.toml` and task files
107+
- 📝 `mise-task` snippets to create tasks in `mise.toml` and task files. They
108+
are only suggested in the files mise loads, and only where a task can be
109+
inserted. Set `mise.enableSnippets` to `false` to turn them off.
108110

109111
### Integration with VSCode tasks (`launch.json`)
110112

docs/src/content/docs/reference/Settings.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Show the tools and environment variables of each [monorepo](https://mise.jdx.dev
275275

276276
Show a code lens on each `[bootstrap.*]` section reporting how many of its entries are not in their desired state.
277277

278-
Requires `#mise.enableCodeLens#` and mise 2026.7.16+. Reading the status runs `mise bootstrap status`, which inspects the machine (installed packages, cloned repos, macOS defaults, Docker Compose projects); the result is cached and only read for files that declare a bootstrap section.
278+
Requires `mise.enableCodeLens` and mise 2026.7.16+. Reading the status runs `mise bootstrap status`, which inspects the machine (installed packages, cloned repos, macOS defaults, Docker Compose projects); the result is cached and only read for files that declare a bootstrap section.
279279

280280
---
281281

@@ -319,6 +319,16 @@ Enable Tera auto-completion in `mise.toml` files.
319319

320320
---
321321

322+
##### `mise.enableSnippets`
323+
- **Type:** `boolean`
324+
- **Default:** `true`
325+
326+
Suggest task snippets (`mise-task`, `mise-task-script`, ...) in mise configuration files and in file tasks.
327+
328+
They are also hidden by `editor.snippetSuggestions` set to `none` and by `editor.suggest.showSnippets` set to `false`, which apply to every extension.
329+
330+
---
331+
322332
##### `mise.automaticallyTrustMiseConfigFiles`
323333
- **Type:** `boolean`
324334
- **Default:** `true`

docs/src/content/docs/reference/Tasks.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ New file tasks are created with a working example of
114114
flag, argument with a default value, custom completion, and the corresponding
115115
`$usage_*` variables in the script).
116116

117+
### Using snippets
118+
119+
Type `mise-task` in a mise configuration file to get snippets for the different
120+
shapes a task can take: `mise-task`, `mise-task-array`, `mise-task-script`,
121+
`mise-task-usage`, `mise-task-template`, `mise-task-full`, and one per language
122+
(`mise-task-node`, `mise-task-python`, `mise-task-uv`, `mise-task-deno`,
123+
`mise-task-bun`, `mise-task-ruby`). In a file task, `mise-task` inserts a
124+
`#MISE` configuration block and `mise-task-usage` a `#USAGE` argument block.
125+
126+
The snippets are only suggested in the files mise loads, which are the
127+
[configuration files](https://mise.jdx.dev/configuration.html) and the scripts
128+
in a [task directory](https://mise.jdx.dev/tasks/file-tasks.html), and only
129+
where a task can be inserted: at the start of a line, outside of strings,
130+
arrays and comments. Set `mise.enableSnippets` to `false` to turn them off.
131+
117132
## Task dependencies
118133

119134
You can visualize the dependencies of a task by using the `Mise: Visualize Tasks Dependencies` command.
@@ -178,8 +193,7 @@ particularly useful in a [monorepo](#monorepo-tasks). It provides:
178193
entry, in the same file or in a parent config file
179194
- **Find references** from a template declaration to every task extending it,
180195
anywhere in the workspace
181-
- Task templates in the outline view, and `task_template` / `task_extends`
182-
snippets
196+
- Task templates in the outline view, and a `mise-task-template` snippet
183197

184198
Task hovers show the template a task extends. The fields shown for the task
185199
itself are the ones mise resolved, i.e. after the template has been merged in.

docs/src/extract-settings.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ access the extension settings.
2929
3030
## Settings`;
3131

32+
/**
33+
* `#editor.snippetSuggestions#` links to another setting in the VS Code
34+
* settings UI, the docs show the setting name instead. The markers are dropped
35+
* whether or not they are already inside a code span.
36+
*/
37+
function renderSettingLinks(description) {
38+
return description.replace(/`?#([\w.-]+)#`?/g, "`$1`");
39+
}
40+
3241
function generateWikiContent(packageJson) {
3342
const settings = packageJson.contributes.configuration.properties;
3443
const settingsEntries = Object.entries(settings).sort(
@@ -56,7 +65,7 @@ function generateWikiContent(packageJson) {
5665
content += `- **Default:** \`${defaultValue}\`\n\n`;
5766
}
5867

59-
content += `${setting.markdownDescription}\n\n`;
68+
content += `${renderSettingLinks(setting.markdownDescription)}\n\n`;
6069

6170
if (setting.items?.enum) {
6271
content += "**Available options:**\n\n";

package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,6 @@
178178
]
179179
}
180180
],
181-
"snippets": [
182-
{
183-
"language": "toml",
184-
"path": "./snippets/toml-tasks-snippets.json"
185-
},
186-
{
187-
"language": "shellscript",
188-
"path": "./snippets/file-tasks-snippets.json"
189-
}
190-
],
191181
"configurationDefaults": {
192182
"[toml]": {
193183
"editor.quickSuggestions": {
@@ -447,6 +437,13 @@
447437
"default": true,
448438
"markdownDescription": "Enable Tera auto-completion in `mise.toml` files."
449439
},
440+
"mise.enableSnippets": {
441+
"order": 14.1,
442+
"type": "boolean",
443+
"title": "Enable snippets",
444+
"default": true,
445+
"markdownDescription": "Suggest task snippets (`mise-task`, `mise-task-script`, ...) in mise configuration files and in file tasks.\n\nThey are also hidden by `#editor.snippetSuggestions#` set to `none` and by `#editor.suggest.showSnippets#` set to `false`, which apply to every extension."
446+
},
450447
"mise.automaticallyTrustMiseConfigFiles": {
451448
"order": 15,
452449
"type": "boolean",

src/browser.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import * as vscode from "vscode";
22
import { MiseTomlTaskSymbolProvider } from "./providers/MiseTomlTaskSymbolProvider";
3+
import { MiseSnippetProvider } from "./providers/miseSnippetProvider";
34
import { logger } from "./utils/logger";
45

6+
/**
7+
* The settings are read directly here: `configuration.ts` reaches for node-only
8+
* helpers, which the web bundle cannot pull in.
9+
*/
10+
const isEnabled = (flag: string) =>
11+
vscode.workspace.getConfiguration("mise").get<boolean>(flag) ?? true;
12+
513
/**
614
* Browser/web extension entry point.
715
*/
@@ -17,6 +25,22 @@ export async function activate(context: vscode.ExtensionContext) {
1725
new MiseTomlTaskSymbolProvider(vscode),
1826
),
1927
);
28+
29+
// no mise binary on the web: the files are recognised by their name only
30+
const snippetProvider = new MiseSnippetProvider({
31+
isEnabled: () => isEnabled("enable") && isEnabled("enableSnippets"),
32+
});
33+
34+
context.subscriptions.push(
35+
vscode.languages.registerCompletionItemProvider(
36+
{ language: "toml" },
37+
snippetProvider,
38+
),
39+
vscode.languages.registerCompletionItemProvider(
40+
{ language: "shellscript" },
41+
snippetProvider,
42+
),
43+
);
2044
} catch (error) {
2145
logger.error("Error while activating Mise extension (browser mode)", error);
2246
throw error;

src/configuration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const CONFIGURATION_FLAGS = {
3030
updateEnvAutomaticallyIncludePath: "updateEnvAutomaticallyIncludePath",
3131
updateOpenTerminalsEnvAutomatically: "updateOpenTerminalsEnvAutomatically",
3232
teraAutoCompletion: "teraAutoCompletion",
33+
enableSnippets: "enableSnippets",
3334
resolveMonorepoProjectConfigs: "resolveMonorepoProjectConfigs",
3435
automaticallyTrustMiseConfigFiles: "automaticallyTrustMiseConfigFiles",
3536
commandTTLCacheSeconds: "commandTTLCacheSeconds",
@@ -280,6 +281,10 @@ export const isTeraAutoCompletionEnabled = () => {
280281
return getConfOrElse(CONFIGURATION_FLAGS.teraAutoCompletion, true);
281282
};
282283

284+
export const areSnippetsEnabled = () => {
285+
return getConfOrElse(CONFIGURATION_FLAGS.enableSnippets, true);
286+
};
287+
283288
export const getCommandTTLCacheSeconds = () => {
284289
return getConfOrElse(CONFIGURATION_FLAGS.commandTTLCacheSeconds, 2);
285290
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
# Fixture for the snippet suite: a file task in a directory mise loads tasks
4+
# from. Deliberately left non-executable, so mise does not list it as a task and
5+
# the task lists the other suites assert on stay unchanged.
6+
echo "file task fixture for snippets"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Fixture for the snippet suite. `mise.<env>.toml` files are only loaded with
2+
# MISE_ENV=<env>, so this one is a mise config file by name without changing the
3+
# tasks of the workspace.
4+
5+
[tasks.example]
6+
run = '''
7+
echo "inside a multiline string"
8+
9+
'''
10+
depends = [
11+
"echo-hello",
12+
13+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
# Fixture for the snippet suite: a shell script that is not a mise file task,
4+
# so no `#MISE`/`#USAGE` snippet should be offered in it.
5+
echo "not a task"

0 commit comments

Comments
 (0)