Skip to content

Conversation

@aaron-ang
Copy link
Contributor

@aaron-ang aaron-ang commented Nov 3, 2025

Close #1416.

Apparently, the issue of the method name not displaying has been fixed. I added a test case to verify this, and also refactored OverloadedCallee to an enum to better distinguish between resolved (show one) vs candidate (show all) traces.

Screenshot 2025-11-10 at 7 04 03 PM

@meta-cla meta-cla bot added the cla signed label Nov 3, 2025
Copy link
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

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

thanks for the contribution! i'm trying to assign you to the issue but it's not letting me put your name in. maybe you need to comment no that issue?

8 | result = a == b
^
Hover Result: `(self: My, other: object) -> bool`
Hover Result: `BoundMethod[My, (self: My, other: object) -> bool]`
Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't seem like it displays overloaded method name for everything. i'd expect to see __eq__ here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hover_type test suite reports the type only, so the code changes made this diff.

fn get_test_report(state: &State, handle: &Handle, position: TextSize) -> String {
if let Some(t) = state.transaction().get_type_at(handle, position) {
format!("Hover Result: `{t}`")
} else {
"Hover Result: None".to_owned()
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test cases in hover.rs verify the display.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think this is probably a regression. users don't want to see BoundMethod in the hover type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fn overloaded_methods_test() {
let code = r#"
from typing import overload
class Foo:
@overload
def overloaded_meth(self, a: str) -> bool: ...
@overload
def overloaded_meth(self, a: int, b: bool) -> str: ...
def overloaded_meth(self):
pass
foo = Foo()
foo.overloaded_meth("")
# ^
foo.overloaded_meth(1, True)
# ^
foo.overloaded_meth(False)
# ^
"#;
let report = get_batched_lsp_operations_report_allow_error(&[("main", code)], get_test_report);
assert_eq!(
r#"
# main.py
13 | foo.overloaded_meth("")
^
Hover Result: `(self: Foo, a: str) -> bool`
15 | foo.overloaded_meth(1, True)
^
Hover Result: `(self: Foo, a: int, b: bool) -> str`
17 | foo.overloaded_meth(False)
^
Hover Result: `BoundMethod[Foo, Overload[(self: Foo, a: str) -> bool, (self: Foo, a: int, b: bool) -> str]]`

@kinto0 an existing test expects BoundMethod on hover when the method does not match any of the overloaded function signatures. I may have misinterpreted when it should be shown. Can I get some clarification here?

@aaron-ang
Copy link
Contributor Author

@kinto0 I've changed OverloadCallee into an enum to decouple the two cases. Tracing the call stack, record_overload_trace_from_type is used to insert resolved dunder methods, so I named one of the variants as such.

is_closest_overload_chosen: bool,
enum OverloadedCallee {
Resolved {
ty: Arc<Type>,
Copy link
Contributor

Choose a reason for hiding this comment

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

in general, every time we export this Type type, there's a lot of overhead. we probably want to only export the necessary part. in this case, you only need the callable + the name. in another change, we might also want "type" to make the method change but I see that as another PR to "make hover for methods say (method) instead of (attribute).

thoughts @stroxler ?

@aaron-ang aaron-ang force-pushed the missing-method branch 2 times, most recently from 6713342 to 50975d0 Compare November 5, 2025 06:02
@aaron-ang
Copy link
Contributor Author

rebased

@kinto0
Copy link
Contributor

kinto0 commented Nov 6, 2025

looks like some tests are still failing

@aaron-ang
Copy link
Contributor Author

looks like some tests are still failing

@kinto0 I have fixed my test cases.

@meta-codesync
Copy link

meta-codesync bot commented Nov 7, 2025

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

Copy link
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

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

hey, thanks for keeping it updated with all our changes coming in. this is a lot of work.

I still am not 100% sure we want to expose Type everywhere. It's not needed for this task, since the test passes without it. If you still want to expose type, what if we split that into another PR where we can weigh the pros/cons? fwiw, I tested the performance on the IG codebase (20+MLOC) and it didn't make a huge difference.

happy to merge this right now with just the test addition

}

#[test]
fn hover_over_overloaded_binary_operator_shows_dunder_name() {
Copy link
Contributor

@kinto0 kinto0 Nov 10, 2025

Choose a reason for hiding this comment

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

this test actually passes before your change.... maybe this feature is done in the meantime or the bug report was incorrect

what if you split this into two PRs:

Copy link
Contributor Author

@aaron-ang aaron-ang Nov 10, 2025

Choose a reason for hiding this comment

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

After I rebased this branch onto main, the test failed the assertion:

<(method) __matmul__: def __matmul__(
>(attribute) __matmul__: (
    self: Matrix,
    other: Matrix
<) -> Matrix: ...
>) -> Matrix

Copy link
Contributor Author

@aaron-ang aaron-ang Nov 10, 2025

Choose a reason for hiding this comment

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

If it's ok for the method to be named as an attribute for now, I will refactor the PR to reflect this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also want to add that I was able to reproduce the issue on my machine while working on it initially. So the bug report is legit, and the issue may have been fixed elsewhere afterwards.

8 | result = a == b
^
Hover Result: `(self: My, other: object) -> bool`
Hover Result: `BoundMethod[My, (self: My, other: object) -> bool]`
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think this is probably a regression. users don't want to see BoundMethod in the hover type

@aaron-ang aaron-ang changed the title Display overloaded method name in hover trace Verify overloaded method name displays in hover trace Nov 10, 2025
@kinto0
Copy link
Contributor

kinto0 commented Nov 11, 2025

thanks for the split. I like your refactor too

Copy link
Contributor

@stroxler stroxler left a comment

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync bot closed this in 4ee45a9 Nov 11, 2025
@meta-codesync
Copy link

meta-codesync bot commented Nov 11, 2025

@kinto0 merged this pull request in 4ee45a9.

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 operator missing the magic method name and highlight

4 participants