File tree 2 files changed +42
-1
lines changed
2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,8 @@ class ReferencesHandler
64
64
ReferenceParams params,
65
65
ResolvedUnitResult unit,
66
66
OperationPerformanceImpl performance) async {
67
- final node = NodeLocator (offset).searchWithin (result.unit);
67
+ var node = NodeLocator (offset).searchWithin (result.unit);
68
+ node = _getReferenceTargetNode (node);
68
69
var element = server.getElementOfNode (node);
69
70
if (element == null ) {
70
71
return success (null );
@@ -104,4 +105,24 @@ class ReferencesHandler
104
105
105
106
return success (referenceResults);
106
107
}
108
+
109
+ /// Gets the nearest node that should be used for finding references.
110
+ ///
111
+ /// This is usually the same node but allows some adjustments such as
112
+ /// considering the offset between a type name and type arguments as part
113
+ /// of the type.
114
+ AstNode ? _getReferenceTargetNode (AstNode ? node) {
115
+ // Consider the angle brackets for type arguments part of the leading type,
116
+ // otherwise we don't navigate in the common situation of having the type
117
+ // name selected, where VS Code provides the end of the selection as the
118
+ // position to search.
119
+ //
120
+ // In `A^<String>` node will be `TypeParameterList` and we will not find any
121
+ // references.
122
+ if (node is TypeParameterList ) {
123
+ node = node.parent;
124
+ }
125
+
126
+ return node;
127
+ }
107
128
}
Original file line number Diff line number Diff line change @@ -178,6 +178,26 @@ f^oo() {
178
178
await _checkRanges (content, includeDeclarations: false );
179
179
}
180
180
181
+ Future <void > test_type () async {
182
+ final content = '''
183
+ class A^aa<T> {}
184
+
185
+ [!Aaa!]<String>? a;
186
+ ''' ;
187
+
188
+ await _checkRanges (content);
189
+ }
190
+
191
+ Future <void > test_type_generic_end () async {
192
+ final content = '''
193
+ class Aaa^<T> {}
194
+
195
+ [!Aaa!]<String>? a;
196
+ ''' ;
197
+
198
+ await _checkRanges (content);
199
+ }
200
+
181
201
Future <void > test_unopenFile () async {
182
202
final code = TestCode .parse ('''
183
203
f^oo() {
You can’t perform that action at this time.
0 commit comments