python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.76k stars 186 forks source link

Resolving Python Symbols with Wildcard Imports using python-lsp-server #425

Closed nashid closed 10 months ago

nashid commented 10 months ago

I've been using the python-lsp-server to analyze a Python project and extract symbol definitions and references. The server works well for explicit imports, but I've encountered an issue when dealing with wildcard imports (import *).

Example:

Consider the following code structure:

# utils.py
def check_files_in_directory():
    pass
# main.py
from utils import *

def main():
    check_files_in_directory()

When I try to resolve the check_files_in_directory function in main.py using the LSP server, it fails to determine its origin due to the wildcard import.

What I've tried:

  1. I've successfully resolved symbols for explicit imports, e.g., from utils import check_files_in_directory.
  2. I've checked the LSP server's capabilities and ensured I'm sending the correct requests.

Question:

Is there a way to make python-lsp-server resolve symbols imported with wildcard imports effectively? I understand wildcard imports can be challenging for static analysis tools since they obfuscate the origin of symbols. *Do I have to set some configuration? For my case, even if it the analysis takes time and it is slow to resolve it, that is not a problem.*

ccordoba12 commented 10 months ago

Pylsp is only a wrapper over several Python code completion and linting libraries. In this case Jedi is used to get definitions.

So, please ask in its repo if Jedi supports star imports (I guess not and that's why you don't get the definition you want).