[analysis_server] Add missing semantic token for super expressions
Noticed while testing highlighting for augment/augmented - apparently we weren't producing any tokens for super expressions (but did for super constructor and super formal params). It wasn't noticable in VS Code because a completely uncoloured token uses the TextMate grammar token.
Change-Id: I32c782db0c7771cad52ed49912c215313a64c055
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355422
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/computer/computer_highlights.dart b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
index c444ed8..b78a467 100644
--- a/pkg/analysis_server/lib/src/computer/computer_highlights.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
@@ -1466,6 +1466,12 @@
}
@override
+ void visitSuperExpression(SuperExpression node) {
+ computer._addRegion_token(node.superKeyword, HighlightRegionType.KEYWORD);
+ super.visitSuperExpression(node);
+ }
+
+ @override
void visitSuperFormalParameter(SuperFormalParameter node) {
computer._addRegion_token(
node.requiredKeyword,
diff --git a/pkg/analysis_server/test/lsp/semantic_tokens_test.dart b/pkg/analysis_server/test/lsp/semantic_tokens_test.dart
index 51a4f3c..f0ae59e 100644
--- a/pkg/analysis_server/test/lsp/semantic_tokens_test.dart
+++ b/pkg/analysis_server/test/lsp/semantic_tokens_test.dart
@@ -459,6 +459,105 @@
await _verifyTokens(content, expected);
}
+ Future<void> test_class_super() async {
+ final content = '''
+class A {
+ A(int i) {}
+ void f() {}
+}
+
+class B extends A {
+[!
+ B.b() : super(1);
+ B(super.i);
+ void f() {
+ super.f();
+ }
+!]
+}
+''';
+
+ final expected = [
+ _Token('B', SemanticTokenTypes.class_, [
+ CustomSemanticTokenModifiers.constructor,
+ SemanticTokenModifiers.declaration,
+ ]),
+ _Token('b', SemanticTokenTypes.method, [
+ CustomSemanticTokenModifiers.constructor,
+ SemanticTokenModifiers.declaration,
+ ]),
+ _Token('super', SemanticTokenTypes.keyword),
+ _Token('1', SemanticTokenTypes.number),
+ _Token('B', SemanticTokenTypes.class_, [
+ CustomSemanticTokenModifiers.constructor,
+ SemanticTokenModifiers.declaration,
+ ]),
+ _Token('super', SemanticTokenTypes.keyword),
+ _Token('i', SemanticTokenTypes.parameter,
+ [SemanticTokenModifiers.declaration]),
+ _Token('void', SemanticTokenTypes.keyword,
+ [CustomSemanticTokenModifiers.void_]),
+ _Token('f', SemanticTokenTypes.method, [
+ SemanticTokenModifiers.declaration,
+ CustomSemanticTokenModifiers.instance,
+ ]),
+ _Token('super', SemanticTokenTypes.keyword),
+ _Token('f', SemanticTokenTypes.method, [
+ CustomSemanticTokenModifiers.instance,
+ ])
+ ];
+
+ await _verifyTokensInRange(content, expected);
+ }
+
+ Future<void> test_class_this() async {
+ final content = '''
+class A {
+ int a;
+ [!
+ A(this.a);
+ A.b() : this(1);
+ void f() {
+ this.f();
+ }
+ !]
+}
+''';
+
+ final expected = [
+ _Token('A', SemanticTokenTypes.class_, [
+ CustomSemanticTokenModifiers.constructor,
+ SemanticTokenModifiers.declaration,
+ ]),
+ _Token('this', SemanticTokenTypes.keyword),
+ _Token('a', SemanticTokenTypes.property, [
+ CustomSemanticTokenModifiers.instance,
+ ]),
+ _Token('A', SemanticTokenTypes.class_, [
+ CustomSemanticTokenModifiers.constructor,
+ SemanticTokenModifiers.declaration,
+ ]),
+ _Token('b', SemanticTokenTypes.method, [
+ CustomSemanticTokenModifiers.constructor,
+ SemanticTokenModifiers.declaration,
+ ]),
+ _Token('1', SemanticTokenTypes.number),
+ _Token('void', SemanticTokenTypes.keyword, [
+ CustomSemanticTokenModifiers.void_,
+ ]),
+ _Token('f', SemanticTokenTypes.method, [
+ SemanticTokenModifiers.declaration,
+ CustomSemanticTokenModifiers.instance,
+ ]),
+ _Token('this', SemanticTokenTypes.keyword),
+ _Token('f', SemanticTokenTypes.method, [
+ CustomSemanticTokenModifiers.instance,
+ ])
+ ];
+
+ await _verifyTokensInRange(content, expected);
+ }
+
Future<void> test_dartdoc() async {
final content = '''
/// before [aaa] after