0

When I start typing a line, for example plt.subp it will show suggestions from matplotlib.pyplot, if I have imported the library above. This is the expected behaviour. The problem is that this is not happening with numpy. For example say I want to write np.linspace; while I am typing, at no point in time it will show me the the dropdown menu with suggestions (e.g. when I write np.l I should get suggestions like log, log10, linspace, logspace, etc, but that does not happen). The weird thing is that after I type for example np.linspace(, Jedi will show me all the relevant information about linspace.

The setup: I am trying to set up VSCodium as a python IDE. In order to isolate the problem as much as I can, I have created a virtual environment and I use this as my Python Interpreter. I have installed a few libraries in the virtual environment, including numpy. I use Jedi as my language server. I have also installed the Python Extension.

Am I missing something obvious here? Do you have any troubleshooting suggestions?

Notes:

  • When I used anaconda as my interpreter, everything worked as expected. I have other issues with anaconda so I do not use it anymore.
  • When I use /bin/python as my interpreter this problem appears as well (I numpy installed in my system as well).
  • This is only happening in VSCodium. If I open a .py file with gvim for example, everything works as expected. This would be irrelevant as vim uses a different LSP (vim-lsp/asyncomplete/pylsp-all), but the weird thing is that when I used vim outside of the virtual environment, I would not get autocomplete suggestions for any imported module, although I would get suggestions for internal python commands. Vim/Gvim also worked as expected with the conda base activated.

Workaround

Using pylance instead of jedi solves the above problem. But this is not a solution of course.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • So for example, if you type `np.lins`, you don't get any suggestions, right? And the "relevant information" you mentioned is the Parameter Hints, right? (Another option is the Hover, but that seems unlikely given your description.) If so, I can reproduce that behaviour in Codium with Jedi. Although, if I type `np.lin`, I get `linalg` as a suggestion, which is a module, and if I type `np.nd` or `np.max`, I get `ndarray` and `maximum` (among others), which are a type and a ufunc, respectively. Please [edit] the question to add a specific example. – wjandrea Feb 11 '23 at 21:53
  • I'm assuming Jedi runs something like `help(np.linspace)` to get the parameter hints, which would explain why that works even if it doesn't know `np.linspace` exists. As for why it doesn't know it exists, it might be some complicated import structure in the NumPy package that Jedi can't parse, or maybe the functions are added to the namespace at runtime, IDK. I'd have to check the NumPy source code to get a better idea. – wjandrea Feb 11 '23 at 21:59
  • 1
    I added an example, I hope you understand what I mean now: I have imported " import numpy as np" and below that I start typing "np.l". The expected dropdown menu doesn't appear at any point. And yes you are correct, I do get the parameter hints after I have already written "np.linspace(". I also do not get the modules, type and ufunc suggestions that you do get. Basically I get no suggestions for numpy whatsoever. – DiscoMallard Feb 11 '23 at 22:33
  • Huh, that's weird that you don't get *any* suggestions but you do get the parameter hints. I'm not sure what would cause that. – wjandrea Feb 12 '23 at 19:38
  • Try typing `np.l` then pressing Ctrl+Space to get suggestions (or run command **Trigger Suggest** `editor.action.triggerSuggest`). – wjandrea Feb 12 '23 at 19:42
  • [I found an issue on Jedi's GitHub that might be relevant](https://github.com/davidhalter/jedi/issues/1864). It looks like you should try updating Jedi to the latest version, and it might not hurt to update NumPy either. – wjandrea Feb 12 '23 at 19:48
  • I just realized why I wasn't getting `linspace` as a suggestion: I had disabled function suggestions by accident. Argghhhh :) – wjandrea Feb 13 '23 at 00:11

1 Answers1

0

The similar issue has been solved on github.

The solution is that install jedi-language-server in your Python environment (system Python, conda, homebrew, etc) and update your settings.json with the path to your jedi-language-server executable. Example:

{
  "jedi.executable.command": "/PATH/TO/JEDI/LANGUAGE/SERVER"
}

By the way, Pylance is really a good choice.

MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13