[ty] Use dedent in cursor tests (#20019)
Some checks are pending
CI / mkdocs (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run

This commit is contained in:
Micha Reiser 2025-08-21 10:31:54 +02:00 committed by GitHub
parent a5cbca156c
commit 045cba382a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 596 additions and 595 deletions

View file

@ -53,14 +53,14 @@ mod tests {
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:2:17 --> main.py:2:5
| |
2 | def my_function(x, y): 2 | def my_function(x, y):
| ^^^^^^^^^^^ | ^^^^^^^^^^^
3 | return x + y 3 | return x + y
| |
info: Source info: Source
--> main.py:5:22 --> main.py:5:10
| |
3 | return x + y 3 | return x + y
4 | 4 |
@ -81,14 +81,14 @@ mod tests {
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:2:13 --> main.py:2:1
| |
2 | x = 42 2 | x = 42
| ^ | ^
3 | y = x 3 | y = x
| |
info: Source info: Source
--> main.py:3:17 --> main.py:3:5
| |
2 | x = 42 2 | x = 42
3 | y = x 3 | y = x
@ -111,7 +111,7 @@ mod tests {
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:2:19 --> main.py:2:7
| |
2 | class MyClass: 2 | class MyClass:
| ^^^^^^^ | ^^^^^^^
@ -119,7 +119,7 @@ mod tests {
4 | pass 4 | pass
| |
info: Source info: Source
--> main.py:6:24 --> main.py:6:12
| |
4 | pass 4 | pass
5 | 5 |
@ -140,14 +140,14 @@ mod tests {
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:2:21 --> main.py:2:9
| |
2 | def foo(param): 2 | def foo(param):
| ^^^^^ | ^^^^^
3 | return param * 2 3 | return param * 2
| |
info: Source info: Source
--> main.py:3:24 --> main.py:3:12
| |
2 | def foo(param): 2 | def foo(param):
3 | return param * 2 3 | return param * 2
@ -168,7 +168,7 @@ mod tests {
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:2:30 --> main.py:2:18
| |
2 | def generic_func[T](value: T) -> T: 2 | def generic_func[T](value: T) -> T:
| ^ | ^
@ -176,7 +176,7 @@ mod tests {
4 | return v 4 | return v
| |
info: Source info: Source
--> main.py:3:20 --> main.py:3:8
| |
2 | def generic_func[T](value: T) -> T: 2 | def generic_func[T](value: T) -> T:
3 | v: T = value 3 | v: T = value
@ -198,7 +198,7 @@ mod tests {
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:2:32 --> main.py:2:20
| |
2 | class GenericClass[T]: 2 | class GenericClass[T]:
| ^ | ^
@ -206,7 +206,7 @@ mod tests {
4 | self.value = value 4 | self.value = value
| |
info: Source info: Source
--> main.py:3:43 --> main.py:3:31
| |
2 | class GenericClass[T]: 2 | class GenericClass[T]:
3 | def __init__(self, value: T): 3 | def __init__(self, value: T):
@ -230,7 +230,7 @@ mod tests {
assert_snapshot!(test.goto_declaration(), @r#" assert_snapshot!(test.goto_declaration(), @r#"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:2:13 --> main.py:2:1
| |
2 | x = "outer" 2 | x = "outer"
| ^ | ^
@ -238,7 +238,7 @@ mod tests {
4 | def inner_func(): 4 | def inner_func():
| |
info: Source info: Source
--> main.py:5:28 --> main.py:5:16
| |
3 | def outer_func(): 3 | def outer_func():
4 | def inner_func(): 4 | def inner_func():
@ -852,7 +852,7 @@ def another_helper(path):
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:4:21 --> main.py:4:9
| |
2 | class C: 2 | class C:
3 | def __init__(self): 3 | def __init__(self):
@ -862,7 +862,7 @@ def another_helper(path):
6 | c = C() 6 | c = C()
| |
info: Source info: Source
--> main.py:7:19 --> main.py:7:7
| |
6 | c = C() 6 | c = C()
7 | y = c.x 7 | y = c.x
@ -890,7 +890,7 @@ def another_helper(path):
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:4:21 --> main.py:4:9
| |
2 | class C: 2 | class C:
3 | def __init__(self): 3 | def __init__(self):
@ -900,7 +900,7 @@ def another_helper(path):
6 | class D: 6 | class D:
| |
info: Source info: Source
--> main.py:11:21 --> main.py:11:9
| |
10 | d = D() 10 | d = D()
11 | y = d.y.x 11 | y = d.y.x
@ -924,7 +924,7 @@ def another_helper(path):
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:4:21 --> main.py:4:9
| |
2 | class C: 2 | class C:
3 | def __init__(self): 3 | def __init__(self):
@ -934,7 +934,7 @@ def another_helper(path):
6 | c = C() 6 | c = C()
| |
info: Source info: Source
--> main.py:7:19 --> main.py:7:7
| |
6 | c = C() 6 | c = C()
7 | y = c.x 7 | y = c.x
@ -958,7 +958,7 @@ def another_helper(path):
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:3:21 --> main.py:3:9
| |
2 | class C: 2 | class C:
3 | def foo(self): 3 | def foo(self):
@ -966,7 +966,7 @@ def another_helper(path):
4 | return 42 4 | return 42
| |
info: Source info: Source
--> main.py:7:21 --> main.py:7:9
| |
6 | c = C() 6 | c = C()
7 | res = c.foo() 7 | res = c.foo()
@ -1103,7 +1103,7 @@ def function():
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:3:17 --> main.py:3:5
| |
2 | class A: 2 | class A:
3 | x = 10 3 | x = 10
@ -1112,7 +1112,7 @@ def function():
5 | class B(A): 5 | class B(A):
| |
info: Source info: Source
--> main.py:9:19 --> main.py:9:7
| |
8 | b = B() 8 | b = B()
9 | y = b.x 9 | y = b.x
@ -1140,7 +1140,7 @@ def function():
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:7:21 --> main.py:7:9
| |
6 | @property 6 | @property
7 | def value(self): 7 | def value(self):
@ -1148,7 +1148,7 @@ def function():
8 | return self._value 8 | return self._value
| |
info: Source info: Source
--> main.py:11:15 --> main.py:11:3
| |
10 | c = C() 10 | c = C()
11 | c.value = 42 11 | c.value = 42
@ -1213,7 +1213,7 @@ def function():
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:6:17 --> main.py:6:5
| |
4 | class Drawable(Protocol): 4 | class Drawable(Protocol):
5 | def draw(self) -> None: ... 5 | def draw(self) -> None: ...
@ -1223,7 +1223,7 @@ def function():
8 | def use_drawable(obj: Drawable): 8 | def use_drawable(obj: Drawable):
| |
info: Source info: Source
--> main.py:9:21 --> main.py:9:9
| |
8 | def use_drawable(obj: Drawable): 8 | def use_drawable(obj: Drawable):
9 | obj.name 9 | obj.name
@ -1280,14 +1280,14 @@ class MyClass:
assert_snapshot!(test.goto_declaration(), @r" assert_snapshot!(test.goto_declaration(), @r"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:2:32 --> main.py:2:20
| |
2 | def my_function(x, y, z=10): 2 | def my_function(x, y, z=10):
| ^ | ^
3 | return x + y + z 3 | return x + y + z
| |
info: Source info: Source
--> main.py:5:37 --> main.py:5:25
| |
3 | return x + y + z 3 | return x + y + z
4 | 4 |
@ -1320,7 +1320,7 @@ class MyClass:
// Should navigate to the parameter in both matching overloads // Should navigate to the parameter in both matching overloads
assert_snapshot!(test.goto_declaration(), @r#" assert_snapshot!(test.goto_declaration(), @r#"
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:5:36 --> main.py:5:24
| |
4 | @overload 4 | @overload
5 | def process(data: str, format: str) -> str: ... 5 | def process(data: str, format: str) -> str: ...
@ -1329,7 +1329,7 @@ class MyClass:
7 | @overload 7 | @overload
| |
info: Source info: Source
--> main.py:14:39 --> main.py:14:27
| |
13 | # Call the overloaded function 13 | # Call the overloaded function
14 | result = process("hello", format="json") 14 | result = process("hello", format="json")
@ -1337,7 +1337,7 @@ class MyClass:
| |
info[goto-declaration]: Declaration info[goto-declaration]: Declaration
--> main.py:8:36 --> main.py:8:24
| |
7 | @overload 7 | @overload
8 | def process(data: int, format: int) -> int: ... 8 | def process(data: int, format: int) -> int: ...
@ -1346,7 +1346,7 @@ class MyClass:
10 | def process(data, format): 10 | def process(data, format):
| |
info: Source info: Source
--> main.py:14:39 --> main.py:14:27
| |
13 | # Call the overloaded function 13 | # Call the overloaded function
14 | result = process("hello", format="json") 14 | result = process("hello", format="json")

View file

@ -50,7 +50,7 @@ mod tests {
assert_snapshot!(test.goto_type_definition(), @r" assert_snapshot!(test.goto_type_definition(), @r"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:2:19 --> main.py:2:7
| |
2 | class Test: ... 2 | class Test: ...
| ^^^^ | ^^^^
@ -58,7 +58,7 @@ mod tests {
4 | ab = Test() 4 | ab = Test()
| |
info: Source info: Source
--> main.py:4:13 --> main.py:4:1
| |
2 | class Test: ... 2 | class Test: ...
3 | 3 |
@ -82,7 +82,7 @@ mod tests {
assert_snapshot!(test.goto_type_definition(), @r" assert_snapshot!(test.goto_type_definition(), @r"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:2:17 --> main.py:2:5
| |
2 | def foo(a, b): ... 2 | def foo(a, b): ...
| ^^^ | ^^^
@ -90,7 +90,7 @@ mod tests {
4 | ab = foo 4 | ab = foo
| |
info: Source info: Source
--> main.py:6:13 --> main.py:6:1
| |
4 | ab = foo 4 | ab = foo
5 | 5 |
@ -120,7 +120,7 @@ mod tests {
assert_snapshot!(test.goto_type_definition(), @r" assert_snapshot!(test.goto_type_definition(), @r"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:3:17 --> main.py:3:5
| |
3 | def foo(a, b): ... 3 | def foo(a, b): ...
| ^^^ | ^^^
@ -128,7 +128,7 @@ mod tests {
5 | def bar(a, b): ... 5 | def bar(a, b): ...
| |
info: Source info: Source
--> main.py:12:13 --> main.py:12:1
| |
10 | a = bar 10 | a = bar
11 | 11 |
@ -137,7 +137,7 @@ mod tests {
| |
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:5:17 --> main.py:5:5
| |
3 | def foo(a, b): ... 3 | def foo(a, b): ...
4 | 4 |
@ -147,7 +147,7 @@ mod tests {
7 | if random.choice(): 7 | if random.choice():
| |
info: Source info: Source
--> main.py:12:13 --> main.py:12:1
| |
10 | a = bar 10 | a = bar
11 | 11 |
@ -177,7 +177,7 @@ mod tests {
| ^^^^^^ | ^^^^^^
| |
info: Source info: Source
--> main.py:4:13 --> main.py:4:1
| |
2 | import lib 2 | import lib
3 | 3 |
@ -197,7 +197,7 @@ mod tests {
"#, "#,
); );
assert_snapshot!(test.goto_type_definition(), @r###" assert_snapshot!(test.goto_type_definition(), @r#"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> stdlib/builtins.pyi:901:7 --> stdlib/builtins.pyi:901:7
| |
@ -209,14 +209,14 @@ mod tests {
903 | str(bytes_or_buffer[, encoding[, errors]]) -> str 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str
| |
info: Source info: Source
--> main.py:4:13 --> main.py:4:1
| |
2 | a: str = "test" 2 | a: str = "test"
3 | 3 |
4 | a 4 | a
| ^ | ^
| |
"###); "#);
} }
#[test] #[test]
fn goto_type_of_expression_with_literal_node() { fn goto_type_of_expression_with_literal_node() {
@ -226,7 +226,7 @@ mod tests {
"#, "#,
); );
assert_snapshot!(test.goto_type_definition(), @r###" assert_snapshot!(test.goto_type_definition(), @r#"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> stdlib/builtins.pyi:901:7 --> stdlib/builtins.pyi:901:7
| |
@ -238,12 +238,12 @@ mod tests {
903 | str(bytes_or_buffer[, encoding[, errors]]) -> str 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str
| |
info: Source info: Source
--> main.py:2:22 --> main.py:2:10
| |
2 | a: str = "test" 2 | a: str = "test"
| ^^^^^^ | ^^^^^^
| |
"###); "#);
} }
#[test] #[test]
@ -256,13 +256,13 @@ mod tests {
assert_snapshot!(test.goto_type_definition(), @r" assert_snapshot!(test.goto_type_definition(), @r"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:2:24 --> main.py:2:12
| |
2 | type Alias[T: int = bool] = list[T] 2 | type Alias[T: int = bool] = list[T]
| ^ | ^
| |
info: Source info: Source
--> main.py:2:46 --> main.py:2:34
| |
2 | type Alias[T: int = bool] = list[T] 2 | type Alias[T: int = bool] = list[T]
| ^ | ^
@ -312,7 +312,7 @@ mod tests {
assert_snapshot!(test.goto_type_definition(), @r#" assert_snapshot!(test.goto_type_definition(), @r#"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:4:13 --> main.py:4:1
| |
2 | from typing_extensions import TypeAliasType 2 | from typing_extensions import TypeAliasType
3 | 3 |
@ -322,7 +322,7 @@ mod tests {
6 | Alias 6 | Alias
| |
info: Source info: Source
--> main.py:6:13 --> main.py:6:1
| |
4 | Alias = TypeAliasType("Alias", tuple[int, int]) 4 | Alias = TypeAliasType("Alias", tuple[int, int])
5 | 5 |
@ -342,7 +342,7 @@ mod tests {
"#, "#,
); );
assert_snapshot!(test.goto_type_definition(), @r###" assert_snapshot!(test.goto_type_definition(), @r#"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> stdlib/builtins.pyi:901:7 --> stdlib/builtins.pyi:901:7
| |
@ -354,14 +354,14 @@ mod tests {
903 | str(bytes_or_buffer[, encoding[, errors]]) -> str 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str
| |
info: Source info: Source
--> main.py:4:18 --> main.py:4:6
| |
2 | def test(a: str): ... 2 | def test(a: str): ...
3 | 3 |
4 | test(a= "123") 4 | test(a= "123")
| ^ | ^
| |
"###); "#);
} }
#[test] #[test]
@ -389,7 +389,7 @@ mod tests {
339 | int(x, base=10) -> integer 339 | int(x, base=10) -> integer
| |
info: Source info: Source
--> main.py:4:18 --> main.py:4:6
| |
2 | def test(a: str): ... 2 | def test(a: str): ...
3 | 3 |
@ -442,7 +442,7 @@ f(**kwargs<CURSOR>)
"#, "#,
); );
assert_snapshot!(test.goto_type_definition(), @r###" assert_snapshot!(test.goto_type_definition(), @r#"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> stdlib/builtins.pyi:901:7 --> stdlib/builtins.pyi:901:7
| |
@ -454,13 +454,13 @@ f(**kwargs<CURSOR>)
903 | str(bytes_or_buffer[, encoding[, errors]]) -> str 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str
| |
info: Source info: Source
--> main.py:3:17 --> main.py:3:5
| |
2 | def foo(a: str): 2 | def foo(a: str):
3 | a 3 | a
| ^ | ^
| |
"###); "#);
} }
#[test] #[test]
@ -478,14 +478,14 @@ f(**kwargs<CURSOR>)
assert_snapshot!(test.goto_type_definition(), @r" assert_snapshot!(test.goto_type_definition(), @r"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:2:19 --> main.py:2:7
| |
2 | class X: 2 | class X:
| ^ | ^
3 | def foo(a, b): ... 3 | def foo(a, b): ...
| |
info: Source info: Source
--> main.py:7:13 --> main.py:7:1
| |
5 | x = X() 5 | x = X()
6 | 6 |
@ -507,7 +507,7 @@ f(**kwargs<CURSOR>)
assert_snapshot!(test.goto_type_definition(), @r" assert_snapshot!(test.goto_type_definition(), @r"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:2:17 --> main.py:2:5
| |
2 | def foo(a, b): ... 2 | def foo(a, b): ...
| ^^^ | ^^^
@ -515,7 +515,7 @@ f(**kwargs<CURSOR>)
4 | foo() 4 | foo()
| |
info: Source info: Source
--> main.py:4:13 --> main.py:4:1
| |
2 | def foo(a, b): ... 2 | def foo(a, b): ...
3 | 3 |
@ -535,7 +535,7 @@ f(**kwargs<CURSOR>)
"#, "#,
); );
assert_snapshot!(test.goto_type_definition(), @r###" assert_snapshot!(test.goto_type_definition(), @r#"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> stdlib/builtins.pyi:901:7 --> stdlib/builtins.pyi:901:7
| |
@ -547,14 +547,14 @@ f(**kwargs<CURSOR>)
903 | str(bytes_or_buffer[, encoding[, errors]]) -> str 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str
| |
info: Source info: Source
--> main.py:4:27 --> main.py:4:15
| |
2 | def foo(a: str | None, b): 2 | def foo(a: str | None, b):
3 | if a is not None: 3 | if a is not None:
4 | print(a) 4 | print(a)
| ^ | ^
| |
"###); "#);
} }
#[test] #[test]
@ -566,7 +566,7 @@ f(**kwargs<CURSOR>)
"#, "#,
); );
assert_snapshot!(test.goto_type_definition(), @r###" assert_snapshot!(test.goto_type_definition(), @r#"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> stdlib/types.pyi:922:11 --> stdlib/types.pyi:922:11
| |
@ -577,7 +577,7 @@ f(**kwargs<CURSOR>)
923 | """The type of the None singleton.""" 923 | """The type of the None singleton."""
| |
info: Source info: Source
--> main.py:3:17 --> main.py:3:5
| |
2 | def foo(a: str | None, b): 2 | def foo(a: str | None, b):
3 | a 3 | a
@ -595,13 +595,13 @@ f(**kwargs<CURSOR>)
903 | str(bytes_or_buffer[, encoding[, errors]]) -> str 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str
| |
info: Source info: Source
--> main.py:3:17 --> main.py:3:5
| |
2 | def foo(a: str | None, b): 2 | def foo(a: str | None, b):
3 | a 3 | a
| ^ | ^
| |
"###); "#);
} }
impl CursorTest { impl CursorTest {

View file

@ -174,7 +174,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:4:9 --> main.py:4:1
| |
2 | a = 10 2 | a = 10
3 | 3 |
@ -233,7 +233,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:11:9 --> main.py:11:1
| |
9 | return 0 9 | return 0
10 | 10 |
@ -291,7 +291,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:2:13 --> main.py:2:5
| |
2 | def my_func(a, b): 2 | def my_func(a, b):
| ^^^^^-^ | ^^^^^-^
@ -357,7 +357,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:24:9 --> main.py:24:1
| |
22 | return 0 22 | return 0
23 | 23 |
@ -422,7 +422,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:2:15 --> main.py:2:7
| |
2 | class MyClass: 2 | class MyClass:
| ^^^^^-^ | ^^^^^-^
@ -489,7 +489,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:24:13 --> main.py:24:5
| |
22 | return 0 22 | return 0
23 | 23 |
@ -563,7 +563,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:25:11 --> main.py:25:3
| |
24 | x = MyClass(0) 24 | x = MyClass(0)
25 | x.my_method(2, 3) 25 | x.my_method(2, 3)
@ -599,7 +599,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:10:13 --> main.py:10:5
| |
9 | foo = Foo() 9 | foo = Foo()
10 | foo.a 10 | foo.a
@ -635,7 +635,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:4:13 --> main.py:4:1
| |
2 | def foo(a, b): ... 2 | def foo(a, b): ...
3 | 3 |
@ -664,7 +664,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:3:17 --> main.py:3:5
| |
2 | def foo(a: int, b: int, c: int): 2 | def foo(a: int, b: int, c: int):
3 | a + b == c 3 | a + b == c
@ -701,7 +701,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:10:18 --> main.py:10:6
| |
8 | return 0 8 | return 0
9 | 9 |
@ -736,7 +736,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:2:22 --> main.py:2:10
| |
2 | def test(ab: int): 2 | def test(ab: int):
| ^- | ^-
@ -778,7 +778,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:16:13 --> main.py:16:1
| |
14 | a = bar 14 | a = bar
15 | 15 |
@ -845,7 +845,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:19:13 --> main.py:19:1
| |
17 | a = "hello" 17 | a = "hello"
18 | 18 |
@ -900,7 +900,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:19:13 --> main.py:19:1
| |
17 | a = "hello" 17 | a = "hello"
18 | 18 |
@ -955,7 +955,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:4:13 --> main.py:4:1
| |
2 | import lib 2 | import lib
3 | 3 |
@ -1005,7 +1005,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:2:20 --> main.py:2:8
| |
2 | import lib 2 | import lib
| ^^- | ^^-
@ -1027,7 +1027,7 @@ mod tests {
); );
// TODO: This should render T@Alias once we create GenericContexts for type alias scopes. // TODO: This should render T@Alias once we create GenericContexts for type alias scopes.
assert_snapshot!(test.hover(), @r###" assert_snapshot!(test.hover(), @r"
typing.TypeVar typing.TypeVar
--------------------------------------------- ---------------------------------------------
```python ```python
@ -1035,14 +1035,14 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:2:46 --> main.py:2:34
| |
2 | type Alias[T: int = bool] = list[T] 2 | type Alias[T: int = bool] = list[T]
| ^- Cursor offset | ^- Cursor offset
| | | |
| source | source
| |
"###); ");
} }
#[test] #[test]
@ -1061,7 +1061,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:2:53 --> main.py:2:41
| |
2 | type Alias[**P = [int, str]] = Callable[P, int] 2 | type Alias[**P = [int, str]] = Callable[P, int]
| ^- Cursor offset | ^- Cursor offset
@ -1087,7 +1087,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:2:43 --> main.py:2:31
| |
2 | type Alias[*Ts = ()] = tuple[*Ts] 2 | type Alias[*Ts = ()] = tuple[*Ts]
| ^^- Cursor offset | ^^- Cursor offset
@ -1113,7 +1113,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:2:13 --> main.py:2:1
| |
2 | value = 1 2 | value = 1
| ^^^^^- Cursor offset | ^^^^^- Cursor offset
@ -1144,7 +1144,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:3:13 --> main.py:3:1
| |
2 | value = 1 2 | value = 1
3 | value += 2 3 | value += 2
@ -1174,7 +1174,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:5:15 --> main.py:5:3
| |
3 | attr: int = 1 3 | attr: int = 1
4 | 4 |
@ -1207,7 +1207,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:5:15 --> main.py:5:3
| |
3 | attr = 1 3 | attr = 1
4 | 4 |
@ -1236,7 +1236,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:3:13 --> main.py:3:5
| |
2 | class Foo: 2 | class Foo:
3 | a: int 3 | a: int
@ -1264,7 +1264,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:3:13 --> main.py:3:5
| |
2 | class Foo: 2 | class Foo:
3 | a: int = 1 3 | a: int = 1
@ -1293,7 +1293,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:4:22 --> main.py:4:14
| |
2 | class Foo: 2 | class Foo:
3 | def __init__(self, a: int): 3 | def __init__(self, a: int):
@ -1329,7 +1329,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:10:27 --> main.py:10:15
| |
8 | ''' 8 | '''
9 | if a is not None: 9 | if a is not None:
@ -1407,7 +1407,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:5:9 --> main.py:5:1
| |
3 | def ab(x: int, y: Callable[[int, int], Any], z: List[int]) -> int: ... 3 | def ab(x: int, y: Callable[[int, int], Any], z: List[int]) -> int: ...
4 | 4 |
@ -1439,7 +1439,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:5:9 --> main.py:5:1
| |
3 | ab: Tuple[Any, int, Callable[[int, int], Any]] = ... 3 | ab: Tuple[Any, int, Callable[[int, int], Any]] = ...
4 | 4 |
@ -1471,7 +1471,7 @@ mod tests {
``` ```
--------------------------------------------- ---------------------------------------------
info[hover]: Hovered content is info[hover]: Hovered content is
--> main.py:5:9 --> main.py:5:1
| |
3 | ab: Callable[[int, int], Any] | None = ... 3 | ab: Callable[[int, int], Any] | None = ...
4 | 4 |

View file

@ -287,6 +287,7 @@ mod tests {
use ruff_db::diagnostic::{Diagnostic, DiagnosticFormat, DisplayDiagnosticConfig}; use ruff_db::diagnostic::{Diagnostic, DiagnosticFormat, DisplayDiagnosticConfig};
use ruff_db::files::{File, system_path_to_file}; use ruff_db::files::{File, system_path_to_file};
use ruff_db::system::{DbWithWritableSystem, SystemPath, SystemPathBuf}; use ruff_db::system::{DbWithWritableSystem, SystemPath, SystemPathBuf};
use ruff_python_trivia::textwrap::dedent;
use ruff_text_size::TextSize; use ruff_text_size::TextSize;
use ty_project::ProjectMetadata; use ty_project::ProjectMetadata;
use ty_python_semantic::{ use ty_python_semantic::{
@ -417,12 +418,12 @@ mod tests {
pub(super) fn source( pub(super) fn source(
&mut self, &mut self,
path: impl Into<SystemPathBuf>, path: impl Into<SystemPathBuf>,
contents: impl Into<String>, contents: impl AsRef<str>,
) -> &mut CursorTestBuilder { ) -> &mut CursorTestBuilder {
const MARKER: &str = "<CURSOR>"; const MARKER: &str = "<CURSOR>";
let path = path.into(); let path = path.into();
let contents = contents.into(); let contents = dedent(contents.as_ref()).into_owned();
let Some(cursor_offset) = contents.find(MARKER) else { let Some(cursor_offset) = contents.find(MARKER) else {
self.sources.push(Source { self.sources.push(Source {
path, path,

View file

@ -1405,34 +1405,34 @@ u = List.__name__ # __name__ should be variable<CURSOR>
"MyClass" @ 89..96: Class [definition] "MyClass" @ 89..96: Class [definition]
"CONSTANT" @ 102..110: Variable [readonly] "CONSTANT" @ 102..110: Variable [readonly]
"42" @ 113..115: Number "42" @ 113..115: Number
"method" @ 129..135: Method [definition] "method" @ 125..131: Method [definition]
"self" @ 136..140: SelfParameter "self" @ 132..136: SelfParameter
"/"hello/"" @ 158..165: String "/"hello/"" @ 154..161: String
"property" @ 176..184: Decorator "property" @ 168..176: Decorator
"prop" @ 193..197: Method [definition] "prop" @ 185..189: Method [definition]
"self" @ 198..202: SelfParameter "self" @ 190..194: SelfParameter
"self" @ 220..224: Variable "self" @ 212..216: Variable
"CONSTANT" @ 225..233: Variable [readonly] "CONSTANT" @ 217..225: Variable [readonly]
"obj" @ 235..238: Variable "obj" @ 227..230: Variable
"MyClass" @ 241..248: Class "MyClass" @ 233..240: Class
"x" @ 286..287: Namespace "x" @ 278..279: Namespace
"os" @ 290..292: Namespace "os" @ 282..284: Namespace
"path" @ 293..297: Namespace "path" @ 285..289: Namespace
"y" @ 347..348: Method "y" @ 339..340: Method
"obj" @ 351..354: Variable "obj" @ 343..346: Variable
"method" @ 355..361: Method "method" @ 347..353: Method
"z" @ 413..414: Variable "z" @ 405..406: Variable
"obj" @ 417..420: Variable "obj" @ 409..412: Variable
"CONSTANT" @ 421..429: Variable [readonly] "CONSTANT" @ 413..421: Variable [readonly]
"w" @ 491..492: Variable "w" @ 483..484: Variable
"obj" @ 495..498: Variable "obj" @ 487..490: Variable
"prop" @ 499..503: Variable "prop" @ 491..495: Variable
"v" @ 542..543: Function "v" @ 534..535: Function
"MyClass" @ 546..553: Class "MyClass" @ 538..545: Class
"method" @ 554..560: Method "method" @ 546..552: Method
"u" @ 604..605: Variable "u" @ 596..597: Variable
"List" @ 608..612: Variable "List" @ 600..604: Variable
"__name__" @ 613..621: Variable "__name__" @ 605..613: Variable
"#); "#);
} }
@ -1456,14 +1456,14 @@ y = obj.unknown_attr # Should fall back to variable<CURSOR>
"MyClass" @ 7..14: Class [definition] "MyClass" @ 7..14: Class [definition]
"some_attr" @ 20..29: Variable "some_attr" @ 20..29: Variable
"/"value/"" @ 32..39: String "/"value/"" @ 32..39: String
"obj" @ 45..48: Variable "obj" @ 41..44: Variable
"MyClass" @ 51..58: Class "MyClass" @ 47..54: Class
"x" @ 121..122: Variable "x" @ 117..118: Variable
"obj" @ 125..128: Variable "obj" @ 121..124: Variable
"some_attr" @ 129..138: Variable "some_attr" @ 125..134: Variable
"y" @ 191..192: Variable "y" @ 187..188: Variable
"obj" @ 195..198: Variable "obj" @ 191..194: Variable
"unknown_attr" @ 199..211: Variable "unknown_attr" @ 195..207: Variable
"#); "#);
} }
@ -1497,20 +1497,20 @@ w = obj.A # Should not have readonly modifier (length == 1)<CURSOR>
"12" @ 72..74: Number "12" @ 72..74: Number
"A" @ 79..80: Variable "A" @ 79..80: Variable
"1" @ 83..84: Number "1" @ 83..84: Number
"obj" @ 90..93: Variable "obj" @ 86..89: Variable
"MyClass" @ 96..103: Class "MyClass" @ 92..99: Class
"x" @ 106..107: Variable "x" @ 102..103: Variable
"obj" @ 110..113: Variable "obj" @ 106..109: Variable
"UPPER_CASE" @ 114..124: Variable [readonly] "UPPER_CASE" @ 110..120: Variable [readonly]
"y" @ 160..161: Variable "y" @ 156..157: Variable
"obj" @ 164..167: Variable "obj" @ 160..163: Variable
"lower_case" @ 168..178: Variable "lower_case" @ 164..174: Variable
"z" @ 220..221: Variable "z" @ 216..217: Variable
"obj" @ 224..227: Variable "obj" @ 220..223: Variable
"MixedCase" @ 228..237: Variable "MixedCase" @ 224..233: Variable
"w" @ 278..279: Variable "w" @ 274..275: Variable
"obj" @ 282..285: Variable "obj" @ 278..281: Variable
"A" @ 286..287: Variable "A" @ 282..283: Variable
"#); "#);
} }
@ -1636,7 +1636,7 @@ def test_function(param: int, other: MyClass) -> Optional[List[str]]:
"List" @ 236..240: Variable "List" @ 236..240: Variable
"str" @ 241..244: Class "str" @ 241..244: Class
"/"hello/"" @ 249..256: String "/"hello/"" @ 249..256: String
"None" @ 361..365: BuiltinConstant "None" @ 357..361: BuiltinConstant
"#); "#);
} }
@ -1800,32 +1800,32 @@ class BoundedContainer[T: int, U = str]:
"value1" @ 594..600: Parameter "value1" @ 594..600: Parameter
"U" @ 622..623: TypeParameter "U" @ 622..623: TypeParameter
"value2" @ 626..632: Parameter "value2" @ 626..632: Parameter
"get_first" @ 646..655: Method [definition] "get_first" @ 642..651: Method [definition]
"self" @ 656..660: SelfParameter "self" @ 652..656: SelfParameter
"T" @ 665..666: TypeParameter "T" @ 661..662: TypeParameter
"self" @ 683..687: Variable "self" @ 679..683: Variable
"value1" @ 688..694: Variable "value1" @ 684..690: Variable
"get_second" @ 708..718: Method [definition] "get_second" @ 700..710: Method [definition]
"self" @ 719..723: SelfParameter "self" @ 711..715: SelfParameter
"U" @ 728..729: TypeParameter "U" @ 720..721: TypeParameter
"self" @ 746..750: Variable "self" @ 738..742: Variable
"value2" @ 751..757: Variable "value2" @ 743..749: Variable
"BoundedContainer" @ 806..822: Class [definition] "BoundedContainer" @ 798..814: Class [definition]
"T" @ 823..824: TypeParameter [definition] "T" @ 815..816: TypeParameter [definition]
"int" @ 826..829: Class "int" @ 818..821: Class
"U" @ 831..832: TypeParameter [definition] "U" @ 823..824: TypeParameter [definition]
"str" @ 835..838: Class "str" @ 827..830: Class
"process" @ 849..856: Method [definition] "process" @ 841..848: Method [definition]
"self" @ 857..861: SelfParameter "self" @ 849..853: SelfParameter
"x" @ 863..864: Parameter "x" @ 855..856: Parameter
"T" @ 866..867: TypeParameter "T" @ 858..859: TypeParameter
"y" @ 869..870: Parameter "y" @ 861..862: Parameter
"U" @ 872..873: TypeParameter "U" @ 864..865: TypeParameter
"tuple" @ 878..883: Class "tuple" @ 870..875: Class
"T" @ 884..885: TypeParameter "T" @ 876..877: TypeParameter
"U" @ 887..888: TypeParameter "U" @ 879..880: TypeParameter
"x" @ 907..908: Parameter "x" @ 899..900: Parameter
"y" @ 910..911: Parameter "y" @ 902..903: Parameter
"#); "#);
} }
@ -2071,24 +2071,24 @@ def outer():
"/"outer_value/"" @ 63..76: String "/"outer_value/"" @ 63..76: String
"z" @ 81..82: Variable "z" @ 81..82: Variable
"/"outer_local/"" @ 85..98: String "/"outer_local/"" @ 85..98: String
"inner" @ 112..117: Function [definition] "inner" @ 108..113: Function [definition]
"x" @ 138..139: Variable "x" @ 134..135: Variable
"z" @ 141..142: Variable "z" @ 137..138: Variable
"y" @ 193..194: Variable "y" @ 189..190: Variable
"x" @ 243..244: Variable "x" @ 239..240: Variable
"/"modified/"" @ 247..257: String "/"modified/"" @ 243..253: String
"y" @ 266..267: Variable "y" @ 262..263: Variable
"/"modified_global/"" @ 270..287: String "/"modified_global/"" @ 266..283: String
"z" @ 296..297: Variable "z" @ 292..293: Variable
"/"modified_local/"" @ 300..316: String "/"modified_local/"" @ 296..312: String
"deeper" @ 338..344: Function [definition] "deeper" @ 326..332: Function [definition]
"x" @ 369..370: Variable "x" @ 357..358: Variable
"y" @ 410..411: Variable "y" @ 398..399: Variable
"x" @ 413..414: Variable "x" @ 401..402: Variable
"x" @ 469..470: Variable "x" @ 457..458: Variable
"y" @ 473..474: Variable "y" @ 461..462: Variable
"deeper" @ 499..505: Function "deeper" @ 479..485: Function
"inner" @ 522..527: Function "inner" @ 498..503: Function
"#); "#);
} }
@ -2115,20 +2115,20 @@ def test():
"test" @ 34..38: Function [definition] "test" @ 34..38: Function [definition]
"x" @ 53..54: Variable "x" @ 53..54: Variable
"y" @ 68..69: Variable "y" @ 68..69: Variable
"a" @ 128..129: Variable "a" @ 124..125: Variable
"b" @ 131..132: Variable "b" @ 127..128: Variable
"c" @ 134..135: Variable "c" @ 130..131: Variable
"d" @ 149..150: Variable "d" @ 145..146: Variable
"e" @ 152..153: Variable "e" @ 148..149: Variable
"f" @ 155..156: Variable "f" @ 151..152: Variable
"x" @ 173..174: Variable "x" @ 165..166: Variable
"y" @ 177..178: Variable "y" @ 169..170: Variable
"a" @ 181..182: Variable "a" @ 173..174: Variable
"b" @ 185..186: Variable "b" @ 177..178: Variable
"c" @ 189..190: Variable "c" @ 181..182: Variable
"d" @ 193..194: Variable "d" @ 185..186: Variable
"e" @ 197..198: Variable "e" @ 189..190: Variable
"f" @ 201..202: Variable "f" @ 193..194: Variable
"#); "#);
} }