From ef614ba2d95377748834caca7307ef6c799ba1c3 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sat, 18 May 2024 12:34:18 -0500 Subject: [PATCH] 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. --- share/completions/rustc.fish | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/share/completions/rustc.fish b/share/completions/rustc.fish index e6ab59085..d35c3b02d 100644 --- a/share/completions/rustc.fish +++ b/share/completions/rustc.fish @@ -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