AcademySoftwareFoundation / AcademySoftwareFoundation/rez

Zsh autocompletion doesn't work : COMP_LINE and COMP_POINT are empty

Open
#1,028 10 comments 0 reactions 0 assignees View on GitHub
bug shell
Dominant language
Python
Stars
1.1k
Forks
374
Avg merge
9d 12h
Merged PRs (30d)
5

Description

Hi,

I just installed rez 2.72.0 (7f760bf) on a Pop!_OS 20.04 computer (`Python 3.8.6`) and I have a zsh shell with the latest [Oh My Zsh](https://github.com/ohmyzsh/ohmyzsh) installed.

## Steps to reproduce

I installed rez successfully with :

```shell
git clone https://github.com/nerdvegas/rez
cd rez
python ./install.py
```

Then added the paths to my `.zshrc` file :

```zsh
# Rez
export PATH="/opt/rez/bin/rez:$PATH"
source /opt/rez/completion/complete.zsh
```

Now when I type `rez env` and press Tab, this is the error message :

```zsh
$ rez env …Traceback (most recent call last):
File "/opt/rez/bin/rez/_rez-complete", line 8, in
sys.exit(run_rez_complete())
File "/opt/rez/lib/python3.8/site-packages/rez/cli/_entry_points.py", line 80, in run_rez_complete
return run("complete")
File "/opt/rez/lib/python3.8/site-packages/rez/cli/_main.py", line 170, in run
returncode = run_cmd()
File "/opt/rez/lib/python3.8/site-packages/rez/cli/_main.py", line 162, in run_cmd
return func(opts, opts.parser, extra_arg_groups)
File "/opt/rez/lib/python3.8/site-packages/rez/cli/complete.py", line 29, in command
last_word = comp_line.split()[-1]
IndexError: list index out of range
```

## Source of the issue

I've looked at the problematic line and it's caused because the `COMP_LINE` and `COMP_POINT` environment variables are empty strings :

```python
# rez/lib/python3.8/site-packages/rez/cli/complete.py

# get comp info from environment variables
comp_line = os.getenv("COMP_LINE", "")
comp_point = os.getenv("COMP_POINT", "")

# ...

last_word = comp_line.split()[-1]
```

However this is working by setting manually the variables :

```zsh
$ COMP_LINE="rez " _rez-complete
bind build config context cp depends diff env gui help interpret memcache pip pkg-cache plugins python release search selftest status suite test view yaml2py
```

Also I tried changing the complete function in `complete.zsh` file to this :

```zsh
# rez/completion/complete.zsh

_rez_complete_fn()
{
if [ -z "$COMP_LINE" ]; then echo "COMP_LINE is empty"; fi
if [ -z "$COMP_POINT" ]; then echo "COMP_POINT is empty"; fi

COMPREPLY=($(COMP_LINE=${COMP_LINE} COMP_POINT=${COMP_POINT} _rez-complete))
}
```

And it gives me this when pressing TAB :

```
COMP_LINE is empty
COMP_POINT is empty
```

So what is going on here?

Contributor guide

Open the contributing guide

Research direction

Start with completion/complete.zsh and rez/cli/complete.py, then inspect the _rez-complete entry point and how the zsh function supplies completion context. Reproduce the Tab completion failure with the reported setup and determine why COMP_LINE and COMP_POINT are empty; done means `rez env` completion no longer raises IndexError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, zsh
Domain
cli, developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.