Skip to content

Commit 37af167

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Fix missing semantic token modifiers for dynamics
This removes `_addIdentifierRegion_dynamicLocal` and just inlines the region kind into the existing variable/name methods, that way the modifiers are still applied without having to duplicate them in `_addIdentifierRegion_dynamicLocal`. Fixes Dart-Code/Dart-Code#5324 Change-Id: I7f39ec828c916de0fb99d8c71baa78a2f690c94b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392582 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 56fc836 commit 37af167

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

pkg/analysis_server/lib/src/computer/computer_highlights.dart

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ class DartUnitHighlightsComputer {
119119
if (_addIdentifierRegion_field(parent, nameToken, element)) {
120120
return;
121121
}
122-
if (_addIdentifierRegion_dynamicLocal(nameToken, element)) {
123-
return;
124-
}
125122
if (_addIdentifierRegion_function(parent, nameToken, element)) {
126123
return;
127124
}
@@ -229,23 +226,6 @@ class DartUnitHighlightsComputer {
229226
);
230227
}
231228

232-
bool _addIdentifierRegion_dynamicLocal(Token nameToken, Element2? element) {
233-
if (element is LocalVariableElement2) {
234-
var elementType = element.type;
235-
if (elementType is DynamicType) {
236-
var type = HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_REFERENCE;
237-
return _addRegion_token(nameToken, type);
238-
}
239-
} else if (element is FormalParameterElement) {
240-
var elementType = element.type;
241-
if (elementType is DynamicType) {
242-
var type = HighlightRegionType.DYNAMIC_PARAMETER_REFERENCE;
243-
return _addRegion_token(nameToken, type);
244-
}
245-
}
246-
return false;
247-
}
248-
249229
bool _addIdentifierRegion_extension(Token nameToken, Element2? element) {
250230
if (element is! ExtensionElement2) {
251231
return false;
@@ -407,7 +387,9 @@ class DartUnitHighlightsComputer {
407387
return false;
408388
}
409389
// OK
410-
var type = HighlightRegionType.LOCAL_VARIABLE_REFERENCE;
390+
var type = element.type is DynamicType
391+
? HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_REFERENCE
392+
: HighlightRegionType.LOCAL_VARIABLE_REFERENCE;
411393
return _addRegion_token(nameToken, type);
412394
}
413395

@@ -438,7 +420,9 @@ class DartUnitHighlightsComputer {
438420
if (element is! FormalParameterElement) {
439421
return false;
440422
}
441-
var type = HighlightRegionType.PARAMETER_REFERENCE;
423+
var type = element.type is DynamicType
424+
? HighlightRegionType.DYNAMIC_PARAMETER_REFERENCE
425+
: HighlightRegionType.PARAMETER_REFERENCE;
442426
var modifiers =
443427
parent is Label ? {CustomSemanticTokenModifiers.label} : null;
444428
return _addRegion_token(nameToken, type, semanticTokenModifiers: modifiers);

pkg/analysis_server/test/lsp/semantic_tokens_test.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,8 +1337,8 @@ class MyClass {}
13371337

13381338
Future<void> test_namedArguments() async {
13391339
var content = '''
1340-
f({String? a}) {
1341-
f(a: a);
1340+
f({String? a, dynamic b}) {
1341+
f(a: a, b: b);
13421342
}
13431343
''';
13441344

@@ -1348,10 +1348,16 @@ f({String? a}) {
13481348
_Token('String', SemanticTokenTypes.class_),
13491349
_Token('a', SemanticTokenTypes.parameter,
13501350
[SemanticTokenModifiers.declaration]),
1351+
_Token('dynamic', SemanticTokenTypes.type),
1352+
_Token('b', SemanticTokenTypes.parameter,
1353+
[SemanticTokenModifiers.declaration]),
13511354
_Token('f', SemanticTokenTypes.function),
13521355
_Token('a', SemanticTokenTypes.parameter,
13531356
[CustomSemanticTokenModifiers.label]),
13541357
_Token('a', SemanticTokenTypes.parameter),
1358+
_Token('b', SemanticTokenTypes.parameter,
1359+
[CustomSemanticTokenModifiers.label]),
1360+
_Token('b', SemanticTokenTypes.parameter),
13551361
];
13561362

13571363
await _initializeAndVerifyTokens(content, expected);

0 commit comments

Comments
 (0)