Skip to content

Commit a78fb5e

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Fix semantic tokens for method tear-offs in object patterns
Fixes #59976 Change-Id: I75127a59670522ddfc6526d10bfe9844638fdd99 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408001 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 46a739c commit a78fb5e

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,15 +1497,19 @@ class _DartUnitHighlightsComputerVisitor extends RecursiveAstVisitor<void> {
14971497
}
14981498

14991499
@override
1500-
void visitPatternFieldName(PatternFieldName node) {
1501-
var name = node.name;
1500+
void visitPatternField(PatternField node) {
1501+
var name = node.name?.name;
15021502
if (name != null) {
1503-
computer._addRegion_token(
1504-
node.name,
1505-
HighlightRegionType.INSTANCE_GETTER_REFERENCE,
1506-
);
1503+
// Patterns can be method tear-offs as well as getters:
1504+
// https://github.com/dart-lang/sdk/issues/59976#issuecomment-2613558317
1505+
var type = switch (node.element2) {
1506+
MethodElement2() => HighlightRegionType.INSTANCE_METHOD_TEAR_OFF,
1507+
_ => HighlightRegionType.INSTANCE_GETTER_REFERENCE,
1508+
};
1509+
1510+
computer._addRegion_token(name, type);
15071511
}
1508-
super.visitPatternFieldName(node);
1512+
super.visitPatternField(node);
15091513
}
15101514

15111515
@override

pkg/analysis_server/test/lsp/semantic_tokens_test.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,9 @@ void f() {
17261726
var content = r'''
17271727
void f() {
17281728
switch (1) {
1729-
case int(isEven: var isEven) when isEven:
1729+
case int(isEven: var isEven, toString: var toString) when isEven:
1730+
isEven;
1731+
toString;
17301732
}
17311733
}
17321734
''';
@@ -1754,10 +1756,19 @@ void f() {
17541756
_Token('isEven', SemanticTokenTypes.variable, [
17551757
SemanticTokenModifiers.declaration,
17561758
]),
1759+
_Token('toString', SemanticTokenTypes.method, [
1760+
CustomSemanticTokenModifiers.instance,
1761+
]),
1762+
_Token('var', SemanticTokenTypes.keyword),
1763+
_Token('toString', SemanticTokenTypes.variable, [
1764+
SemanticTokenModifiers.declaration,
1765+
]),
17571766
_Token('when', SemanticTokenTypes.keyword, [
17581767
CustomSemanticTokenModifiers.control,
17591768
]),
17601769
_Token('isEven', SemanticTokenTypes.variable),
1770+
_Token('isEven', SemanticTokenTypes.variable),
1771+
_Token('toString', SemanticTokenTypes.variable),
17611772
];
17621773

17631774
await _initializeAndVerifyTokens(content, expected);

0 commit comments

Comments
 (0)