elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.65k stars 299 forks source link

Support command argument completion in VS Code "Elvish" extension #1675

Open EmilyGraceSeville7cf opened 1 year ago

EmilyGraceSeville7cf commented 1 year ago

Elvish: 0.19.2+official Extension: v0.2.0 Platform: Ubuntu 22.04.1 LTS

image

At least for external programs.

krader1961 commented 1 year ago

What version of Elvish did you try and on which platform? I ask because this works for me using the current version of Elvish on macOS.

EmilyGraceSeville7cf commented 1 year ago

Elvish: 0.19.2+official Extension: v0.2.0 Platform: Ubuntu 22.04.1 LTS

krader1961 commented 1 year ago

I don't understand what "Extension: v0.2.0" refers to. Regardless, the reason this works for me is thanks to a great Elvish module known as Carapace. Which I enable with this in my ~/.config/elvish/rc.elv:

# Enable the universal command completer if available.
# See https://github.com/rsteube/carapace-bin
if (has-external carapace) {
  eval (carapace _carapace | slurp)
}

When I type sed -- followed by Tab I see this:

> sed --debug
 COMPLETING argument
--debug (annotate program execution)
--expression (add the script to the commands to be executed)
--file (add the contents of script-file to the commands to be executed)
--follow-symlinks (follow symlinks when processing in place)
--help (display this help and exit)
--in-place (edit files in place (makes backup if SUFFIX supplied))
--line-length (specify the desired line-wrap length for the l command)
--null-data (separate lines by NUL characters)
--posix (disable all GNU extensions)
--quiet (suppress automatic printing of pattern space)
--regexp-extended (use extended regular expressions in the script)
--sandbox (operate in sandbox mode (disable e/r/w commands))
--seperate (consider files as separate rather than as a single, continuous long stream.)
--silent (suppress automatic printing of pattern space)
--unbuffered (load minimal amounts of data from the input files and flush the output buffer...)
--version (output version information and exit)

Does that not

EmilyGraceSeville7cf commented 1 year ago

I don't understand what "Extension: v0.2.0" refers to.

To this Elvish extension. :)

Regardless, the reason this works for me is thanks to a great Elvish module known as Carapace.

Wow, thanks! It looks pretty neat. Completion works inside terminal, but not inside VS Code.

xiaq commented 1 year ago

Change the title to refer to the VS Code extension.

The completion in the extension is actually driven by the same code behind CLI completion, but because elvish -lsp doesn't source rc.elv there is currently no way to actually configure command argument completion.

krader1961 commented 1 year ago

I see I failed to recognize the original problem statement involved command completion inside the VS Code IDE. But in my defense, @EmilySeville7cfg, I would argue that is because you did not make it clear you were talking about command completion inside the VS Code IDE rather than at an Elvish prompt in a typical terminal. Notwithstanding your embedded screen shot.

As @xiaq noted, non-interactive invocations of the Elvish interpreter, such as via elvish -lsp from a non-interactive context, explicitly does not run the ~/.config/elvish/rc.elv script. So even if your interactive Elvish configuration, like mine, provides useful completions because of modules imported by your interactive ~/.config/elvish/rc.elv, that would not happen inside the VS Code IDE.

To be determined is how to square this circle.