Skip to content
Merged
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
98 changes: 55 additions & 43 deletions crates/ty_ide/src/semantic_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,6 @@ f: """'list["int | str"]' | 'None'"""
import os
import sys
from collections import defaultdict
from typing import List

class MyClass:
CONSTANT = 42
Expand All @@ -1906,7 +1905,7 @@ y = obj.method # method should be method (bound method)
z = obj.CONSTANT # CONSTANT should be variable with readonly modifier
w = obj.prop # prop should be property
v = MyClass.method # method should be method (function)
u = List.__name__ # __name__ should be variable
u = MyClass.__name__ # __name__ should resolve on the class object
t = MyClass.prop # prop should be property on the class itself
",
);
Expand All @@ -1918,41 +1917,40 @@ t = MyClass.prop # prop should be property on the class itself
"sys" @ 18..21: Namespace
"collections" @ 27..38: Namespace
"defaultdict" @ 46..57: Class
"typing" @ 63..69: Namespace
"List" @ 77..81: Variable
"MyClass" @ 89..96: Class [definition]
"CONSTANT" @ 102..110: Variable [definition, readonly]
"42" @ 113..115: Number
"method" @ 125..131: Method [definition]
"self" @ 132..136: SelfParameter [definition]
"\"hello\"" @ 154..161: String
"property" @ 168..176: Decorator
"prop" @ 185..189: Method [definition]
"self" @ 190..194: SelfParameter [definition]
"self" @ 212..216: SelfParameter
"CONSTANT" @ 217..225: Variable [readonly]
"obj" @ 227..230: Variable [definition]
"MyClass" @ 233..240: Class
"x" @ 278..279: Variable [definition]
"os" @ 282..284: Namespace
"path" @ 285..289: Namespace
"y" @ 339..340: Variable [definition]
"obj" @ 343..346: Variable
"method" @ 347..353: Method
"z" @ 405..406: Variable [definition]
"obj" @ 409..412: Variable
"CONSTANT" @ 413..421: Variable [readonly]
"w" @ 483..484: Variable [definition]
"obj" @ 487..490: Variable
"prop" @ 491..495: Property [readonly]
"v" @ 534..535: Variable [definition]
"MyClass" @ 538..545: Class
"method" @ 546..552: Method
"u" @ 596..597: Variable [definition]
"List" @ 600..604: Variable
"t" @ 651..652: Variable [definition]
"MyClass" @ 655..662: Class
"prop" @ 663..667: Property [readonly]
"MyClass" @ 65..72: Class [definition]
Copy link
Copy Markdown
Contributor Author

@denyszhak denyszhak Apr 21, 2026

Choose a reason for hiding this comment

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

@MichaReiser sorry it's shifted the only different is in u = MyClass.__name__ but it still resolves into a variable and I think for it to be a property it requires implementation change

"CONSTANT" @ 78..86: Variable [definition, readonly]
"42" @ 89..91: Number
"method" @ 101..107: Method [definition]
"self" @ 108..112: SelfParameter [definition]
"\"hello\"" @ 130..137: String
"property" @ 144..152: Decorator
"prop" @ 161..165: Method [definition]
"self" @ 166..170: SelfParameter [definition]
"self" @ 188..192: SelfParameter
"CONSTANT" @ 193..201: Variable [readonly]
"obj" @ 203..206: Variable [definition]
"MyClass" @ 209..216: Class
"x" @ 254..255: Variable [definition]
"os" @ 258..260: Namespace
"path" @ 261..265: Namespace
"y" @ 315..316: Variable [definition]
"obj" @ 319..322: Variable
"method" @ 323..329: Method
"z" @ 381..382: Variable [definition]
"obj" @ 385..388: Variable
"CONSTANT" @ 389..397: Variable [readonly]
"w" @ 459..460: Variable [definition]
"obj" @ 463..466: Variable
"prop" @ 467..471: Property [readonly]
"v" @ 510..511: Variable [definition]
"MyClass" @ 514..521: Class
"method" @ 522..528: Method
"u" @ 572..573: Variable [definition]
"MyClass" @ 576..583: Class
"__name__" @ 584..592: Variable
"t" @ 643..644: Variable [definition]
"MyClass" @ 647..654: Class
"prop" @ 655..659: Property [readonly]
"#);
}

Expand Down Expand Up @@ -3602,6 +3600,12 @@ def generic_function[T](value: T) -> T:
fn decorator_classification() {
let test = SemanticTokenTest::new(
r#"
class App:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@MichaReiser
To make sure this test covers complex decorator path as per your comment here #24718 (comment)

def route(self, path):
pass

app = App()

@staticmethod
@property
@app.route("/path")
Expand All @@ -3617,12 +3621,20 @@ class MyClass:
let tokens = test.highlight_file();

assert_snapshot!(test.to_snapshot(&tokens), @r#"
"staticmethod" @ 2..14: Decorator
"property" @ 16..24: Decorator
"\"/path\"" @ 36..43: String
"my_function" @ 49..60: Function [definition]
"dataclass" @ 75..84: Decorator
"MyClass" @ 91..98: Class [definition]
"App" @ 7..10: Class [definition]
"route" @ 20..25: Method [definition]
"self" @ 26..30: SelfParameter [definition]
"path" @ 32..36: Parameter [definition]
"app" @ 53..56: Variable [definition]
"App" @ 59..62: Class
"staticmethod" @ 67..79: Decorator
"property" @ 81..89: Decorator
"app" @ 91..94: Variable
"route" @ 95..100: Method
"\"/path\"" @ 101..108: String
"my_function" @ 114..125: Function [definition]
"dataclass" @ 140..149: Decorator
"MyClass" @ 156..163: Class [definition]
"#);
}

Expand Down
Loading