VirtusLab / scala-cli

Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run, test, and package your Scala code (and more!)
https://scala-cli.virtuslab.org
Apache License 2.0
540 stars 128 forks source link

Completions not working in zsh when oh-my-zsh isn't installed #1147

Open wleczny opened 2 years ago

wleczny commented 2 years ago

Version(s)

0.1.9

Describe the bug

After scala-cli install completions I had this error message in terminal every time I run it:

/Users/username/.zshrc:4: command not found: compinit

Adding these 2 lines at the beginning of .zshrc file solved the case:

autoload -Uz compinit
compinit

It would be nice to get information what should I do during scala-cli completions installation.

Moreover scala-cli completions don't work for me after all these steps. I am using macOS with M1 Pro.

alexarchambault commented 2 years ago

It works for me locally (macOS too, but Intel one). Do you use oh-my-zsh? I'm using it, I'm wondering whether some of its setup (beyond the compinit stuff you mentioned) is required…

wleczny commented 2 years ago

Installing oh-my-zsh did the work, thanks!

alexarchambault commented 2 years ago

Ideally, we should ensure it works even without oh-my-zsh…

Jasper-M commented 1 year ago

I have oh-my-zsh but completions still don't work.

$ scala-cli e
(eval):5: unmatched '
(eval):5: unmatched '
(eval):5: unmatched '

The problem seems to be with those escaped ' characters:

$ scala-cli complete zsh-v1 "1" "e"
local -a args306746944
args306746944=(
'export:The \'export\' sub-command is experimental.'
)
_describe command args306746944
$ eval "local -a args306746944
args306746944=(
'export:The \'export\' sub-command is experimental.'
)
_describe command args306746944"

zsh: unmatched '

$ eval "local -a args306746944
args306746944=(
'export:The export sub-command is experimental.'
)
_describe command args306746944"

_tags:comptags:36: can only be called from completion function
_tags:comptry:55: can only be called from completion function
_tags:comptags:60: can only be called from completion function
_tags:comptags:67: can only be called from completion function

I am using scalacli version 1.0.0-RC2.

Jasper-M commented 1 year ago

I hacked the completions file into

#compdef _scala-cli scala-cli

function _scala-cli {
  eval "$(scala-cli complete zsh-v1 $CURRENT $words[@] | sed  's|\\||g')"
}

Now completions seem to work, but I probably don't get the intended quotes in the output...

export                              -- The export sub-command is experimental.

EDIT: this hack seems to completely break completions on scala-cli - or scala-cli --.