Open ajeetdsouza opened 2 years ago
Completion files can be installed like other modules into a global module search directory (https://elv.sh/ref/command.html#module-search-directories).
There is no automatic discovery of completion files though; the user would have to import them manually with use
.
Would it be feasible to implement automatic discovery of completion files?
Would it be feasible to implement automatic discovery of completion files?
Yes, but it probably requires some discussion over a period of several months to determine if the pro's outweigh the con's. At this time Elvish does not automatically import any module other than builtin
. So one con is that automatically importing completion modules is behavior different than for non-completion modules. On the other hand, interactive command completion modules are fundamentally different from non-completion modules and it might be friendlier to automatically import them. On the other hand, a completion module can contain arbitrary Elvish code -- not just command completion code. And thus auto-importing completion modules could be abused to bypass the usual requirement to use
a module. That could, perhaps, be mitigated by putting completion modules in a special namespace that isn't searched when resolving an interactive command.
Revisiting this, it would make sense for the default fallback completer to autoload completion modules. So something like this could work:
foo
command to /usr/share/elvish/lib/completions/foo.elv
, which defines a complete
command.foo
command, and a completer hasn't be installed yet, the fallback completer checks whether the aforementioned file exists, and if so, installs the complete
command within it as the completer for foo
.This autoloader can already be implemented in Elvish code today. However, I am a bit hesitant to commit to this scheme because I'm going to revisit the module system in the near future, and that might mean a slightly different scheme for installing completion scripts. Having two different ways of packaging completion modules can be quite confusing for distributions.
So I'll keep this on hold for now until I have revisited the module system.
Bash, fish, and zsh all have a completions directory on Linux, where applications can add their completion files. Does Elvish have anything similar? If not, consider this a feature request.
/usr/share/bash-completion/completions/
/usr/share/fish/completions/
/usr/share/zsh/vendor-completions/