From 7996fa561e93d9c27919ed4d4257c13d99db3807 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Fri, 5 Aug 2022 22:53:31 +0900 Subject: Felipe Contreras: 50435+50436 (+50444): do not build anything Use 'make -nqp' to ensure nothing is actually built by completion. Also include some performance improvements, but it can be still rather slow in a large project's source tree. --- ChangeLog | 6 ++++++ Completion/Unix/Command/_make | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 660fbbd6b..5b89a7d21 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2022-08-05 Jun-ichi Takimoto + + * Felipe Contreras: 50435+50436 (+50444): + Completion/Unix/Command/_make: do not actually build anything. + Also include some performance improvements. + 2022-07-24 Jun-ichi Takimoto * 50421: Completion/Zsh/Context/_redirect: add missing context diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make index ae91440f0..510368e8b 100644 --- a/Completion/Unix/Command/_make +++ b/Completion/Unix/Command/_make @@ -118,10 +118,34 @@ _make-parseMakefile () { done } +_make-parseDataBase () { + local input var TAB=$'\t' IFS= skip=0 + + while read input + do + if [[ $skip = 1 ]]; then + skip=0 + continue + fi + case "$input " in + (\# Not a target*|\# environment*) + skip=1 # skip next line + ;; + ([[:alnum:]][[:alnum:]_]#[" "$TAB]#(\?|:|::|)=*) + var=${input%%[ $TAB]#(\?|:|::|)=*} + VARIABLES[$var]=1 + ;; + ([[*?[:alnum:]$][^$TAB:=%]#:[^=]*) + TARGETS+=( ${input%%:*} ) + ;; + esac + done +} + _make() { local prev="$words[CURRENT-1]" file expl tmp is_gnu incl match basedir nul=$'\0' - local context state state_descr line + local curcontext=$curcontext state state_descr line local -a option_specs local -A VARIABLES VAR_ARGS opt_args local -aU TARGETS keys @@ -185,7 +209,7 @@ _make() { ) fi - _arguments -s $option_specs \ + _arguments -C -S -s $option_specs \ '*:make target:->target' && ret=0 [[ $state = cdir ]] && cdir=-2 @@ -214,6 +238,10 @@ _make() { ;; (target) + # target name starting with '-' is allowed only after '--' + if [[ $words[CURRENT] = -* ]] && (( ${words[(i)--]} > CURRENT )); then + return ret + fi file=${(v)opt_args[(I)(-f|--file|--makefile)]} if [[ -n $file ]] then @@ -239,7 +267,7 @@ _make() { if [[ $is_gnu == gnu ]] then if zstyle -t ":completion:${curcontext}:targets" call-command; then - _make-parseMakefile < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" --always-make 2> /dev/null) + _make-parseDataBase < <(_call_program targets "$words[1]" -nqp --no-print-directory -f "$file" .DEFAULT 2> /dev/null) else _make-parseMakefile < $file fi -- cgit 1.4.1