Skip to content

Commit 667730a

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes import prefix highlighting
[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]>
1 parent f2929bf commit 667730a

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
125125
super.visitGenericTypeAlias(node);
126126
}
127127

128+
@override
129+
void visitImportPrefixReference(ImportPrefixReference node) {
130+
_addOccurrence(node.element2!, node.offset);
131+
132+
super.visitImportPrefixReference(node);
133+
}
134+
128135
@override
129136
void visitMethodDeclaration(MethodDeclaration node) {
130137
_addOccurrence(node.declaredFragment!.element, node.name.offset);

pkg/analysis_server/test/analysis/notification_occurrences_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,23 @@ String f(int char) {
576576
''');
577577
}
578578

579+
Future<void> test_prefix() async {
580+
await assertOccurrences(kind: ElementKind.PREFIX, '''
581+
import '' as /*[0*/p/*0]*/;
582+
583+
class A {
584+
void m() {
585+
/*[1*/p/*1]*/.foo();
586+
print(/*[2*/p/*2]*/.a);
587+
}
588+
}
589+
590+
void foo() {}
591+
592+
/*[3*/p/*3]*/.A? a;
593+
''');
594+
}
595+
579596
Future<void> test_prefix_wildcard() async {
580597
// Ensure no crash.
581598
await assertOccurrences(kind: ElementKind.PREFIX, '''

pkg/analysis_server/test/lsp/document_highlights_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ void f() {
189189
/*[2*/key/*2]*/;
190190
}
191191
}
192+
''');
193+
194+
Future<void> test_prefix() => _testMarkedContent('''
195+
import '' as /*[0*/p/*0]*/;
196+
197+
class A {
198+
void m() {
199+
/*[1*/p/*1]*/.foo();
200+
print(/*[2*/p/*2]*/.a);
201+
}
202+
}
203+
204+
void foo() {}
205+
206+
/*[3*/p^/*3]*/.A? a;
192207
''');
193208

194209
Future<void> test_prefixed() => _testMarkedContent('''

0 commit comments

Comments
 (0)