jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
8.07k stars 211 forks source link

Enable `.mise.toml` IDE auto-complete/validation via `$schema` key #2281

Closed milas closed 3 weeks ago

milas commented 3 weeks ago

At least in the JetBrains (IntelliJ) suite, it's possible to trigger JSON schema validation & autocomplete by associating a schema with the file by the $schema key.

However, this is not valid within the schema itself, causing the file to fail loading when used.

screenshot of IntelliJ showing a .mise.toml file with a $schema key and code completion
mise error parsing config file: /path/to/.mise.toml
mise TOML parse error at line 1, column 1
  |
1 | "$schema" = 'https://raw.githubusercontent.com/jdx/mise/main/schema/mise.json'
  | ^^^^^^^^^
unknown field `$schema`, expected one of `min_version`, `dotenv`, `env_file`, `env`, `env_path`, `alias`, `tools`, `plugins`, `task_config`, `tasks`, `settings`

Here's how Starship has handled the issue in their schema: https://github.com/starship/starship/blob/46b54ebc7d012908dc5ea7001d4d118cd14019bb/.github/config-schema.json#L6-L9

"$schema": {
  "default": "https://starship.rs/config-schema.json",
  "type": "string"
}

(The default is a nice self-referential touch, but not necessary.)

milas commented 3 weeks ago

My workaround for the moment: keep the "$schema" at the top of the file, uncomment it while editing, and then re-comment it on save.

# HACK(milas): uncomment while editing to get autocomplete in IntelliJ
# "$schema" = 'https://raw.githubusercontent.com/jdx/mise/main/schema/mise.json'

[tools]
go = '1.22'
milas commented 3 weeks ago

OK, I realized after this that IntelliJ already knows the .mise.toml filenames and enables autocomplete without the $schema entry, it was just being weird for me before 🤦🏻

It seems to work out of the box in other editors too (I tried zed.dev), so I'm closing this.

Sorry for the noise, thanks for mise ❤️