7

I am trying to debug a completion method. This method is supposed to present with all the directories within these three folders. I verified that compinit is loading it correctly. tried tracing and i can't decypher most of it.

here is my completion function

#compdef c

_files -W $PROJECT/repos -/
_files -W $PROJECT/helm -/
_files -W ~/Code -/

and the function itself, c

#!/bin/zsh

cd "$PROJECTS/$1"

I don't get anything, nothing. And i can't figure out how to debug it to figure out whats being put in _files to begin with.

1 Answer 1

14

Press ^X? (Ctrl+X ?) instead of Tab to run _complete_debug. This places a trace of the completion code into a file which you can view by pressing Up Enter.


Alternatively, if you want to generate a trace of a specific function while you're debugging it, add this to the beginning of your function to get an execution trace:

setopt local_options xtrace

The trace is extremely verbose so you may prefer to have it in a file rather than on the terminal. To do that, put the code in an auxiliary function and redirect that function's stderr.

#compdef c

function _c_do_complete {
  _files -W $PROJECT/repos -/
  _files -W $PROJECT/helm -/
  _files -W ~/Code -/
}

function _c {
  setopt local_options xtrace
  _c_do_complete 2>|~/_c.trace
}

_c "$@"

You have $PROJECT in the completion code but $PROJECTS in the function (which is actually a script, which would do nothing since cd alone in a script is pointless.) Other than that, your code looks sensible to me.

7
  • i ran functions -t _c and got the trace, problem is its so verbose i can't make heads or tails what its doing. looks like the _files is a lamda, not a list of values. and $PROJECT is an evironment var
    – scphantm
    Aug 25, 2020 at 20:33
  • @scphantm Yes, sure, _files is a function and $PROJECT requires PROJECT to be a shell variable (not necessarily an environment variable). What did you expect them to be? The trace is large, yes. I've never heard of a higher-level tool to debug completions. Aug 25, 2020 at 20:48
  • i fixed my var names and tried as you suggested, no change. Whats supposed to happen is my autocomplete be filled with the subdirs of those three dirs.
    – scphantm
    Aug 25, 2020 at 22:09
  • and yea, i know my c function has a path bug in it, but for the moment id be happy filling the autocomplete.
    – scphantm
    Aug 25, 2020 at 22:11
  • @scphantm Your code works for me. I don't see an obvious dependency on configuration options. Does it work with a .zshrc that contains nothing apart from autoload compinit; compinit? Aug 25, 2020 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .