prezto icon indicating copy to clipboard operation
prezto copied to clipboard

Module cannot both use completion functions and other completion mechanisms

Open jcassee opened this issue 4 years ago • 3 comments

Description

As also mentioned in #1659, the completion module enables the completion system, but also loads completion functions. This means:

  • Modules loaded before completion that use complete for their completions will have their definitions cleared.
  • Modules loaded after completion will not have their completion functions installed.

I have a module that uses both (because of external completion scripts), which causes some completions to be lost.

Expected behavior

To be able to use both complete and completion functions in the same module.

I believe completion functions of modules loaded later could be included if the collection of fpath elements is a separate step before the execution of the init.zsh files, so fpath is already finalized when the completion module is loaded. However, this conflicts with the removal of the entry from fpath if the module fails to load.

Alternatively, the completion module could be separated into two parts, one of which would be loaded early, and the other (compinit) late.

My current workaround is to call compinit again after all modules were loaded, but this seems wasteful.

Actual behavior

Either complete or completion functions work.

Steps to Reproduce

  1. Create a module containing both a completion for terraform and a completion function.
  • init.sh:
    complete -o nospace -C $commands[terraform] terraform`
    
  • functions/_example:
    #compdef example
    
    function _example {
      _arguments '1: :(foo bar)'
    }
    
  1. Either include the module before or after the completion module. Either the terraform or example completion will not work.

Versions

  • Prezto commit: 7c94154dda2dfcf02515f1caf1e9dfe6d80b0350
  • ZSH version: zsh 5.7.1 (x86_64-ubuntu-linux-gnu)
  • OS information: Ubuntu 19.10

jcassee avatar Jan 08 '20 22:01 jcassee

Huh, this is really interesting. I wonder if it would make sense to start adding some sort of prezto hooks, similar to zsh-add-hook... do you have any other ideas on how to call compinit later in the startup process?

belak avatar Jan 20 '20 15:01 belak

@belak As an outside contributor, I'm not inclined to suggest new framework-wide features. A hook for deferred execution sounds like it would work, but a simpler solution could be to split the call to compinit off into its own small module that is placed last in the modules list. Order is already important anyway. What would you like better?

jcassee avatar Jan 29 '20 16:01 jcassee

@belak, @jcassee I've faced the same issues and I use the workaround of deleting compinit cache and calling compinit everytime I add a new completion.

@jcassee's solution of splitting compinit is easier to implement but also easier to forget for the end user. I personally think that a prezto hook might be more suitable for this case, but can't think of any other use case of a custom prezto hook off the top of my head.

srijanshetty avatar Jan 30 '20 09:01 srijanshetty