about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>2022-08-05 22:53:31 +0900
committerJun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>2022-08-05 22:53:31 +0900
commit7996fa561e93d9c27919ed4d4257c13d99db3807 (patch)
treeeaac742a99a1b9582fd35ee541a59dcc20d29aaa
parent8e1c6ed6bf416e7716b4c6d5c6822ec752db7b36 (diff)
downloadzsh-7996fa561e93d9c27919ed4d4257c13d99db3807.tar.gz
zsh-7996fa561e93d9c27919ed4d4257c13d99db3807.tar.xz
zsh-7996fa561e93d9c27919ed4d4257c13d99db3807.zip
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.
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Unix/Command/_make34
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  <takimoto-j@kba.biglobe.ne.jp>
+
+	* 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  <takimoto-j@kba.biglobe.ne.jp>
 
 	* 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