diff --git a/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart b/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart index 86e34ece65d1..f9eb1a3720f2 100644 --- a/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart +++ b/pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart @@ -125,6 +125,13 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor { 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); diff --git a/pkg/analysis_server/test/analysis/notification_occurrences_test.dart b/pkg/analysis_server/test/analysis/notification_occurrences_test.dart index 29f8a49a439a..354cf53b1ec6 100644 --- a/pkg/analysis_server/test/analysis/notification_occurrences_test.dart +++ b/pkg/analysis_server/test/analysis/notification_occurrences_test.dart @@ -576,6 +576,23 @@ String f(int char) { '''); } + Future 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 test_prefix_wildcard() async { // Ensure no crash. await assertOccurrences(kind: ElementKind.PREFIX, ''' diff --git a/pkg/analysis_server/test/lsp/document_highlights_test.dart b/pkg/analysis_server/test/lsp/document_highlights_test.dart index d59cf1d13a48..777b3e5ff2e1 100644 --- a/pkg/analysis_server/test/lsp/document_highlights_test.dart +++ b/pkg/analysis_server/test/lsp/document_highlights_test.dart @@ -189,6 +189,21 @@ void f() { /*[2*/key/*2]*/; } } +'''); + + Future 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 test_prefixed() => _testMarkedContent('''