jdx / mise

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

"mise run" tasks and zsh autocomplete with : delimiters tricks zsh into thinking that grouped tasks are descriptions #2242

Open simonpercivall opened 1 month ago

simonpercivall commented 1 month ago

mise 2024.5.28 if it matters zsh 5.9

The zsh _arguments completion helper, when given an action in double parentheses, accepts completions on the format word:description. With mise tasks using : for grouping, this breaks completion.

If _mise is modified to use single parentheses for _arguments, it works (but, of course, breaks all the other completions that do have descriptions).

Example:

[tasks."lint:ruff:check"]
...

[tasks."lint:ruff.format"]
...

usage correctly completes the tasks:

> usage complete-word --shell zsh -s "$(mise usage)" -- mise run lin
lint:ruff:check
lint:ruff:format

zsh autocomplete, however, gives only:

> mise run <tab>
lint                -- ruff:check
lint                -- ruff:format

and autocompletes only "lint".

simonpercivall commented 1 month ago

Something like this seems to work, instead of the _arguments:

_arguments -C "*: :->args"

case $state in
  (args)
    case $line[1] in
      (run)
        _arguments "*: :($(usage complete-word --shell zsh -s "$spec" -- "${words[@]}" ))"
        ;;
      (*)
        _arguments "*: :(($(usage complete-word --shell zsh -s "$spec" -- "${words[@]}" )))"
        ;;
    esac
esac