Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 119 additions & 10 deletions crates/ty_ide/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ mod tests {
"#,
);

assert_snapshot!(test.hover(), @"
assert_snapshot!(test.hover(), @r"
def my_func(
a,
b
Expand Down Expand Up @@ -358,7 +358,7 @@ mod tests {
"#,
);

assert_snapshot!(test.hover(), @"
assert_snapshot!(test.hover(), @r"
def my_func(
a,
b
Expand Down Expand Up @@ -427,7 +427,7 @@ mod tests {
"#,
);

assert_snapshot!(test.hover(), @"
assert_snapshot!(test.hover(), @r"
<class 'MyClass'>
---------------------------------------------
This is such a great class!!
Expand Down Expand Up @@ -489,7 +489,7 @@ mod tests {
"#,
);

assert_snapshot!(test.hover(), @"
assert_snapshot!(test.hover(), @r"
<class 'MyClass'>
---------------------------------------------
This is such a great class!!
Expand Down Expand Up @@ -664,7 +664,7 @@ mod tests {
"#,
);

assert_snapshot!(test.hover(), @"
assert_snapshot!(test.hover(), @r"
<class 'MyClass'>
---------------------------------------------
This is such a great class!!
Expand Down Expand Up @@ -729,7 +729,7 @@ mod tests {
"#,
);

assert_snapshot!(test.hover(), @"
assert_snapshot!(test.hover(), @r"
bound method MyClass.my_method(
a,
b
Expand Down Expand Up @@ -2045,7 +2045,7 @@ def ab(a: int, *, c: int):
)
.unwrap();

assert_snapshot!(test.hover(), @"
assert_snapshot!(test.hover(), @r"
<module 'lib'>
---------------------------------------------
The cool lib_py module!
Expand Down Expand Up @@ -2599,7 +2599,7 @@ def function():
)
.unwrap();

assert_snapshot!(test.hover(), @"
assert_snapshot!(test.hover(), @r"
<module 'lib'>
---------------------------------------------
The cool lib_py module!
Expand Down Expand Up @@ -2999,7 +2999,7 @@ def function():
"#,
);

assert_snapshot!(test.hover(), @"
assert_snapshot!(test.hover(), @r"
int
---------------------------------------------
This is the docs for this value
Expand Down Expand Up @@ -3088,7 +3088,7 @@ def function():
"#,
);

assert_snapshot!(test.hover(), @"
assert_snapshot!(test.hover(), @r"
int
---------------------------------------------
This is the docs for this value
Expand Down Expand Up @@ -4588,6 +4588,115 @@ def function():
");
}

#[test]
fn hover_multi_inference() {
let test = cursor_test(
r#"
def list1[T](x: T) -> list[T]:
return [x]

def f(x: int, y: int) -> list[int] | list[str]:
return list1(x<CURSOR> + y)
"#,
);

assert_snapshot!(test.hover(), @r"
int
---------------------------------------------
```python
int
```
---------------------------------------------
info[hover]: Hovered content is
--> main.py:6:18
|
5 | def f(x: int, y: int) -> list[int] | list[str]:
6 | return list1(x + y)
| ^- Cursor offset
| |
| source
|
");

let test = cursor_test(
r#"
def f(x: int, y: int) -> list[int] | list[str]:
return [x<CURSOR> + y]
"#,
);

assert_snapshot!(test.hover(), @r"
int
---------------------------------------------
```python
int
```
---------------------------------------------
info[hover]: Hovered content is
--> main.py:3:13
|
2 | def f(x: int, y: int) -> list[int] | list[str]:
3 | return [x + y]
| ^- Cursor offset
| |
| source
|
");

let test = cursor_test(
r#"
def list1[T](x: T) -> list[T]:
return [x]

def f(x: int, y: int) -> list[int] | list[str]:
return (_<CURSOR> := list1(x + y))
"#,
);

assert_snapshot!(test.hover(), @r"
list[int]
---------------------------------------------
```python
list[int]
```
---------------------------------------------
info[hover]: Hovered content is
--> main.py:6:13
|
5 | def f(x: int, y: int) -> list[int] | list[str]:
6 | return (_ := list1(x + y))
| ^- Cursor offset
| |
| source
|
");

let test = cursor_test(
r#"
def f(x: int, y: int) -> list[int] | list[str]:
return (_<CURSOR> := [x + y])
"#,
);

assert_snapshot!(test.hover(), @r"
list[int]
---------------------------------------------
```python
list[int]
```
---------------------------------------------
info[hover]: Hovered content is
--> main.py:3:13
|
2 | def f(x: int, y: int) -> list[int] | list[str]:
3 | return (_ := [x + y])
| ^- Cursor offset
| |
| source
|
");
}

#[test]
fn hover_submodule_import_from_use() {
let test = CursorTest::builder()
Expand Down
Loading
Loading