zsh-workers
 help / color / mirror / code / Atom feed
From: Marlon Richert <marlon.richert@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Add support for multi-project builds to _gradle
Date: Fri, 17 Sep 2021 16:09:25 +0300	[thread overview]
Message-ID: <CAHLkEDvBnn6i7QFxOWoOzROpiLdH8WpWk=0jNDvn472tx5Bt2w@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 16 bytes --]

See attachment.

[-- Attachment #2: 0001-Add-support-for-multi-project-builds-to-_gradle.txt --]
[-- Type: text/plain, Size: 4297 bytes --]

From 730c776299af18ca5c4ecbf308bf15e95719d9ae Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlonrichert@users.noreply.github.com>
Date: Fri, 17 Sep 2021 16:05:53 +0300
Subject: [PATCH] Add support for multi-project builds to _gradle

---
 Completion/Unix/Command/_gradle | 38 ++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/Completion/Unix/Command/_gradle b/Completion/Unix/Command/_gradle
index adf5e9aa8..a1d9381cb 100644
--- a/Completion/Unix/Command/_gradle
+++ b/Completion/Unix/Command/_gradle
@@ -1,9 +1,9 @@
 #compdef gradle gradlew
 
 local curcontext="$curcontext" ret=1 state state_descr line
-local gradle_inspect=yes cache_policy tag_order
+local gradle_inspect=yes cache_policy tag_order filter=
 local -A opt_args
-local -a gradle_group_tasks gradle_all_tasks
+local -aU gradle_group_tasks gradle_all_tasks tasks
 
 # Set the caching policy to invalidate cache if the build file is newer than the cache.
 _gradle_caching_policy() {
@@ -78,31 +78,53 @@ if [[ $words[CURRENT] != -* ]]; then
                 local -a match mbegin mend
                 # Run gradle/gradlew and retrieve possible tasks.
                 for outputline in ${(f)"$($service --build-file $gradle_buildfile -q tasks --all)"}; do
-                    if [[ $outputline == [[:blank:]]#(#b)([[:alnum:]]##)' - '(*) ]]; then
+                    # Subproject tasks are prefixed with one or more instances of [[:alnum:]]##\:
+                    # Leaving out the prefix runs the task in all subprojects where it exists.
+                    if [[ $outputline ==
+                            [[:blank:]]#(#b)([[:alnum:]]##\:)#([[:alnum:]]##)' - '(*) ]]; then
                         # The descriptions of main tasks start at beginning of line, descriptions of
                         # secondary tasks are indented.
                         if [[ $outputline == [[:alnum:]]* ]]; then
-                            gradle_group_tasks+=( "$match[1]:$match[2]" )
+                            gradle_group_tasks+=(
+                                    "$match[-2]:$match[-1]"
+                                    "${${(j::)match[1,-2]}//:/\:}:$match[-1]"
+                            )
                         else
-                            gradle_all_tasks+=( "$match[1]:$match[2]" )
+                            gradle_all_tasks+=(
+                                    "${${(j::)match[1,-2]}//:/\:}:$match[-1]"
+                            )
                         fi
                     fi
                 done
                 _store_cache $cache_name gradle_group_tasks gradle_all_tasks
             fi
 
+            filter=
+            zstyle -T ":completion:${curcontext}:tasks" prefix-needed &&
+                    [[ $PREFIX != ([[:alnum:]]##\:)## ]] &&
+                            filter+="*\:*"
             if [[ $state == task ]]; then
                 _tags gradle_group gradle_all
                 while _tags; do
                     # Offer main tasks and secondary tasks in different tags.
-                    _requested gradle_group && _describe 'group task' gradle_group_tasks && ret=0
-                    _requested gradle_all && _describe 'secondary task' gradle_all_tasks && ret=0
+                    if _requested gradle_group; then
+                        tasks=( ${gradle_group_tasks:#$~filter} )
+                        _describe -t tasks 'group task' tasks &&
+                                ret=0
+                    fi
+                    if _requested gradle_all; then
+                        tasks=( ${gradle_all_tasks:#$~filter} )
+                        _describe -t tasks 'secondary task' tasks &&
+                                ret=0
+                    fi
                     (( ret )) || break
                 done
             elif [[ $state == alltask ]]; then
                 # After '--exclude-task', we don't make a distinction between main tasks and
                 # secondary tasks.
-                _describe 'task' gradle_group_tasks -- gradle_all_tasks && ret=0
+                tasks=( ${gradle_group_tasks:#$~filter} ${gradle_all_tasks:#$~filter} )
+                _describe -t tasks 'task' tasks &&
+                        ret=0
             fi
         fi
     else
-- 
2.33.0


                 reply	other threads:[~2021-09-17 13:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHLkEDvBnn6i7QFxOWoOzROpiLdH8WpWk=0jNDvn472tx5Bt2w@mail.gmail.com' \
    --to=marlon.richert@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).