Skip to content

fix support hover on getitem #1781 - #1817

Closed
asukaminato0721 wants to merge 3 commits into
pyrefly-org:mainfrom
asukaminato0721:1781
Closed

asukaminato0721 wants to merge 3 commits into
pyrefly-org:mainfrom
asukaminato0721:1781

Conversation

@asukaminato0721

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1781

Expanded find_definition_for_operator to recognize ExprSubscript nodes and map their context (Load/Store/Del) to the appropriate dunder (__getitem__, __setitem__, __delitem__), so hover lookups can resolve the underlying method definition when the cursor is on a bracket.

Ensured every implicit dunder invocation routed through call_method_or_error records the callable in the solver trace, allowing hover/type tooling to reuse the callable signature instead of the expression’s result type.

Test Plan

Added regression tests.

@meta-cla meta-cla Bot added the cla signed label Dec 11, 2025
@asukaminato0721

Copy link
Copy Markdown
Collaborator Author
image image

@asukaminato0721
asukaminato0721 marked this pull request as ready for review December 11, 2025 04:23
Copilot AI review requested due to automatic review settings December 11, 2025 04:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes hover support for subscript operators (issue #1781) by extending the LSP definition lookup to recognize ExprSubscript nodes and map them to their corresponding dunder methods (__getitem__, __setitem__, __delitem__). The implementation ensures that when hovering over a bracket in subscript operations, users see the signature of the underlying dunder method rather than just the result type.

Key Changes:

  • Extended find_definition_for_operator to handle ExprSubscript nodes by mapping context (Load/Store/Del) to appropriate dunders
  • Added trace recording in call_method_or_error to capture callable signatures for hover/type tooling
  • Added comprehensive tests for all three subscript operation types

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pyrefly/lib/test/lsp/hover.rs Added three regression tests for hover on __getitem__, __setitem__, and __delitem__ operators
pyrefly/lib/test/lsp/definition.rs Updated test expectations to verify definition lookup now resolves to __getitem__ for dictionary subscripts
pyrefly/lib/state/lsp.rs Implemented ExprSubscript handling in find_definition_for_operator to map subscription contexts to dunder methods
pyrefly/lib/alt/call.rs Added trace recording for method calls to enable hover lookup on dunder method invocations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pyrefly/lib/state/lsp.rs Resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

@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.

looks great!!

@meta-codesync

meta-codesync Bot commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D89061354.

@kinto0 kinto0 self-assigned this Dec 12, 2025

@yangdanny97 yangdanny97 left a comment

Copy link
Copy Markdown
Collaborator

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 commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

filed #1838 for remaining issue (it doesn't work without a space)

@meta-codesync

meta-codesync Bot commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

@kinto0 merged this pull request in 73ae460.

@asukaminato0721
asukaminato0721 deleted the 1781 branch December 13, 2025 08:35
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.

support hover on getitem

5 participants