Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH 0/3] completion: make: various improvements



As pointed out by Felipe Contreras, the biggest problem with the current
_make (with call-cammand on) is that it actually runs make to build all.
This is serious and need be fixed. I will soon push slightly modified patch
(see the end of this post) unless any problem is found.

> 2022/08/03 23:36, Felipe Contreras <felipe.contreras@xxxxxxxxx> wrote:
> 
> On Wed, Aug 3, 2022 at 3:54 AM Jun T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
>> 
>> If 'call-command' style is set to false, then these targets are not
>> offered (as a possible target).
> 
> But if you set it to true they are.
> 
> We are talking about the *current code*. The current code already has
> this behavior.

# I was thinking we were talking about how we can improve the
# current code.

Without your patch, if call-command is on, 'make <TAB>' at the top level
of the zsh source tree gives, after a very long wait, huge number of
possible targets (a few hundreds or more?), but most of them are not
valid targets.

With your patch it immediately gives about 60 candidates.
(Most of them are valid, but they still include configure.ac.)

So I thought (probably mistakenly) that part of the objectives of
the patch was to offer only valid targets. But anyway, I think it is
better to filter out invalid targets if it is easy to do so.


>> zstyle ':completion:*:make:*:' tag-order 'targets variables'
> 
> Sure, in that case those files won't be listed initially, but they
> still will be completed.

I think files are completed only if there is no matching targets.
This is enough for me, but maybe not for everyone.




The patch below is basically [1/3]+[2/3], with a few additions:

(1) In _make-parseDataBase(), filter out targets following the
line '# Not a target', and variables following '# environment'.
I think not offering environment variables is OK, but not sure
everyone agrees with this.
(2) Use make option -q instead of -s (as in your awk-version).
(3) add options -C and -S to _arguments.
(4) Do not call _make-parse{Makefile,DataBase}() when completing
options for 'make -<TAB>'.

# As you write, this is much slower than your awk-version.


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








Messages sorted by: Reverse Date, Date, Thread, Author