Skip to content

fix dunder all hover #4344 - #5587

Open
asukaminato0721 wants to merge 4 commits into
pyrefly-org:mainfrom
asukaminato0721:4344-dunder-all-hover
Open

asukaminato0721 wants to merge 4 commits into
pyrefly-org:mainfrom
asukaminato0721:4344-dunder-all-hover

Conversation

@asukaminato0721

@asukaminato0721 asukaminato0721 commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes part of #4344

Use the checked module's solved export type for __all__ hover and other type queries, including go-to-type-definition.

  • I am a human, and I fully understand the code I am submitting.

Test Plan

add test

@meta-codesync

meta-codesync Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D130538941. (Because this pull request was imported automatically, there will not be any future comments.)

@asukaminato0721 asukaminato0721 mentioned this pull request Nov 8, 2026
1 task done
@github-actions

This comment has been minimized.

@stroxler stroxler self-assigned this Nov 10, 2026

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feedback applies to both #5588 and #5587, they both seem to have the same structure where the LSP is doing more work than it probably should:


Could we rework this so __all__ entries resolve through the checked module’s semantic information, rather than treating go-to-definition locations as symbol types or identities?

Navigation can select a filesystem copy instead of the editor buffer, a source file instead of a stub, or one declaration instead of the final exported binding. Those choices are appropriate for navigation, but not for determining a symbol’s type or whether two occurrences refer to it.

The reconstruction to replace is:

In both PRs, get_hover_with_verbosity substitutes a type by calling get_type_at at the navigation target’s source position.
In 5588, the added local_references_from_definition block resolves each entry through navigation, then uses exact module-path/range equality as reference identity.

The replacement should live in the semantic query/reference layer in state/lsp.rs:

For exported-symbol hover, use the current checked handle’s solved export type: get_solutions(handle) and the retained KeyExport(name) answer. This represents the end-of-module export, rather than a particular declaration’s type.
For references, reuse the existing binding/import resolution behind find_export_for_key, key_to_intermediate_definition, and the normal reference collectors/indexes. Preserve local alias identity and existing buffer/source normalization.

There is no bound-name entry for an __all__ string today, so this is not just replacing one function call. Add a small shared occurrence bridge that connects the recognized name/content range to the existing local binding or import. KeyExport supplies the type; it does not itself supply reference identity.

Keep the useful entry extraction and alias handling. No binder overhaul is needed. Add native-LSP tests with open buffers, source/stub pairs and unopened dependencies—the warm memory-backed helper tests mask these failures.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@kinto0 kinto0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this addresses most of the earlier feedback: the type now comes from the solved KeyExport, and the native-LSP tests cover open buffers, stubs, and unopened dependencies. A few remaining points inline.

Nit: the summary still says "stack on #5586", but this diff against main contains only this change. Can you drop that line if #5586 has landed?

Comment thread pyrefly/lib/state/lsp.rs Resolved
Comment thread pyrefly/lib/state/lsp.rs Resolved
Comment thread pyrefly/lib/lsp/wasm/hover.rs Resolved
Comment thread pyrefly/lib/test/lsp/hover.rs Resolved
@kinto0 kinto0 mentioned this pull request Nov 13, 2026
1 task done

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@stroxler

Copy link
Copy Markdown
Contributor

Whoops sorry for the confusion. There are too many similar PRs, this one is close to ready I think but I'm handing off to @kinto0, and as he notes there are still some minor issues we should clean up.

Thanks for working on this!

Use the existing definition lookup to read the exported symbol type. Keep string literal types for strings outside __all__.
Read the current checked module’s final export answer so buffers, stubs, and unopened dependencies supply the correct type.
Resolve __all__ entries only after identifier lookup fails. Cover go-to-type-definition and remove unrelated hover changes.
@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants