Goto definition stop working after diving into python internals with virtualenvwrapper
See original GitHub issueHello,
I use this extension in a setup where I have pyenv to control python versions and on top of it virtualvenvwrapper to keep my venvs organized in a common folder and it works much like the anaconda scenario but with a WORKON_HOME
envvar to tell were the virtualenvs are (~/.virtualenvs
in my case), and a VIRTUAL_ENV
envvar that once activated tells the location of the activated venv.
I noticed that sometimes while diving into python internals definitions the goto definition stops working and keeps showing the following message:
[coc.nvim] definition not found
The only way I can get them back working is by closing vim or nvim and opening it again.
It was hard to find a pattern but today I found a consistent way of reproducing it, you just need to create a folder to your code then a setup.py
file with the following content:
from setuptools import setup
setup()
The next steps to reproduce it are:
- Open the file
- Jump into
setup()
definition - Jump into
_install_setup_requires(attrs)
that is in the same file to see everything works - Then jump into
setup
from the line bellow_install_setup_requires
that has this contentreturn distutils.core.setup(**attrs)
- At this point you will notice that you leave virtualenv space to reach pyenv distutils core code
- Navigate back to your
setup.py
code without closing the editor - Jump into
setup()
definition - Jump into
_install_setup_requires(attrs)
and this time it’s not working anymore
Checking the outputs I got this:
What’s the output of :CocCommand pyright.version
[coc.nvim] coc-pyright 1.1.243 with Pyright 1.1.244
What’s the output of :CocCommand workspace.showOutput Pyright
Workspace: /home/humrochagf/Projects/example
Using python from /home/humrochagf/.virtualenvs/test/bin/python
[Info - 5:16:10 PM] Pyright language server 1.1.244 starting
[Info - 5:16:10 PM] Server root directory: /home/humrochagf/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Info - 5:16:10 PM] No configuration file found.
[Info - 5:16:10 PM] No pyproject.toml file found.
[Info - 5:16:10 PM] Setting pythonPath for service "example": "/home/humrochagf/.virtualenvs/test/bin/python"
[Warn - 5:16:10 PM] stubPath /home/humrochagf/Projects/example/typings is not a valid directory.
[Info - 5:16:10 PM] Assuming Python version 3.10
[Info - 5:16:10 PM] Assuming Python platform Linux
[Info - 5:16:10 PM] Searching for source files
[Info - 5:16:10 PM] Found 1 source file
[Info - 5:16:15 PM] No configuration file found.
[Info - 5:16:15 PM] No pyproject.toml file found.
[Info - 5:16:15 PM] Setting pythonPath for service ".pyenv": "/home/humrochagf/.virtualenvs/test/bin/python"
[Warn - 5:16:15 PM] stubPath /home/humrochagf/.pyenv/typings is not a valid directory.
[Info - 5:16:15 PM] Assuming Python version 3.10
[Info - 5:16:15 PM] Assuming Python platform Linux
[Info - 5:16:15 PM] Searching for source files
[Info - 5:16:16 PM] Found 7370 source files
[Info - 5:17:29 PM] No pyproject.toml file found.
[Info - 5:17:29 PM] Setting pythonPath for service "<default>": "/home/humrochagf/.virtualenvs/test/bin/python"
[Warn - 5:17:29 PM] stubPath typings is not a valid directory.
[Info - 5:17:29 PM] Assuming Python version 3.10
[Info - 5:17:29 PM] Assuming Python platform Linux
[Info - 5:17:29 PM] Searching for source files
[Info - 5:17:29 PM] No source files found.
I Tried to compare with the same setup of having pyenv but instead of using virtualenvwrapper creating a venv inside the code folder and in that case, everything works properly.
And checking the logs I noticed that I don’t get the Setting pythonPath for service "<default>"
log chunk.
This is my venv test for comparison:
Workspace: /home/humrochagf/Projects/example
Using python from /home/humrochagf/Projects/example/.venv/bin/python
[Info - 5:45:21 PM] Pyright language server 1.1.244 starting
[Info - 5:45:21 PM] Server root directory: /home/humrochagf/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Info - 5:45:21 PM] No configuration file found.
[Info - 5:45:21 PM] No pyproject.toml file found.
[Info - 5:45:21 PM] Setting pythonPath for service "example": "/home/humrochagf/Projects/example/.venv/bin/python"
[Warn - 5:45:21 PM] stubPath /home/humrochagf/Projects/example/typings is not a valid directory.
[Info - 5:45:21 PM] Assuming Python version 3.10
[Info - 5:45:21 PM] Assuming Python platform Linux
[Info - 5:45:21 PM] Searching for source files
[Info - 5:45:21 PM] Found 1 source file
[Info - 5:45:36 PM] No configuration file found.
[Info - 5:45:36 PM] No pyproject.toml file found.
[Info - 5:45:36 PM] Setting pythonPath for service ".pyenv": "/home/humrochagf/Projects/example/.venv/bin/python"
[Warn - 5:45:36 PM] stubPath /home/humrochagf/.pyenv/typings is not a valid directory.
[Info - 5:45:36 PM] Assuming Python version 3.10
[Info - 5:45:36 PM] Assuming Python platform Linux
[Info - 5:45:36 PM] Searching for source files
[Info - 5:45:37 PM] Found 7370 source files
Another info that may be pertinent is that the Setting pythonPath for service "<default>"
log chunk happens at the second time I jump from my code into the setup()
call.
Thanks for taking the time of reading my issue and also thanks a lot for this awesome extension 😃
Issue Analytics
- State:
- Created a year ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
First of all, very clear issue steps 👍 .
I’m using project-level venv in my projects, as your 2nd test, didn’t encounter the problem.
I’d like to debug the issue with pyenv/virtualvenvwrapper, can you clear me how do you setup pyenv to keep all venvs in a common folder? Sorry I didn’t use pyenv ever.
Oh no worries, when I have some spare time I’ll also try to investigate more to see what can be done 😃