@@ -31,6 +31,15 @@ class CompletionTest extends AbstractLspAnalysisServerTest {
31
31
);
32
32
}
33
33
34
+ @override
35
+ void setUp () {
36
+ super .setUp ();
37
+ writePackageConfig (
38
+ projectFolderPath,
39
+ flutter: true ,
40
+ );
41
+ }
42
+
34
43
Future <void > test_commitCharacter_completionItem () async {
35
44
await provideConfig (
36
45
() => initialize (
@@ -124,6 +133,55 @@ main() {
124
133
);
125
134
}
126
135
136
+ Future <void > test_completeFunctionCalls_flutterSetState () async {
137
+ // Flutter's setState method has special handling inside SuggestionBuilder
138
+ // that already adds in a selection (which overlaps with completeFunctionCalls).
139
+ // Ensure we don't end up with two sets of parens/placeholders in this case.
140
+ final content = '''
141
+ import 'package:flutter/material.dart';
142
+
143
+ class MyWidget extends StatefulWidget {
144
+ @override
145
+ _MyWidgetState createState() => _MyWidgetState();
146
+ }
147
+
148
+ class _MyWidgetState extends State<MyWidget> {
149
+ @override
150
+ Widget build(BuildContext context) {
151
+ [[setSt^]]
152
+ return Container();
153
+ }
154
+ }
155
+ ''' ;
156
+
157
+ await provideConfig (
158
+ () => initialize (
159
+ textDocumentCapabilities: withCompletionItemSnippetSupport (
160
+ emptyTextDocumentClientCapabilities),
161
+ workspaceCapabilities:
162
+ withConfigurationSupport (emptyWorkspaceClientCapabilities),
163
+ ),
164
+ {'completeFunctionCalls' : true },
165
+ );
166
+ await openFile (mainFileUri, withoutMarkers (content));
167
+ final res = await getCompletion (mainFileUri, positionFromMarker (content));
168
+ final item = res.singleWhere ((c) => c.label.startsWith ('setState(' ));
169
+
170
+ // Usually the label would be "setState(…)" but here it's slightly different
171
+ // to indicate a full statement is being inserted.
172
+ expect (item.label, equals ('setState(() {});' ));
173
+
174
+ // Ensure the snippet comes through in the expected format with the expected
175
+ // placeholders.
176
+ expect (item.insertTextFormat, equals (InsertTextFormat .Snippet ));
177
+ expect (item.insertText, equals ('setState(() {\n \$ {0:}\n \\ });' ));
178
+ expect (item.textEdit.newText, equals (item.insertText));
179
+ expect (
180
+ item.textEdit.range,
181
+ equals (rangeFromMarkers (content)),
182
+ );
183
+ }
184
+
127
185
Future <void > test_completeFunctionCalls_noRequiredParameters () async {
128
186
final content = '''
129
187
void myFunction({int a}) {}
0 commit comments