From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26550 invoked from network); 2 Oct 2020 16:26:29 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 2 Oct 2020 16:26:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date: Content-Transfer-Encoding:Content-ID:Content-Type:MIME-Version:Subject:To: References:From:In-reply-to:cc:Reply-To:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=yrDe/zfkw8YMeeRpQFyNcbeGN8DogxNMxvx/jxaA68E=; b=rlQSPF5YN/Cvv6O30lKINzsg10 UFWMz26vPLPbce/g+IrrbmrFD4utblTYUwXJ0sqUzc2JAJ6s0YFedjyQMeRzcwYBntuuhilRM/6VM JQgGVF7miRzd0JtaGZqshxPMwf8LNWYkTwmSwW9Oe6U81xK7tRa7jiGZ5RxK1IcUn/cRmbQDVG3Bt 3sap2WyKZKP1Q8EGWtY1B5eRNZHVmvOkd8rlhnbWpLHH3DKtIYmPF2YdxczL23Or0Nt3WCA2tfSV6 pjxumxvSF22cW3A3qmZGpgd0eYCUcp5zeuerxGlW8LiwWMea5kBcG6QPa7lKzEHQL5xaiXuMMVIqZ RnhuiQlQ==; Received: from authenticated user by zero.zsh.org with local id 1kONt5-0002HB-Ln; Fri, 02 Oct 2020 16:26:27 +0000 Received: from authenticated user by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1kONsm-000297-8F; Fri, 02 Oct 2020 16:26:08 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.93.0.4) (envelope-from ) id 1kONsk-000IpI-7l; Fri, 02 Oct 2020 18:26:06 +0200 cc: zsh-workers@zsh.org In-reply-to: From: Oliver Kiddle References: To: Justin Garrison Subject: Re: compadd not returning completion options MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <72370.1601655966.1@hydra> Content-Transfer-Encoding: 8bit Date: Fri, 02 Oct 2020 18:26:06 +0200 Message-ID: <72371-1601655966.237415@B17K.ueth.p0Xz> X-Seq: 47421 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: Justin Garrison wrote: > I have a custom completion script I'm working on that has a few different > functions used for completion (I'm modifying existing completion scripts so I > can't change some of them) > > __start_k -> calls __k_handle_word -> calls __k_handle_kspace -> calls > __k_kspace_parse_config Lots of nested functions is fairly common and is unlikely to be the source of problems unless you forget to declare variables local. You seem to have a number of variables that perhaps ought to be local such as cur. > I can see it being run if I set -x in that function (I'm echoing the array at > the end of the compadd command and also tried with -a array_name) Rather than use set -x, I'd recommend using the _complete_debug widget. By default, pressing Ctrl-X followed by ? where you'd normally press tab will invoke that. Then use up-history to retrieve the file with the dumped trace information and if you use less as your pager, the & command to filter it is very useful. > +__k_kspace_parse_config:33> compadd -X CONTEXTS -P + -S '' bottlerocket In itself, that compadd command looks fine. The -P option here adds a + prefix at the beginning of the current word while your tests of $words[CURRENT-1] look at the previous. The functions are quite hard to follow with all the bash stuff in there. The setopts in __k_bash_source() would break things if you've contrived for them to apply within the zsh completion but I doubt that's the case. Just to rule other problems sources out, I'd suggest renaming your commands array so that it doesn't clash with the builtin variable from zsh/parameters. > $: k + >  -- no matches found -- > > but this returns no matches even though the k_out array has values. Where is the cursor, directly after the + or in the following (empty) word? Unlike bash. zsh "matches" the completion candidates against what is already on the command-line so "no matches found" can mean that candidates were added but none matched. Matching is done against $PREFIX and $SUFFIX with any extra characters allowed in between (where the cursor is). The assignment to PREFIX in __k_handle_reply() if it is called may cause issues. It is common to move characters from the start of $PREFIX to the end of $IPREFIX, usually by calling compset -P to do that job. For debug, it can be helpful to dump the contents of those variables to a separate tty before calls to compadd. I'd suggest you simplify your test cases somewhat by replacing some complex functions with very simple ones that just do something like compadd one two three. Or perhaps copy the exact compadd that you see in the trace output. Without kubectl (and k) installed, I don't even get as far as the failure you describe when trying out your function. It is irrelevant to this but k doesn't seem like a great idea for naming. Single letters are common choices for people's own aliases. Oliver