Skip to content

Commit dbbd11a

Browse files
fix
1 parent 947a3ee commit dbbd11a

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

pyrefly/lib/lsp/wasm/hover.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ pub fn get_hover(
542542
.get_callables_from_call(handle, position)
543543
.map(|info| info.callee_range)
544544
.or_else(find_callee_range_at_position);
545+
let hovering_over_callee = callee_range_opt.is_some_and(|range| range.contains(position));
545546

546547
if let Some(callee_range) = callee_range_opt {
547548
let is_constructor = transaction
@@ -550,6 +551,8 @@ pub fn get_hover(
550551
.is_some_and(is_constructor_call);
551552
if is_constructor && let Some(new_type) = override_constructor_return_type(type_.clone()) {
552553
type_ = new_type;
554+
} else if hovering_over_callee {
555+
type_ = transaction.coerce_type_to_callable(handle, type_);
553556
}
554557
}
555558

pyrefly/lib/test/lsp/hover.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,36 @@ greeter("hi")
177177
);
178178
}
179179

180+
#[test]
181+
fn hover_on_callable_protocol_attribute_uses_dunder_call_signature() {
182+
let code = r#"
183+
from typing import Protocol, cast
184+
185+
class Parametrize(Protocol):
186+
def __call__(self, argnames: str, *, ids: list[str] | None = None) -> int: ...
187+
188+
class Mark:
189+
parametrize: Parametrize
190+
191+
mark = cast(Mark, ...)
192+
mark.parametrize("role", ids=["owner"])
193+
# ^^^^^^^^^^^
194+
"#;
195+
let report = get_batched_lsp_operations_report(&[("main", code)], get_test_report);
196+
assert!(
197+
report.contains("__call__"),
198+
"Expected hover to refer to __call__, got: {report}"
199+
);
200+
assert!(
201+
report.contains("argnames: str"),
202+
"Expected hover to show the positional parameter, got: {report}"
203+
);
204+
assert!(
205+
report.contains("ids: list[str] | None = None"),
206+
"Expected hover to show the keyword-only parameter, got: {report}"
207+
);
208+
}
209+
180210
#[test]
181211
fn hover_over_inline_ignore_comment() {
182212
let code = r#"

0 commit comments

Comments
 (0)