Skip to content

Commit 4564d14

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes Go to import on extension getter/setter
Fixes: #61200 Change-Id: I10c64d4aff472c0f219e2b1af79520fbacbb2ea2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442460 Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 6f69ee3 commit 4564d14

File tree

2 files changed

+53
-18
lines changed

2 files changed

+53
-18
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ class ImportsHandler
7272
if (node is NamedType) {
7373
prefixName = node.importPrefix?.name.lexeme;
7474
} else if (node.thisOrAncestorOfType<PrefixedIdentifier>()
75-
case PrefixedIdentifier(:var prefix) when prefix != node) {
75+
case PrefixedIdentifier(:var prefix)
76+
when prefix != node && prefix.element is PrefixElement) {
7677
prefixName = prefix.name;
7778
} else if (node is SimpleIdentifier) {
7879
if (node.parent case MethodInvocation(
7980
target: SimpleIdentifier target?,
80-
)) {
81-
prefixName = target.toString();
81+
) when target.element is PrefixElement) {
82+
prefixName = target.name;
8283
}
8384
}
8485

pkg/analysis_server/test/lsp/import_test.dart

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,55 @@ void foo() {
5454
);
5555
}
5656

57+
Future<void> test_extension_getter() async {
58+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
59+
extension E on int {
60+
int get bar => 42;
61+
}
62+
''');
63+
await _verifyGoToImports(
64+
TestCode.parse('''
65+
[!import 'other.dart';!]
66+
67+
void f(int i) {
68+
i.ba^r;
69+
}
70+
'''),
71+
);
72+
}
73+
74+
Future<void> test_extension_nestedInvocations() async {
75+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
76+
extension E on int {
77+
void bar() {}
78+
}
79+
''');
80+
await _verifyGoToImports(
81+
TestCode.parse('''
82+
[!import 'other.dart';!]
83+
84+
var a = 1.abs().ba^r();
85+
'''),
86+
);
87+
}
88+
89+
Future<void> test_extension_setter() async {
90+
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
91+
extension E on int {
92+
set foo(int _) {}
93+
}
94+
''');
95+
await _verifyGoToImports(
96+
TestCode.parse('''
97+
[!import 'other.dart';!]
98+
99+
void f(int i) {
100+
i.fo^o = 0;
101+
}
102+
'''),
103+
);
104+
}
105+
57106
Future<void> test_function() async {
58107
await _verifyGoToImports(
59108
TestCode.parse('''
@@ -413,21 +462,6 @@ var a = A().foo().ba^r();
413462
);
414463
}
415464

416-
Future<void> test_nestedInvocations_extension() async {
417-
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
418-
extension E on int {
419-
void bar() {}
420-
}
421-
''');
422-
await _verifyGoToImports(
423-
TestCode.parse('''
424-
[!import 'other.dart';!]
425-
426-
var a = 1.abs().ba^r();
427-
'''),
428-
);
429-
}
430-
431465
Future<void> test_staticDeclarations() async {
432466
newFile(join(projectFolderPath, 'lib', 'other.dart'), '''
433467
class A {

0 commit comments

Comments
 (0)