poet-v icon indicating copy to clipboard operation
poet-v copied to clipboard

poetv + pyright compability

Open Lilja opened this issue 3 years ago • 6 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

  • :PoetvActivate
  • :e src/<file>.py Result: image

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

Result: image

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?

Lilja avatar Feb 22 '21 23:02 Lilja

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.

mrswats avatar Apr 16 '21 22:04 mrswats

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).

vandalt avatar Apr 17 '21 21:04 vandalt

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.

vandalt avatar Apr 17 '21 22:04 vandalt

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...

petobens avatar Apr 18 '21 20:04 petobens

If you want open a PR (even with a preliminary work) and can continue testing from there

petobens avatar Apr 18 '21 20:04 petobens

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!)

matthewn avatar Apr 20 '21 00:04 matthewn