[DAS] Fixes for static declarations on Go to Imports command

R=brianwilkerson@google.com

Fixes https://github.com/dart-lang/sdk/issues/59823

Change-Id: I63f56e770bc53f7fc0f03e1c31a5c2b6b2fb7d54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402540
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_imports.dart b/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_imports.dart
index 02c498a..ac60576 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_imports.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_imports.dart
@@ -69,17 +69,17 @@
         return success(null);
       }
 
-      String? prefix;
+      String? prefixName;
       if (node is NamedType) {
-        prefix = node.importPrefix?.name.lexeme;
+        prefixName = node.importPrefix?.name.lexeme;
       } else if (node.thisOrAncestorOfType<PrefixedIdentifier>()
-          case PrefixedIdentifier identifier) {
-        prefix = identifier.prefix.name;
+          case PrefixedIdentifier(:var prefix) when prefix != node) {
+        prefixName = prefix.name;
       } else if (node is SimpleIdentifier) {
         if (node.parent case MethodInvocation(
           target: SimpleIdentifier target?,
         )) {
-          prefix = target.toString();
+          prefixName = target.toString();
         }
       }
 
@@ -88,7 +88,7 @@
         element = enclosingElement;
       }
 
-      var locations = _getImportLocations(library, unit, element, prefix);
+      var locations = _getImportLocations(library, unit, element, prefixName);
 
       return success(nullIfEmpty(locations));
     });
diff --git a/pkg/analysis_server/test/lsp/import_test.dart b/pkg/analysis_server/test/lsp/import_test.dart
index 3ccc01a..02b0905 100644
--- a/pkg/analysis_server/test/lsp/import_test.dart
+++ b/pkg/analysis_server/test/lsp/import_test.dart
@@ -79,7 +79,7 @@
   }
 
   Future<void> test_import_double() async {
-    newFile('/home/my_project/lib/other.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
 export 'dart:math';
 ''');
     await _verifyGoToImports(
@@ -93,10 +93,10 @@
   }
 
   Future<void> test_import_double_ambiguous() async {
-    newFile('/home/my_project/lib/a1.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
 class A {}
 ''');
-    newFile('/home/my_project/lib/a2.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
 class A {}
 ''');
     await _verifyGoToImports(
@@ -111,10 +111,10 @@
   }
 
   Future<void> test_import_double_hide() async {
-    newFile('/home/my_project/lib/a1.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
 class A {}
 ''');
-    newFile('/home/my_project/lib/a2.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
 class A {}
 ''');
     await _verifyGoToImports(
@@ -128,7 +128,7 @@
   }
 
   Future<void> test_import_double_same_different_alias() async {
-    newFile('/home/my_project/lib/other.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
 export 'dart:math';
 ''');
     await _verifyGoToImports(
@@ -142,7 +142,7 @@
   }
 
   Future<void> test_import_double_same_different_alias_prefix() async {
-    newFile('/home/my_project/lib/other.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
 export 'dart:math';
 ''');
     await _verifyGoToImports(
@@ -156,12 +156,12 @@
   }
 
   Future<void> test_import_double_show() async {
-    newFile('/home/my_project/lib/a1.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
 class A {}
 
 class B {}
 ''');
-    newFile('/home/my_project/lib/a2.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
 class A {}
 ''');
     await _verifyGoToImports(
@@ -175,10 +175,10 @@
   }
 
   Future<void> test_import_double_unambiguous_aliased() async {
-    newFile('/home/my_project/lib/a1.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
 class A {}
 ''');
-    newFile('/home/my_project/lib/a2.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
 class A {}
 ''');
     await _verifyGoToImports(
@@ -371,7 +371,7 @@
   }
 
   Future<void> test_import_single_exported() async {
-    newFile('/home/my_project/lib/other.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
 export 'dart:math';
 ''');
     await _verifyGoToImports(
@@ -397,7 +397,7 @@
   }
 
   Future<void> test_nestedInvocations() async {
-    newFile('/home/my_project/lib/other.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
 class A {
   const A();
   A foo() => A();
@@ -414,7 +414,7 @@
   }
 
   Future<void> test_nestedInvocations_extension() async {
-    newFile('/home/my_project/lib/other.dart', '''
+    newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
 extension E on int {
   void bar() {}
 }
@@ -428,6 +428,36 @@
     );
   }
 
+  Future<void> test_staticDeclarations() async {
+    newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
+class A {
+  static const a = 1;
+}
+''');
+    await _verifyGoToImports(
+      TestCode.parse('''
+[!import 'other.dart';!]
+
+var a = A^.a;
+'''),
+    );
+  }
+
+  Future<void> test_staticDeclarations_prefixed() async {
+    newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
+class A {
+  static const a = 1;
+}
+''');
+    await _verifyGoToImports(
+      TestCode.parse('''
+[!import 'other.dart' as o;!]
+
+var a = o.A^.a;
+'''),
+    );
+  }
+
   Future<void> _verifyGoToImports(
     TestCode code, {
     Uri? fileUri,