-
Notifications
You must be signed in to change notification settings - Fork 232
No completion after import numpy. (possibly related: jedi.auto_import_modules) #704
Description
What does not work
This only happens to numpy imports. If I type
import numpy.
# or
import numpy.polynomial.
# or
from numpy.there will be no completions.
Environment I have tried
- Neovim + lspconfig, pylsp installed with mason
- Vim + vim-lsp, pylsp installed with
LspInstallServer - Geany + lsp plugin, pylsp installed with pacman
All combinations above behaves the same: no completion. I added no user configurations to these setups.
What I found
There was a issue in jedi repo: davidhalter/jedi#2021.
That issue shows nothing wrong about jedi, but setting jedi.settings.auto_import_modules = ["numpy"] actually causing the lack of completions. Also note davidhalter/jedi#2021 (comment)
if you use jedi.settings.auto_import_modules = ["numpy"], you are actually trying to disable parts of Jedi and this is not expected to work after it.
So I tested
In [6]:
...: jedi.settings.auto_import_modules = ["numpy"]
In [7]: script = jedi.Script("from numpy import ")
...: print(f"{len(script.complete())=}")
...:
...: script = jedi.Script("import numpy.")
...: print(f"{len(script.complete())=}")
len(script.complete())=534
len(script.complete())=0
In [8]:
...: jedi.settings.auto_import_modules = []
In [9]: script = jedi.Script("from numpy import ")
...: print(f"{len(script.complete())=}")
...:
...: script = jedi.Script("import numpy.")
...: print(f"{len(script.complete())=}")
len(script.complete())=542
len(script.complete())=33And I confirm setting the pylsp.plugins.jedi.auto_import_modules option in pylsp's configuration to be empty list will solve this issue.
So, is the default value of pylsp.plugins.jedi.auto_import_modules the root problem? Will there be any side effects after I change it?