Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jedi ignores extra paths #236

Open
eyalk11 opened this issue Nov 1, 2022 · 7 comments
Open

jedi ignores extra paths #236

eyalk11 opened this issue Nov 1, 2022 · 7 comments

Comments

@eyalk11
Copy link

eyalk11 commented Nov 1, 2022

I am on windows.

My current config is:

    root_dir = function() return vim.loop.cwd() end,
    init_options = {
        workspace = {
             extraPaths = {'./gui','./engine','./input'}
        }
    }

And it simply doesn't recognize much of my workspace. I tried using \ as well.
How can I see what folders it uses as workspace? Can I access jedi.Project somehow?

Also I did the following try:

proj=jedi.Project(dir)
list(proj.search('wanted'))

And it worked!

@pappasam
Copy link
Owner

pappasam commented Nov 1, 2022

@eyalk11 to help debug, can you please send me a link to a GitHub repo that contains an example directory of Python modules you're trying to get Jedi to analyze, along with what exactly you're trying to do (search workspace, get auto-completion, jump to definition, etc)

Also, some info that will make this easier to debug:

  1. Your Python version?
  2. Your LSP client?
  3. Your text editor?
  4. Your jedi-language-server version?
  5. Your windows version?
  6. Anything else you think might be helpful

@eyalk11
Copy link
Author

eyalk11 commented Nov 1, 2022

  1. Python version: 3.9.6
  2. I am using nvim-lspconfig . I check the symbols using:
    Telescope lsp_workspace_symbols .
  3. nvim v0.80
  4. 0.38.0
  5. windows 10 .

I think that what confuses it is that I use
sys.path.insert dynamically there inside __init___.py
But that doesn't explain the extra path thing. It does analyze the symbols of runsit.py , but not of most of the project.
I wish it had ignored sys.path and worked with all py files in the directory.

https://github.com/eyalk11/compare-my-stocks

current relevant config (on_attach defines keymaps).

require('telescope').setup{}
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())

require'lspconfig'.jedi_language_server.setup{
capabilities = capabilities,
   on_attach = on_attach,
    root_dir = function() return vim.loop.cwd() end,
    init_options = {
        workspace = {
             extraPaths ={'./gui','./engine','./input'}
        }
    }

}


Thanks a lot

@eyalk11
Copy link
Author

eyalk11 commented Nov 1, 2022

I got crash several times when I added the workspace directory to vim (src/compare_my_stocks). I use the windows \ in there.
vim.lsp.buf.add_workspace_folder The root compare-my-stocks is already there.

Also, it keeps saying

[INFO][2022-11-02 01:46:57] ...lsp/handlers.lua:489	"No pyproject.toml file found."
[WARN][2022-11-02 01:46:57] ...lsp/handlers.lua:487	"stubPath C:\\Users\\ekarni\\mypy\\stockscomp\\typings is not a valid directory."

Though I am not sure it is your client.

See the traceback in the log.

[DEBUG][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:364	"rpc.send"	{  jsonrpc = "2.0",  method = "workspace/didChangeWorkspaceFolders",  params = {    event = {      added = { {          name = "C:\\Users\\ekarni\\compare-my-stocks\\src\\compare_my_stocks",          uri = "file:///C:/Users/ekarni/compare-my-stocks/src/compare_my_stocks"        } },      removed = { {} }    }  }}
[DEBUG][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:364	"rpc.send"	{  jsonrpc = "2.0",  method = "workspace/didChangeWorkspaceFolders",  params = {    event = {      added = { {          name = "C:\\Users\\ekarni\\compare-my-stocks\\src\\compare_my_stocks",          uri = "file:///C:/Users/ekarni/compare-my-stocks/src/compare_my_stocks"        } },      removed = { {} }    }  }}
[DEBUG][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:364	"rpc.send"	{  jsonrpc = "2.0",  method = "workspace/didChangeWorkspaceFolders",  params = {    event = {      added = { {          name = "C:\\Users\\ekarni\\compare-my-stocks\\src\\compare_my_stocks",          uri = "file:///C:/Users/ekarni/compare-my-stocks/src/compare_my_stocks"        } },      removed = { {} }    }  }}
[DEBUG][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:364	"rpc.send"	{  jsonrpc = "2.0",  method = "workspace/didChangeWorkspaceFolders",  params = {    event = {      added = { {          name = "C:\\Users\\ekarni\\compare-my-stocks\\src\\compare_my_stocks",          uri = "file:///C:/Users/ekarni/compare-my-stocks/src/compare_my_stocks"        } },      removed = { {} }    }  }}
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'Traceback (most recent call last):\r\n  File "c:\\users\\ekarni\\appdata\\local\\nvim-data\\lsp_servers\\jedi_language_server\\venv\\lib\\site-packages\\pygls\\protocol.py", line 152, in deserialize_message\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'    deserialize_params(data, get_params_type)\r\n  File "c:\\users\\ekarni\\appdata\\local\\nvim-data\\lsp_servers\\jedi_language_server\\venv\\lib\\site-packages\\pygls\\protocol.py", line 138, in deserialize_params\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	"    data['params'] = params_type(**params)\r\n"
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'  File "c:\\users\\ekarni\\appdata\\local\\nvim-data\\lsp_servers\\jedi_language_server\\venv\\lib\\site-packages\\pygls\\lsp\\types\\basic_structures.py", line 58, in __init__\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'    super().__init__(**data)\r\n  File "pydantic\\main.py", line 342, in pydantic.main.BaseModel.__init__\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	"pydantic.error_wrappers.ValidationError: 2 validation errors for DidChangeWorkspaceFoldersParams\r\nevent -> removed -> 0 -> uri\r\n  field required (type=value_error.missing)\r\nevent -> removed -> 0 -> name\r\n  field required (type=value_error.missing)\r\n"
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File "C:\\Users\\ekarni\\.pyenv\\pyenv-win\\versions\\3.9\\lib\\runpy.py", line 197, in _run_module_as_main\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'    return _run_code(code, main_globals, None,\r\n  File "C:\\Users\\ekarni\\.pyenv\\pyenv-win\\versions\\3.9\\lib\\runpy.py", line 87, in _run_code\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	"    exec(code, run_globals)\r\n"
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'  File "C:\\Users\\ekarni\\AppData\\Local\\nvim-data\\lsp_servers\\jedi_language_server\\venv\\Scripts\\jedi-language-server.exe\\__main__.py", line 7, in <module>\r\n  File "c:\\users\\ekarni\\appdata\\local\\nvim-data\\lsp_servers\\jedi_language_server\\venv\\lib\\site-packages\\jedi_language_server\\cli.py", line 125, in cli\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'    SERVER.start_io()\r\n  File "c:\\users\\ekarni\\appdata\\local\\nvim-data\\lsp_servers\\jedi_language_server\\venv\\lib\\site-packages\\pygls\\server.py", line 225, in start_io\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'    self.loop.run_until_complete(\r\n  File "C:\\Users\\ekarni\\.pyenv\\pyenv-win\\versions\\3.9\\lib\\asyncio\\base_events.py", line 642, in run_until_complete\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'    return future.result()\r\n  File "c:\\users\\ekarni\\appdata\\local\\nvim-data\\lsp_servers\\jedi_language_server\\venv\\lib\\site-packages\\pygls\\server.py", line 78, in aio_readline\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	"    proxy(b''.join(message))\r\n  File \"c:\\users\\ekarni\\appdata\\local\\nvim-data\\lsp_servers\\jedi_language_server\\venv\\lib\\site-packages\\pygls\\protocol.py\", line 456, in data_received\r\n"
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'    json.loads(body.decode(self.CHARSET),\r\n  File "C:\\Users\\ekarni\\.pyenv\\pyenv-win\\versions\\3.9\\lib\\json\\__init__.py", line 359, in loads\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'    return cls(**kw).decode(s)\r\n  File "C:\\Users\\ekarni\\.pyenv\\pyenv-win\\versions\\3.9\\lib\\json\\decoder.py", line 337, in decode\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\r\n  File "C:\\Users\\ekarni\\.pyenv\\pyenv-win\\versions\\3.9\\lib\\json\\decoder.py", line 353, in raw_decode\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	'    obj, end = self.scan_once(s, idx)\r\n  File "c:\\users\\ekarni\\appdata\\local\\nvim-data\\lsp_servers\\jedi_language_server\\venv\\lib\\site-packages\\pygls\\protocol.py", line 154, in deserialize_message\r\n'
[ERROR][2022-11-02 01:42:44] .../vim/lsp/rpc.lua:439	"rpc"	"jedi-language-server"	"stderr"	"    raise JsonRpcInvalidParams()\r\npygls.exceptions.JsonRpcInvalidParams: Invalid Params\r\n"

@pappasam
Copy link
Owner

pappasam commented Nov 2, 2022

@eyalk11 in your example, you should specify your path from the root of your git repository (eg, where you've put your setup.py).

So: extraPaths ={'./src/compare_my_stocks/gui','./src/compare_my_stocks/engine','./src/compare_my_stocks/input'}

@pappasam
Copy link
Owner

pappasam commented Nov 2, 2022

The above works for me when using the repository you referenced:

Peek 2022-11-01 17-23

@eyalk11
Copy link
Author

eyalk11 commented Nov 4, 2022

Thanks for the effort. It doesn't work in my environment. How is it best to debug it?
image

@pappasam
Copy link
Owner

pappasam commented Nov 4, 2022

Not sure, but please let me know if you figure out what's wrong. Happy to add your findings to a FAQ in case someone else has a similar issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants