Skip to content

Commit 22a1b93

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Suggest extension members for an implicit target in extension members
I added one test for this case and several other tests for already passing cases. I think that some of these cases were failing before the switch away from using available suggestions for imported libraries and was originally trying to write a test for a different reported problem, but the test passed. Change-Id: I989d8419506c59b883fe5b52168e15fd7d68787c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201300 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 3cf34d1 commit 22a1b93

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

pkg/analysis_server/lib/src/services/completion/dart/extension_member_contributor.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class ExtensionMemberContributor extends DartCompletionContributor {
5454
extendedType.element, type.element);
5555
_addTypeMembers(type, inheritanceDistance);
5656
}
57+
_addExtensionMembers(containingLibrary, extendedType);
5758
}
5859
}
5960
}

pkg/analysis_server/test/src/services/completion/dart/completion_test.dart

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import '../../../../completion_test_support.dart';
1010
void main() {
1111
defineReflectiveSuite(() {
1212
defineReflectiveTests(ConstructorCompletionTest);
13+
defineReflectiveTests(ExtensionCompletionTest);
1314
defineReflectiveTests(PropertyAccessorCompletionTest);
1415
});
1516
}
@@ -31,6 +32,142 @@ abstract class C {
3132
}
3233
}
3334

35+
@reflectiveTest
36+
class ExtensionCompletionTest extends CompletionTestCase {
37+
Future<void> test_explicitTarget_getter_sameUnit() async {
38+
addTestFile('''
39+
void f(String s) {
40+
s.^;
41+
}
42+
extension E on String {
43+
int get g => length;
44+
}
45+
''');
46+
await getSuggestions();
47+
assertHasCompletion('g');
48+
}
49+
50+
Future<void> test_explicitTarget_method_imported() async {
51+
newFile(convertPath('/project/bin/lib.dart'), content: '''
52+
extension E on String {
53+
void m() {}
54+
}
55+
''');
56+
addTestFile('''
57+
import 'lib.dart';
58+
void f(String s) {
59+
s.^;
60+
}
61+
''');
62+
await getSuggestions();
63+
assertHasCompletion('m');
64+
}
65+
66+
Future<void> test_explicitTarget_method_inLibrary() async {
67+
newFile(convertPath('/project/bin/lib.dart'), content: '''
68+
part 'test.dart';
69+
extension E on String {
70+
void m() {}
71+
}
72+
''');
73+
addTestFile('''
74+
part of 'lib.dart';
75+
void f(String s) {
76+
s.^;
77+
}
78+
''');
79+
await getSuggestions();
80+
assertHasCompletion('m');
81+
}
82+
83+
Future<void> test_explicitTarget_method_inPart() async {
84+
newFile(convertPath('/project/bin/part.dart'), content: '''
85+
extension E on String {
86+
void m() {}
87+
}
88+
''');
89+
addTestFile('''
90+
part 'part.dart';
91+
void f(String s) {
92+
s.^;
93+
}
94+
''');
95+
await getSuggestions();
96+
assertHasCompletion('m');
97+
}
98+
99+
@failingTest
100+
Future<void> test_explicitTarget_method_notImported() async {
101+
// Available suggestions data doesn't yet have information about extension
102+
// methods.
103+
newFile(convertPath('/project/bin/lib.dart'), content: '''
104+
extension E on String {
105+
void m() {}
106+
}
107+
''');
108+
addTestFile('''
109+
void f(String s) {
110+
s.^;
111+
}
112+
''');
113+
await getSuggestions();
114+
assertHasCompletion('m');
115+
}
116+
117+
Future<void> test_explicitTarget_method_sameUnit() async {
118+
addTestFile('''
119+
void f(String s) {
120+
s.^;
121+
}
122+
extension E on String {
123+
void m() {}
124+
}
125+
''');
126+
await getSuggestions();
127+
assertHasCompletion('m');
128+
}
129+
130+
Future<void> test_explicitTarget_setter_sameUnit() async {
131+
addTestFile('''
132+
void f(String s) {
133+
s.^;
134+
}
135+
extension E on String {
136+
set e(int v) {}
137+
}
138+
''');
139+
await getSuggestions();
140+
assertHasCompletion('e');
141+
}
142+
143+
Future<void> test_implicitTarget_inClass_method_sameUnit() async {
144+
addTestFile('''
145+
class C {
146+
void c() {
147+
^
148+
}
149+
}
150+
extension E on C {
151+
void m() {}
152+
}
153+
''');
154+
await getSuggestions();
155+
assertHasCompletion('m');
156+
}
157+
158+
Future<void> test_implicitTarget_inExtension_method_sameUnit() async {
159+
addTestFile('''
160+
extension E on String {
161+
void m() {
162+
^
163+
}
164+
}
165+
''');
166+
await getSuggestions();
167+
assertHasCompletion('m');
168+
}
169+
}
170+
34171
@reflectiveTest
35172
class PropertyAccessorCompletionTest extends CompletionTestCase {
36173
Future<void> test_setter_deprecated() async {

0 commit comments

Comments
 (0)