Skip to content

fix Hover on datetime.datetime import does not show constructor signature & docstring #2814#2847

Open
asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
asukaminato0721:2814
Open

fix Hover on datetime.datetime import does not show constructor signature & docstring #2814#2847
asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
asukaminato0721:2814

Conversation

@asukaminato0721
Copy link
Contributor

Summary

Fixes #2814

changing class hover rendering so non-definition class symbols show constructor information instead of the generic type[Class] form, while still keeping the class docstring.

Test Plan

add test

@meta-cla meta-cla bot added the cla signed label Mar 22, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review March 22, 2026 00:18
Copilot AI review requested due to automatic review settings March 22, 2026 00:18
Copy link

Copilot AI left a comment

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 updates Pyrefly’s hover rendering so that hovering a non-definition class symbol (e.g., an imported class) shows the constructor call signature instead of the generic type[Class] form, while preserving docstring display. It also updates and adds tests to validate the new hover output.

Changes:

  • Add hover formatting logic to display class constructor signatures for non-definition class symbols.
  • Update existing LSP interaction hover tests to match the new hover rendering.
  • Add a new hover regression test covering imported class constructor signature + docstring.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pyrefly/lib/lsp/wasm/hover.rs Adds constructor-signature rendering for imported/non-definition class hovers and wires it into get_hover.
pyrefly/lib/test/lsp/lsp_interaction/hover.rs Updates hover interaction assertions to match the new constructor-style output.
pyrefly/lib/test/lsp/lsp_interaction/configuration.rs Updates hover interaction assertions in configuration-related tests to match new output.
pyrefly/lib/test/lsp/hover.rs Adds a new regression test for imported class hover showing constructor signature + docstring.

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

Comment on lines +356 to +370
fn class_constructor_display(
transaction: &Transaction<'_>,
handle: &Handle,
position: TextSize,
kind: Option<SymbolKind>,
type_: &Type,
name: Option<&str>,
) -> Option<String> {
if kind != Some(SymbolKind::Class)
|| transaction
.identifier_at(handle, position)
.is_some_and(|id| matches!(id.context, IdentifierContext::ClassDef { .. }))
{
return None;
}
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

class_constructor_display will also rewrite hovers for class symbols whose displayed name differs from the underlying ClassType being hovered (e.g. from typing import List currently shows List: type[list], but this logic would likely switch it to the list constructor signature). That can be misleading because the hover header still says (class) List while the signature corresponds to a different class. Consider adding a guard that only applies this constructor formatting when the hovered symbol name matches the underlying class name (cls.name()), otherwise fall back to the existing type[...] display.

Copilot uses AI. Check for mistakes.
@github-actions

This comment has been minimized.

@asukaminato0721 asukaminato0721 marked this pull request as draft March 22, 2026 01:20
@asukaminato0721 asukaminato0721 marked this pull request as ready for review March 22, 2026 11:20
@github-actions
Copy link

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

@meta-codesync
Copy link

meta-codesync bot commented Mar 22, 2026

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

@yangdanny97 yangdanny97 self-assigned this Mar 22, 2026
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.

Hover on datetime.datetime import does not show constructor signature & docstring

3 participants