Skip to content

Conversation

@sgavriil01
Copy link

Fixes #1805

Shows the class instance type instead of -> None for constructor calls in both signature help and hover.

Changes

  • Constructor calls like Person() now show -> Person instead of -> None
  • Direct __init__ calls still show -> None
  • Generic constructors show the specialized type (e.g., Box[str])

Tests

  • Added 6 hover tests covering constructors, direct init calls, methods, and arguments
  • Added 1 signature help test for method calls
  • All 24 signature help tests passing
  • All 73 hover tests passing

Constructor calls now display the instance type instead of None in both
signature help and hover. Direct __init__ calls still show -> None.

Fixes facebook#1805
@meta-cla
Copy link

meta-cla bot commented Jan 17, 2026

Hi @sgavriil01!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@yangdanny97 yangdanny97 self-assigned this Jan 17, 2026
@yangdanny97 yangdanny97 requested a review from rchen152 January 17, 2026 16:00
@yangdanny97 yangdanny97 self-requested a review January 17, 2026 16:00
Param::Pos(name, self_type, _) | Param::PosOnly(Some(name), self_type, _),
) = params_list.items().first()
{
if name.as_str() == "self" || name.as_str() == "cls" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the should_override should be inititalized to false and set to true if all the conditions succeed, would reduce the size of these conditionals

contents
.get(start..end)
.map(|callee_text| {
if callee_text.ends_with(".__init__") {
Copy link
Contributor

Choose a reason for hiding this comment

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

this logic appears duplicated w/ the hover code - maybe we can add a util function to share it?

I also don't really like that we're doing string slicing here - is there a way to do it by detecting the CallTarget? If it's a call to a class name it would show up as CallTarget::Class, directly calling __init__ would not

Class(ClassType, ConstructorKind),

"#;
let report = get_batched_lsp_operations_report_allow_error(&[("main", code)], get_test_report);
assert!(
report.contains("-> Person"),
Copy link
Contributor

Choose a reason for hiding this comment

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

can we assert on the whole string in these tests

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious if we should do def Person(...) -> Person here, it might give it better highlighting properties

@yangdanny97
Copy link
Contributor

cc @rchen152 for second review since she wrote the original task

Copy link
Contributor

@yangdanny97 yangdanny97 left a comment

Choose a reason for hiding this comment

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

Back to you with some comments, thanks

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.

[lsp] Seeing signatures that contain -> None when constructing a class is confusing

2 participants