pappasam / jedi-language-server

A Python language server exclusively for Jedi. If Jedi supports it well, this language server should too.
MIT License
574 stars 44 forks source link

Problems with import resolution #297

Closed FatPigeorz closed 7 months ago

FatPigeorz commented 7 months ago

Hello there! 👋

I hope this message finds you well. I'm currently diving into the world of Jedi to implement some definition/reference retrival stuff. I've switched the language server of the VSCode Python extension to Jedi to gain a deeper understanding of the Jedi project, and also use the behaviour of vscode as a oracle to test my implementation.

However, I've encountered a situation where Jedi Language Server fails to resolve imports in certain cases, while Pylance succeeds in doing so.

FatPigeorz commented 7 months ago

sorry for accidentally submitting the draft :) here is a detailed description

Jedi: image Pylance: image

the Foo class is defined in src/foo/lib.py, I'm wondering if it is possible to get the definition of Foo via Jedi, or I can config something of jedi-langauge-server to get the definition. I've spent the a few days wrestling with this problem, and I'm starting to suspect that I might be missing something obvious. Any insights or fresh perspectives would be greatly appreciated

FatPigeorz commented 7 months ago

I've push the code for reproduction to this repo

davidhalter commented 7 months ago

You can give Jedi the correct sys path and everything works. Pylance seems to "arbitrarily" detect that there's a foo package within src. This might also be saved in settings.json. If you give Jedi that information it will work. Not sure how to do that via language server though.

FatPigeorz commented 7 months ago

You can give Jedi the correct sys path and everything works. Pylance seems to "arbitrarily" detect that there's a foo package within src. This might also be saved in settings.json. If you give Jedi that information it will work. Not sure how to do that via language server though.

Appreciate your response. It seems that Pylance has special handling for certain scenarios.. For instance, in a previous use case, when I renamed the 'src' directory to a name like 'srccc,' Pylance also encountered a failure like jedi:(.