-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Summary of the new feature / enhancement
Currently, argument completers for native commands must be explicitly registered using Register-ArgumentCompleter. However, this means that the module which registers the completer must be eagerly loaded in $PROFILE during startup, otherwise the completions aren't loaded. If many different argument completers are registered, this may take a considerable amount of time on each startup, even when most of the completions are never used in the session.
As an example, importing https://github.com/MatejKafka/PowerShell-ArgumentCompleters takes about 175 ms on my computer. Currently, I'm loading them in an OnIdle event callback, which helps, but it's still not ideal and doesn't scale well to a larger number of completers.
It would be nice to add autoloading support for argument completers. Completions for native commands (together with inline description) are the main reason why I prefer fish shell autocompletion over the one in PowerShell.
As an additional food for thought (which is definitely out-of-scope for this issue), currently there isn't any official repository for argument completers. If that was added, it could be possibly to interactively offer the user to download completions for the given command (if available) when they first trigger autocomplete on it, greatly improving the experience of using native commands in PowerShell. It already kinda works this way on Linux, where many packages also install autocompleters for commonly used shells.
Proposed technical implementation details (optional)
Possible implementation: Add an entry to the module manifest, listing the commands for which it provides argument completers. When completions for the command are requested, the module is autoloaded, which registers the argument completers.
This implementation has an issue where if the module is large (slow to load), there may be a considerable delay before the completions appear. This could be further improved by also specifying which file contains the argument completer for the given command, so that only that file could be loaded, without loading the whole module. This would allow for one big module, which registers many different completers, each in a separate file, without having to load the whole module.