Repository navigation
fix support hover on getitem #1781 - #1817
asukaminato0721 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
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_operatorto handleExprSubscriptnodes by mapping context (Load/Store/Del) to appropriate dunders - Added trace recording in
call_method_or_errorto 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
yangdanny97
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
filed #1838 for remaining issue (it doesn't work without a space) |


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.