Skip to content

LSP doesn't really understand DefinitionKind::ImportFromSubmodule #1759

@Gankra

Description

@Gankra

Summary

This covers the implicit subpkg = mypackage.subpkg local assignment that from .subpkg.whatever import blah creates in an __init__.py.

In astral-sh/ruff#21793 I added several tests for this and marked the bad results as TODO(submodule-imports)

✅ goto-type and hover work great, because they're just asking the inference engine or correctly using the fact that hovering the LHS of import-from is always modules.

🆗 goto-declaration mostly works, there's one "hmm what SHOULD this do" case and one "oh I think we're just seeing broken handling of imports writ-large"

The span is overly broad. This is because the Definition actually claims the entire from..import.. AST node. Unfortunately even if we made it only claim the LHS Identifier it would still be overly broad (from .x.y would highlight x.y instead of just x). So either way the LSP probably wants to special-case the span here. (fixed in astral-sh/ruff#21795)

❌ find-references/rename doesn't really understand it at all.

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingserverRelated to the LSP server

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions