Moving from PyCharm; stuck
dycw opened this issue · comments
Hi, I am considering moving from PyCharm, and thought this would be a great place to start.
I am running a setup of the following form:
- Ubuntu 20.04:
- Homebrew/Linuxbrew installed node
I have conda
:
❯ conda env list
# conda environments:
#
base * /home/derek/miniconda3
neovim /home/derek/miniconda3/envs/neovim
where I've put pynvim
in the neovim
environment.
In PyCharm, if I have an environment called work
with pytest
(for example) installed, then setting the project interpreter to the said environment would allow me to autocomplete & auto-import from:
@fix<CURSOR> # <-- press <Ctrl+Enter> twice
def stuff():
pass
to:
from pytest import fixture
@fixture<CURSOR>
def stuff():
pass
I cannot seem to recreate this.
In my init.vim
I have:
let conda_default_env = $CONDA_DEFAULT_ENV
if conda_default_env == 'base'
let env_name = 'neovim'
else
let env_name = conda_default_env
endif
let bin_python = expand('~') . '/miniconda3/envs/' . env_name . '/bin/python'
if filereadable(bin_python)
let g:python3_host_prog = bin_python
endif
which allows me to use different python
s as I switch around projects, as well as
Plug 'neoclide/coc.nvim', {
\ 'do': { -> coc#util#install() },
\ 'branch': 'release',
\ 'tag': '*',
\ }
let g:coc_global_extensions = [
\ 'coc-jedi',
\ ]
along with the rest of the stuff from here.
I haven't configured coc-settings.json
besides setting its entirety to this.
Any assistance please?
FWIW, I am able to do the symbol rename and other things:
3 [Scrat┌New name ───────────────────────┐
✘ 1 def│foo2 │
1 └────────────────────────────────┘
2
3
✘ 4 @pytes
✘ 5 def bar(x: int) -> str:
✘ 6 return foo2(x)
~
~
Ah, I believe you're running into a jedi limitation. Jedi does not support autoimport, nor will it in the future. davidhalter/jedi-vim#736 . Since you are trying to automatically insert an import statement, it appears this is not currently possible and never will be possible with Jedi (I assume for a combination of performance and generalization reasons).
Please let me know if this adequately answers your question; if yes, feel free to close the issue. If not, let me know what else you might be having trouble replicating.
Also, just found this tool, maybe you can experiment with it and let me know how it goes for you! https://pypi.org/project/autoimport/
Hi @pappasam, thanks for dropping by.
I understand the issue of this being a jedi limitation now, thank you. However, allow me to expand on my query. If I am to write imports by hand, am I right in expecting my interpreter to understand what's been installed into my environment? Viz.:
from numpy import <CURSOR>
should start showing me members of __all__
, like arange
, ones
, etc?
Whilst unable to get this working straight up, I can't be sure where to start debugging because there appears to be many places to set "interpreter path" (using PyCharm terminology) like:
~/.config/nvim/init.vim
which haspython3_host_prog
,~/.config/nvim/coc-settings.json
which has bothpython.pythonPath
andpython.venvPath
, andjedi
hasjedi.executable.command
(I have read this).
I don't mind installing pynvim
and jedi-language-server
in each of my conda
/poetry
environments wasteful as that might sound - I'm just trying to get started!
Further, it's unclear if I need to install jedi
by hand? Can I just leave
let g:coc_global_extensions = ['coc-jedi']
in my init.vim
and have coc.nvim
do the rest?
P.S. Thanks for introducing me to autoimport.
I believe you'll need to install pynvim
everywhere (that's a Neovim requirement), but coc-jedi
manages the installation of jedi-language-server
in one place if you configure it appropriately. Everything's documented in the readme, but the relevant section is here.
And yes, Neovim + coc-jedi can discover what's been installed in your environment if you've installed pynvim. See the following screencast for what you should be able to do with proper configuration:
If you're looking for overall configuration recommendations, my vimrc is a gem: https://github.com/pappasam/dotfiles/blob/master/dotfiles/.config/nvim/init.vim
Additionally, I use the function ve
from my zshrc to create a virtualenv for Python. This automatically installs all the necessary software to make Vim behave. See: https://github.com/pappasam/dotfiles/blob/master/dotfiles/.zshrc#L981
Good luck on your configuration journey, there are no right answers in the Vim world, part of the fun is figuring out the exact setup that works for you. Soon you'll be able to do with every language what you used to do with Python in PyCharm!
Thanks for stopping by again - I will have a good look! (Not sure why I didn't think of going through your dotfiles!)
Allow me to close this for now. Cheers!