@@ -54,6 +54,110 @@ class SemanticTokensTest extends AbstractLspAnalysisServerTest {
5454 return results;
5555 }
5656
57+ Future <void > test_annotation () async {
58+ final content = '''
59+ import 'other_file.dart' as other;
60+
61+ @a
62+ @A()
63+ @A.n()
64+ @B(A())
65+ @other.C()
66+ @other.C.n()
67+ void foo() {}
68+
69+ class A {
70+ const A();
71+ const A.n();
72+ }
73+
74+ const a = A();
75+
76+ class B {
77+ final A a;
78+ const B(this.a);
79+ }
80+ ''' ;
81+
82+ final otherContent = '''
83+ class C {
84+ const C();
85+ const C.n();
86+ }
87+ ''' ;
88+
89+ final expectedStart = [
90+ _Token ('import' , SemanticTokenTypes .keyword),
91+ _Token ("'other_file.dart'" , SemanticTokenTypes .string),
92+ _Token ('as' , SemanticTokenTypes .keyword),
93+ _Token ('other' , SemanticTokenTypes .variable),
94+ _Token ('@' , CustomSemanticTokenTypes .annotation),
95+ _Token ('a' , SemanticTokenTypes .property,
96+ [CustomSemanticTokenModifiers .annotation]),
97+ _Token ('@' , CustomSemanticTokenTypes .annotation),
98+ _Token ('A' , SemanticTokenTypes .class_,
99+ [CustomSemanticTokenModifiers .annotation]),
100+ _Token ('(' , CustomSemanticTokenTypes .annotation),
101+ _Token (')' , CustomSemanticTokenTypes .annotation),
102+ _Token ('@' , CustomSemanticTokenTypes .annotation),
103+ _Token ('A' , SemanticTokenTypes .class_,
104+ [CustomSemanticTokenModifiers .annotation]),
105+ _Token ('.' , CustomSemanticTokenTypes .annotation),
106+ _Token ('n' , SemanticTokenTypes .method, [
107+ CustomSemanticTokenModifiers .constructor,
108+ CustomSemanticTokenModifiers .annotation
109+ ]),
110+ _Token ('(' , CustomSemanticTokenTypes .annotation),
111+ _Token (')' , CustomSemanticTokenTypes .annotation),
112+ _Token ('@' , CustomSemanticTokenTypes .annotation),
113+ _Token ('B' , SemanticTokenTypes .class_,
114+ [CustomSemanticTokenModifiers .annotation]),
115+ _Token ('(' , CustomSemanticTokenTypes .annotation),
116+ _Token ('A' , SemanticTokenTypes .class_,
117+ [CustomSemanticTokenModifiers .constructor]),
118+ _Token (')' , CustomSemanticTokenTypes .annotation),
119+ _Token ('@' , CustomSemanticTokenTypes .annotation),
120+ _Token ('other' , SemanticTokenTypes .variable),
121+ _Token ('.' , CustomSemanticTokenTypes .annotation),
122+ _Token ('C' , SemanticTokenTypes .class_,
123+ [CustomSemanticTokenModifiers .annotation]),
124+ _Token ('(' , CustomSemanticTokenTypes .annotation),
125+ _Token (')' , CustomSemanticTokenTypes .annotation),
126+ _Token ('@' , CustomSemanticTokenTypes .annotation),
127+ _Token ('other' , SemanticTokenTypes .variable),
128+ _Token ('.' , CustomSemanticTokenTypes .annotation),
129+ _Token ('C' , SemanticTokenTypes .class_,
130+ [CustomSemanticTokenModifiers .annotation]),
131+ _Token ('.' , CustomSemanticTokenTypes .annotation),
132+ _Token ('n' , SemanticTokenTypes .method, [
133+ CustomSemanticTokenModifiers .constructor,
134+ CustomSemanticTokenModifiers .annotation
135+ ]),
136+ _Token ('(' , CustomSemanticTokenTypes .annotation),
137+ _Token (')' , CustomSemanticTokenTypes .annotation),
138+ _Token ('void' , SemanticTokenTypes .keyword,
139+ [CustomSemanticTokenModifiers .void_]),
140+ _Token ('foo' , SemanticTokenTypes .function,
141+ [SemanticTokenModifiers .declaration, SemanticTokenModifiers .static ])
142+ ];
143+
144+ final otherFilePath = join (projectFolderPath, 'lib' , 'other_file.dart' );
145+ final otherFileUri = Uri .file (otherFilePath);
146+
147+ await initialize ();
148+ await openFile (mainFileUri, withoutMarkers (content));
149+ await openFile (otherFileUri, withoutMarkers (otherContent));
150+
151+ final tokens = await getSemanticTokens (mainFileUri);
152+ final decoded = decodeSemanticTokens (content, tokens);
153+ expect (
154+ // Only check the first expectedStart.length items since the test code
155+ // is mostly unrelated to the annotations.
156+ decoded.sublist (0 , expectedStart.length),
157+ equals (expectedStart),
158+ );
159+ }
160+
57161 Future <void > test_class () async {
58162 final content = '''
59163 /// class docs
@@ -305,7 +409,8 @@ class SemanticTokensTest extends AbstractLspAnalysisServerTest {
305409 _Token ('/// method docs' , SemanticTokenTypes .comment,
306410 [SemanticTokenModifiers .documentation]),
307411 _Token ('@' , CustomSemanticTokenTypes .annotation),
308- _Token ('override' , SemanticTokenTypes .property),
412+ _Token ('override' , SemanticTokenTypes .property,
413+ [CustomSemanticTokenModifiers .annotation]),
309414 _Token ('void' , SemanticTokenTypes .keyword,
310415 [CustomSemanticTokenModifiers .void_]),
311416 _Token ('myMethod' , SemanticTokenTypes .method,
0 commit comments