The sections below document how this extension works, especially how to port it to other editors. If you have questions or suggestions about the following sections, please visit the ‘Ports’ Discussions on GitHub.
This script handles the fish shell side of the completions.
The tenth channel of the process (index 9) is the output channel. The script does not send anything to stdout or stderr.
The _FISH_COMPLETION_TEMP_DIR variable should refer to a temporary directory.
It sends the string ready to the output channel when the fish shell finishes
processing the config files and prints the first prompt.
It registers the e key binding to query the completions. Unfortunately,
fish_prompt cannot set the commandline, so once it sends the string ready,
the extension should send the character e to stdin.
It reads the commandline from $_FISH_COMPLETION_TEMP_DIR/text. The extension
should write the text content up to the cursor to this directory.
The script will send the current token to the output channel with the format below. The extension uses this to determine what to erase before inserting the completions.
current %s\n
The script sends the completion entries to the output channel according to the following format:
complete %s\t%s\n (without description)
complete %s\t%s\t%s\n (with description)
The first field is the generated type of entry, the second field is the content (which may not contain a horizontal tab), and the optional third field is the description.
Type of entry may be Text, Keyword, Variable, File, Folder, or
Function. The script should regard any unknown type as Text.
Since the script is one-shot, it will end once it sends all the entries.
Initially, it creates a temporary directory. The extension should remove it later.
It also prepares a script to run:
script -e -q -c 'fish -iPC '\''source $_FISH_COMPLETION_WORKER'\' /dev/null
# Or on FreeBSD and Darwin:
script -q /dev/null fish -iPC 'source $_FISH_COMPLETION_WORKER'It then spawns the script with TERM=dumb, _FISH_COMPLETION_TEMP_DIR= path to
the temporary directory, and __FISH_COMPLETION_WORKER= path to the worker
script. It should receive the stdin and output channels as a stream. (For
debugging purposes, it also pipes stdout and stderr.)
Once it receives ready on the output channel, it will send e to stdin.
By collecting every line on the output channel starting with current or
complete, the extension can provide the completion entries to the editor.
Since the extension uses fish completions, it may provide a command to run
fish_update_completions for convenience.
The extension may parse the output of fish_update_completions and show the
progress to the user. If not, the extension should display the live output or
notify the user when the command finishes.