poetv + pyright compability
Closed this issue · 7 comments
I'm having some issues using this plugin as well as Coc.nvim's coc-pyright plugin/extension.
More technically, I'm having some issues with :PoetvActivate
. AFAIK, :PoetvActivate
and poetry shell
should do the same behaviour?
$ vim
As you can see per my statusline, the venv has been loaded. which python
resolves to the venv. However, pyright complains that it can't find my modules. In the original thread, :!pip list
shows these packages in the vim environment.
$ poetry shell
(backend-dmp__8h8-py3.8) bash-3.2 $ vim
:e src/<file>.py
It works! All the packages are resolved! But why?
Do you have any idea what is happening here? Is this something on coc-pyright's end or should I expect something else to happen?
Something similar I observed with python-language-server
. With the plugin alone it does not work, does not show any candiates for completion but when running poetry shell, opening vim and trying again, get the right candidates and so on.
I am using nvim's buildin LSP and nvim-compe for the completion engine.
I also have this issue with nvim's built-in LSP and pyright
it is probably because pyright (or pyls) is launched before the VIRTUAL_ENV variable is set by poetv (discussed in this nvim-lspconfig issue).
Running :LspRestart
makes the LSP detect the environment (because VIRTUAL_ENV is now set). I tried editing the plugin source code to run LspRestart
automatically when the environment is activated. It worked when running :PoetvActivate
, but it does not work with the poetv_auto_activate
option (i.e. I have to re-run :PoetvActivate
even when using the auto-activate option). Unfortunately I don't know vimscript very well so I would not know how to make it work with auto-activate.
I don't use the LSP thingy yet... but I'll promise to take a look if a find some spare time over the next weekends...
If you want open a PR (even with a preliminary work) and can continue testing from there
I'm running into similar trouble using poet-v with standard vim plus ALE's support for LSPs. I am using the current workaround (adapted from part of poet-v's source) in my vimrc:
augroup poetv_autocmd
au!
au WinEnter,BufWinEnter *.py
\ if &previewwindow != 1 && expand('%:p') !~# "/\\.git/" |
\ call poetv#activate() | call ale#lsp#reset#StopAllLSPs() |
\ endif
augroup END
(Poet-v is splendid, by the way. Thank you!)
For lsp support (using lua) take a look at https://github.com/petobens/dotfiles/blob/91f53abcb25b18a7759c6056c46a47da8e25b6be/nvim/ftplugin/python.lua#L238-L253