Skip to content

impl Class Hierarchy #2207 - #2687

Open
asukaminato0721 wants to merge 2 commits into
facebook:mainfrom
asukaminato0721:2207-4972
Open

impl Class Hierarchy #2207#2687
asukaminato0721 wants to merge 2 commits into
facebook:mainfrom
asukaminato0721:2207-4972

Conversation

@asukaminato0721

Copy link
Copy Markdown
Collaborator

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

@meta-cla meta-cla Bot added the cla signed label Mar 6, 2026
@github-actions

This comment has been minimized.

@asukaminato0721
asukaminato0721 marked this pull request as ready for review March 6, 2026 14:51
Copilot AI review requested due to automatic review settings March 6, 2026 14:51

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 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 OverrideCodeLensProvider that 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_declaration to 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.

Comment thread lsp/src/overrideCodeLens.ts Outdated
Comment thread lsp/src/overrideCodeLens.ts Outdated
Comment thread lsp/src/extension.ts
Comment on lines +229 to +235
context.subscriptions.push(
workspace.onDidChangeTextDocument(event => {
if (event.document.languageId === 'python') {
overrideCodeLensProvider.refresh();
}
}),
);

Copilot AI Mar 6, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread pyrefly/lib/state/lsp.rs
Comment on lines +2005 to +2019
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)

Copilot AI Mar 6, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread pyrefly/lib/state/lsp.rs Outdated
Comment thread pyrefly/lib/state/lsp.rs Outdated
@asukaminato0721
asukaminato0721 marked this pull request as draft March 6, 2026 19:21
@asukaminato0721
asukaminato0721 marked this pull request as ready for review March 6, 2026 19:37
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@meta-codesync

meta-codesync Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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

@codspeed-hq

codspeed-hq Bot commented Jul 28, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing asukaminato0721:2207-4972 (5bd5be4) with main (3ad3a27)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

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

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.

3 participants