Skip to content

Commit

Permalink
Fix the semantic highlighting for both extension types and mixins
Browse files Browse the repository at this point in the history
Change-Id: Ie64494adbe9d54810b0b156b4884734bdb801309
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336601
Commit-Queue: Brian Wilkerson <[email protected]>
Reviewed-by: Samuel Rawlins <[email protected]>
  • Loading branch information
bwilkerson authored and Commit Queue committed Nov 15, 2023
1 parent c06f69c commit 974b97c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/analysis_server/lib/src/lsp/semantic_tokens/mapping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ final highlightRegionTokenTypes = {
HighlightRegionType.ENUM: SemanticTokenTypes.enum_,
HighlightRegionType.ENUM_CONSTANT: SemanticTokenTypes.enumMember,
HighlightRegionType.EXTENSION: SemanticTokenTypes.class_,
HighlightRegionType.EXTENSION_TYPE: SemanticTokenTypes.class_,
HighlightRegionType.FUNCTION_TYPE_ALIAS: SemanticTokenTypes.type,
HighlightRegionType.IDENTIFIER_DEFAULT: CustomSemanticTokenTypes.source,
HighlightRegionType.IMPORT_PREFIX: SemanticTokenTypes.variable,
Expand All @@ -147,6 +148,7 @@ final highlightRegionTokenTypes = {
HighlightRegionType.LOCAL_FUNCTION_TEAR_OFF: SemanticTokenTypes.function,
HighlightRegionType.LOCAL_VARIABLE_DECLARATION: SemanticTokenTypes.variable,
HighlightRegionType.LOCAL_VARIABLE_REFERENCE: SemanticTokenTypes.variable,
HighlightRegionType.MIXIN: SemanticTokenTypes.class_,
HighlightRegionType.PARAMETER_DECLARATION: SemanticTokenTypes.parameter,
HighlightRegionType.PARAMETER_REFERENCE: SemanticTokenTypes.parameter,
HighlightRegionType.STATIC_FIELD_DECLARATION: SemanticTokenTypes.property,
Expand Down
39 changes: 38 additions & 1 deletion pkg/analysis_server/test/lsp/semantic_tokens_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SemanticTokensTest extends AbstractLspAnalysisServerTest {
@override
AnalysisServerOptions get serverOptions => AnalysisServerOptions()
..enabledExperiments = [
EnableString.patterns,
EnableString.inline_class,
];

Future<void> test_annotation() async {
Expand Down Expand Up @@ -555,6 +555,24 @@ extension A on String {}
await _verifyTokens(content, expected);
}

Future<void> test_extensionType() async {
final content = '''
extension type E(int i) {}
''';

final expected = [
_Token('extension', SemanticTokenTypes.keyword),
_Token('type', SemanticTokenTypes.keyword),
_Token(
'E', SemanticTokenTypes.class_, [SemanticTokenModifiers.declaration]),
_Token('int', SemanticTokenTypes.class_),
_Token('i', SemanticTokenTypes.property,
[SemanticTokenModifiers.declaration])
];

await _verifyTokens(content, expected);
}

Future<void> test_fromPlugin() async {
final pluginAnalyzedFilePath = join(projectFolderPath, 'lib', 'foo.foo');
final pluginAnalyzedFileUri = pathContext.toUri(pluginAnalyzedFilePath);
Expand Down Expand Up @@ -852,6 +870,25 @@ import 'dart:async';
await _verifyTokens(content, expected);
}

Future<void> test_mixin() async {
final content = '''
mixin M on C {}
class C {}
''';

final expected = [
_Token('mixin', SemanticTokenTypes.keyword),
_Token('M', SemanticTokenTypes.class_),
_Token('on', SemanticTokenTypes.keyword),
_Token('C', SemanticTokenTypes.class_),
_Token('class', SemanticTokenTypes.keyword),
_Token(
'C', SemanticTokenTypes.class_, [SemanticTokenModifiers.declaration])
];

await _verifyTokens(content, expected);
}

Future<void> test_multilineRegions() async {
final content = '''
/**
Expand Down

0 comments on commit 974b97c

Please sign in to comment.