I've installed neovim with some lsp-servers and setup them. But when I try to get in-module objects, completion suggest almost nothing (module has a lot of functions, but completion doesn't show it).
I have tried a lot of LSP servers (pylance, pyright, jedi, etc) and completion plugins(coq.nvim, nvim-cmp, coc.nvim) with the same result. Now I've installed coc and coc-pyright, it shows this error:"xxx" is not a known member of module
. It is false-error because python run this program correctly.
screenshots:opencv false-error, but lsp see opencv module, another false-error
Already, I have no idea what I can do to fix it.
Upd: I think type stubs might be the cause of the error. I don't really understand what is it, but I've found some common similar error with OpenCV lib here. In my case, completion does not work correctly with either opencv nor mediapipe. I've tried to generate the type stubs with pyright and stubgen, but it didn't help.
CodePudding user response:
I've just solved the problem:
- First we need to make a link to the lib in lib-dynload folder (it placed in
/path/to/python/lib/python/version/lib-dynload/
). You can do it withln /path/to/lib-dynload/ /path/to/library.so
In my case I entered next command:
ln ./python3.8/site-packages/cv2/python-3.8/cv2.cpython-38-x86_64-linux-gnu.so ./python3.8/lib-dynload/cv2.cpython-38-x86_64-linux-gnu.so
- After that you can generate the type stubs, and they will work. For my case with opencv lib, I entered:
stubgen -p cv2
- Import the type stubs to your LSP. E.g. for pyright you may just rename
out
folder totypings
You must have installed mypy
module to use stubgen
command. Some LSP servers are also able to create type stubs (e.g. pyright).