Skip to content

Commit 26a2bf2

Browse files
FMorschelCommit Queue
authored and
Commit Queue
committed
[DAS] Fixes for static declarations on Go to Imports command
[email protected] Fixes #59823 Change-Id: I63f56e770bc53f7fc0f03e1c31a5c2b6b2fb7d54 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402540 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Auto-Submit: Felipe Morschel <[email protected]>
1 parent c033dd2 commit 26a2bf2

File tree

2 files changed

+50
-20
lines changed

2 files changed

+50
-20
lines changed

pkg/analysis_server/lib/src/lsp/handlers/custom/handler_imports.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ class ImportsHandler
6969
return success(null);
7070
}
7171

72-
String? prefix;
72+
String? prefixName;
7373
if (node is NamedType) {
74-
prefix = node.importPrefix?.name.lexeme;
74+
prefixName = node.importPrefix?.name.lexeme;
7575
} else if (node.thisOrAncestorOfType<PrefixedIdentifier>()
76-
case PrefixedIdentifier identifier) {
77-
prefix = identifier.prefix.name;
76+
case PrefixedIdentifier(:var prefix) when prefix != node) {
77+
prefixName = prefix.name;
7878
} else if (node is SimpleIdentifier) {
7979
if (node.parent case MethodInvocation(
8080
target: SimpleIdentifier target?,
8181
)) {
82-
prefix = target.toString();
82+
prefixName = target.toString();
8383
}
8484
}
8585

@@ -88,7 +88,7 @@ class ImportsHandler
8888
element = enclosingElement;
8989
}
9090

91-
var locations = _getImportLocations(library, unit, element, prefix);
91+
var locations = _getImportLocations(library, unit, element, prefixName);
9292

9393
return success(nullIfEmpty(locations));
9494
});

pkg/analysis_server/test/lsp/import_test.dart

+44-14
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void foo() {
7979
}
8080

8181
Future<void> test_import_double() async {
82-
newFile('/home/my_project/lib/other.dart', '''
82+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
8383
export 'dart:math';
8484
''');
8585
await _verifyGoToImports(
@@ -93,10 +93,10 @@ Rando^m? r;
9393
}
9494

9595
Future<void> test_import_double_ambiguous() async {
96-
newFile('/home/my_project/lib/a1.dart', '''
96+
newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
9797
class A {}
9898
''');
99-
newFile('/home/my_project/lib/a2.dart', '''
99+
newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
100100
class A {}
101101
''');
102102
await _verifyGoToImports(
@@ -111,10 +111,10 @@ class A {}
111111
}
112112

113113
Future<void> test_import_double_hide() async {
114-
newFile('/home/my_project/lib/a1.dart', '''
114+
newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
115115
class A {}
116116
''');
117-
newFile('/home/my_project/lib/a2.dart', '''
117+
newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
118118
class A {}
119119
''');
120120
await _verifyGoToImports(
@@ -128,7 +128,7 @@ import 'a1.dart' hide A;
128128
}
129129

130130
Future<void> test_import_double_same_different_alias() async {
131-
newFile('/home/my_project/lib/other.dart', '''
131+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
132132
export 'dart:math';
133133
''');
134134
await _verifyGoToImports(
@@ -142,7 +142,7 @@ other.Rando^m? r;
142142
}
143143

144144
Future<void> test_import_double_same_different_alias_prefix() async {
145-
newFile('/home/my_project/lib/other.dart', '''
145+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
146146
export 'dart:math';
147147
''');
148148
await _verifyGoToImports(
@@ -156,12 +156,12 @@ other.Ran^dom? r;
156156
}
157157

158158
Future<void> test_import_double_show() async {
159-
newFile('/home/my_project/lib/a1.dart', '''
159+
newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
160160
class A {}
161161
162162
class B {}
163163
''');
164-
newFile('/home/my_project/lib/a2.dart', '''
164+
newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
165165
class A {}
166166
''');
167167
await _verifyGoToImports(
@@ -175,10 +175,10 @@ import 'a1.dart' show B;
175175
}
176176

177177
Future<void> test_import_double_unambiguous_aliased() async {
178-
newFile('/home/my_project/lib/a1.dart', '''
178+
newFile(join(projectFolderPath, 'lib', 'a1.dart'), '''
179179
class A {}
180180
''');
181-
newFile('/home/my_project/lib/a2.dart', '''
181+
newFile(join(projectFolderPath, 'lib', 'a2.dart'), '''
182182
class A {}
183183
''');
184184
await _verifyGoToImports(
@@ -371,7 +371,7 @@ math.Rando^m? r;
371371
}
372372

373373
Future<void> test_import_single_exported() async {
374-
newFile('/home/my_project/lib/other.dart', '''
374+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
375375
export 'dart:math';
376376
''');
377377
await _verifyGoToImports(
@@ -397,7 +397,7 @@ class LocalClass {}
397397
}
398398

399399
Future<void> test_nestedInvocations() async {
400-
newFile('/home/my_project/lib/other.dart', '''
400+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
401401
class A {
402402
const A();
403403
A foo() => A();
@@ -414,7 +414,7 @@ var a = A().foo().ba^r();
414414
}
415415

416416
Future<void> test_nestedInvocations_extension() async {
417-
newFile('/home/my_project/lib/other.dart', '''
417+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
418418
extension E on int {
419419
void bar() {}
420420
}
@@ -428,6 +428,36 @@ var a = 1.abs().ba^r();
428428
);
429429
}
430430

431+
Future<void> test_staticDeclarations() async {
432+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
433+
class A {
434+
static const a = 1;
435+
}
436+
''');
437+
await _verifyGoToImports(
438+
TestCode.parse('''
439+
[!import 'other.dart';!]
440+
441+
var a = A^.a;
442+
'''),
443+
);
444+
}
445+
446+
Future<void> test_staticDeclarations_prefixed() async {
447+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
448+
class A {
449+
static const a = 1;
450+
}
451+
''');
452+
await _verifyGoToImports(
453+
TestCode.parse('''
454+
[!import 'other.dart' as o;!]
455+
456+
var a = o.A^.a;
457+
'''),
458+
);
459+
}
460+
431461
Future<void> _verifyGoToImports(
432462
TestCode code, {
433463
Uri? fileUri,

0 commit comments

Comments
 (0)