impl Class Hierarchy #2207 - #2687
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR adds an overrides/implementations CodeLens experience for Python in the VS Code extension and extends the backend go-to-declaration behavior so overriding members can navigate to the overridden parent declaration (supporting class hierarchy/navigation work tracked in #2207).
Changes:
- Added a new VS Code
OverrideCodeLensProviderthat shows “Overrides …” and “Implemented by …” lenses based on declaration/implementation providers. - Registered the provider and navigation/quick-pick commands in the extension activation flow.
- Updated backend
goto_declarationto redirect overriding members to parent declarations, and added regression tests for method + class attribute overrides.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| pyrefly/lib/test/lsp/definition.rs | Adds tests validating go-to-declaration jumps from overrides to parent declarations. |
| pyrefly/lib/state/lsp.rs | Adds override-parent lookup logic to goto_declaration plus a helper for resolving module info from a ModulePath. |
| lsp/src/overrideCodeLens.ts | Implements the CodeLens provider and navigation commands for override/implementation targets. |
| lsp/src/extension.ts | Registers the CodeLens provider, hooks refreshes, and registers navigation commands. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| context.subscriptions.push( | ||
| workspace.onDidChangeTextDocument(event => { | ||
| if (event.document.languageId === 'python') { | ||
| overrideCodeLensProvider.refresh(); | ||
| } | ||
| }), | ||
| ); |
There was a problem hiding this comment.
Refreshing CodeLenses on every onDidChangeTextDocument for Python means this provider will re-run (and potentially issue many LSP requests) on every keystroke. Consider debouncing this refresh (timer-based) and/or refreshing only on saves / when the edited document is the active editor to reduce churn.
| fn parent_declarations_for_definition( | ||
| &self, | ||
| handle: &Handle, | ||
| definition: &TextRangeWithModule, | ||
| ) -> Vec<TextRangeWithModule> { | ||
| let Some(index) = self | ||
| .get_solutions(handle) | ||
| .and_then(|solutions| solutions.get_index()) | ||
| else { | ||
| return Vec::new(); | ||
| }; | ||
| let Some(parent_methods) = index | ||
| .lock() | ||
| .parent_methods_map | ||
| .get(&definition.range) |
There was a problem hiding this comment.
parent_declarations_for_definition always reads the solutions index for the current handle, but it looks up overrides by definition.range (a TextRange without module identity). If find_definition returns a definition in another module (e.g. imports/stubs), this can either miss the override info or accidentally match an unrelated range in the current module and return incorrect parent declarations. Consider only applying this override-redirect when definition.module.path() matches the current module, or resolve the correct handle/index for definition.module before consulting parent_methods_map.
This comment has been minimized.
This comment has been minimized.
5ffd72b to
3b624e4
Compare
This comment has been minimized.
This comment has been minimized.
3b624e4 to
7caf02c
Compare
This comment has been minimized.
This comment has been minimized.
7caf02c to
dd3e847
Compare
This comment has been minimized.
This comment has been minimized.
dd3e847 to
8777e0b
Compare
This comment has been minimized.
This comment has been minimized.
8777e0b to
a23e70b
Compare
This comment has been minimized.
This comment has been minimized.
a23e70b to
b0d9b11
Compare
|
This pull request has been imported. If you are a Meta employee, you can view this in D113979798. (Because this pull request was imported automatically, there will not be any future comments.) |
Merging this PR will not alter performance
Comparing Footnotes
|
This comment has been minimized.
This comment has been minimized.
b0d9b11 to
5bd5be4
Compare
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Summary
Fixes part of #2207
ref microsoft/pylance-release#4972 (comment)
Added a client-side Python CodeLens provider that shows:
- $(arrow-up) Overrides ... on overriding methods
- $(arrow-down) Implemented by ... / implementation counts on parent methods
Registered the provider plus navigation/quick-pick commands
Implemented the provider
Test Plan
Added backend regression coverage for that parent-resolution path