Skip to content

Commit

Permalink
[DAS] Fixes import prefix highlighting
Browse files Browse the repository at this point in the history
[email protected]

Fixes: #59942
Change-Id: Id5c971f040dc2dcdddde6e36055e9045eb4b2aef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404925
Auto-Submit: Felipe Morschel <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Phil Quitslund <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
  • Loading branch information
FMorschel authored and Commit Queue committed Jan 20, 2025
1 parent f2929bf commit 667730a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
super.visitGenericTypeAlias(node);
}

@override
void visitImportPrefixReference(ImportPrefixReference node) {
_addOccurrence(node.element2!, node.offset);

super.visitImportPrefixReference(node);
}

@override
void visitMethodDeclaration(MethodDeclaration node) {
_addOccurrence(node.declaredFragment!.element, node.name.offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,23 @@ String f(int char) {
''');
}

Future<void> test_prefix() async {
await assertOccurrences(kind: ElementKind.PREFIX, '''
import '' as /*[0*/p/*0]*/;
class A {
void m() {
/*[1*/p/*1]*/.foo();
print(/*[2*/p/*2]*/.a);
}
}
void foo() {}
/*[3*/p/*3]*/.A? a;
''');
}

Future<void> test_prefix_wildcard() async {
// Ensure no crash.
await assertOccurrences(kind: ElementKind.PREFIX, '''
Expand Down
15 changes: 15 additions & 0 deletions pkg/analysis_server/test/lsp/document_highlights_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ void f() {
/*[2*/key/*2]*/;
}
}
''');

Future<void> test_prefix() => _testMarkedContent('''
import '' as /*[0*/p/*0]*/;
class A {
void m() {
/*[1*/p/*1]*/.foo();
print(/*[2*/p/*2]*/.a);
}
}
void foo() {}
/*[3*/p^/*3]*/.A? a;
''');

Future<void> test_prefixed() => _testMarkedContent('''
Expand Down

0 comments on commit 667730a

Please sign in to comment.