Speed up rustc completions, filter out deprecated options

Don't unconditionally execute the plumbing to get `rustc -C` completions (use it
only when trying to complete `rustc -C`), filter out deprecated options, and use
fewer calls to the `string` builtin to optimize further.

Need to do the same thing for the `-Z` completions next, those hang the shell
for a good 1.5+ seconds.
This commit is contained in:
Mahmoud Al-Qudsi 2024-05-18 12:34:18 -05:00
parent 0a7725e469
commit ef614ba2d9

View File

@ -28,17 +28,7 @@ complete -c rustc -f -l extern
complete -c rustc -f -l sysroot
complete -c rustc -x -l color -a 'auto always never'
set -l rust_docs (rustc -C help 2>/dev/null \
| string replace -r -i '(\s+)-C(.+)(\s+)--(\s+)([^\n]+)' '$2 $5' \
| string trim \
| string match -r '^.*[^:]$')
for line in $rust_docs
set -l docs (string split -m 1 ' ' -- $line)
set -l flag (string replace -r '^([a-z\-]+\=|[a-z\-]+)(.*)' '$1' \
$docs[1])
complete -c rustc -x -s C -l codegen -a (string escape -- "$flag") -d "$docs[2]"
end
complete -c rustc -s C -l codegen -xa "(rustc -C help 2>/dev/null | string match -rv 'option is deprecated' | string replace -rf -i '(\s+)-C\s*(.+)=val(\s+)--(\s+)([^\n]+)' '\$2='\t'\$5')"
# rustc -Z is only available with the nightly toolchain, which may not be installed
if rustc +nightly >/dev/null 2>&1