@@ -102,6 +102,11 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
102
102
_forExpression (node);
103
103
}
104
104
105
+ @override
106
+ void visitBooleanLiteral (BooleanLiteral node) {
107
+ _forExpression (node);
108
+ }
109
+
105
110
@override
106
111
void visitClassDeclaration (ClassDeclaration node) {
107
112
if (offset < node.classKeyword.offset) {
@@ -141,11 +146,99 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
141
146
}
142
147
}
143
148
149
+ @override
150
+ void visitConstructorDeclaration (ConstructorDeclaration node) {
151
+ var separator = node.separator;
152
+ if (separator != null ) {
153
+ if (offset >= separator.end && offset <= node.body.offset) {
154
+ collector.completionLocation = 'ConstructorDeclaration_initializer' ;
155
+ keywordHelper.addConstructorInitializerKeywords (node);
156
+ }
157
+ }
158
+ }
159
+
144
160
@override
145
161
void visitDoubleLiteral (DoubleLiteral node) {
146
162
_visitParentIfAtOrBeforeNode (node);
147
163
}
148
164
165
+ @override
166
+ void visitEnumDeclaration (EnumDeclaration node) {
167
+ if (! featureSet.isEnabled (Feature .enhanced_enums)) {
168
+ return ;
169
+ }
170
+ if (offset < node.enumKeyword.offset) {
171
+ // There are no modifiers for enums.
172
+ return ;
173
+ }
174
+ if (offset <= node.enumKeyword.end) {
175
+ keywordHelper.addKeyword (Keyword .ENUM );
176
+ return ;
177
+ }
178
+ if (offset <= node.name.end) {
179
+ // TODO(brianwilkerson) Suggest a name for the mixin.
180
+ return ;
181
+ }
182
+ if (offset <= node.leftBracket.offset) {
183
+ keywordHelper.addEnumDeclarationKeywords (node);
184
+ return ;
185
+ }
186
+ var rightBracket = node.rightBracket;
187
+ if (! rightBracket.isSynthetic && offset >= rightBracket.end) {
188
+ return ;
189
+ }
190
+ var semicolon = node.semicolon;
191
+ if (semicolon != null && offset >= semicolon.end) {
192
+ collector.completionLocation = 'EnumDeclaration_member' ;
193
+ _forEnumMember ();
194
+ }
195
+ }
196
+
197
+ @override
198
+ void visitExtensionDeclaration (ExtensionDeclaration node) {
199
+ if (offset < node.extensionKeyword.offset) {
200
+ // There are no modifiers for extensions.
201
+ return ;
202
+ }
203
+ if (offset <= node.extensionKeyword.end) {
204
+ keywordHelper.addKeyword (Keyword .EXTENSION );
205
+ return ;
206
+ }
207
+ var name = node.name;
208
+ if (name != null && offset <= name.end) {
209
+ // TODO(brianwilkerson) We probably need to suggest `on`.
210
+ // TODO(brianwilkerson) We probably need to suggest `type` when extension
211
+ // types are supported.
212
+ // Don't suggest a name for the extension.
213
+ return ;
214
+ }
215
+ if (offset <= node.leftBracket.offset) {
216
+ if (node.onKeyword.isSynthetic) {
217
+ keywordHelper.addExtensionDeclarationKeywords (node);
218
+ } else {
219
+ collector.completionLocation = 'ExtensionDeclaration_extendedType' ;
220
+ }
221
+ return ;
222
+ }
223
+ if (offset >= node.leftBracket.end && offset <= node.rightBracket.offset) {
224
+ collector.completionLocation = 'ExtensionDeclaration_member' ;
225
+ _forExtensionMember ();
226
+ }
227
+ }
228
+
229
+ @override
230
+ void visitFunctionDeclaration (FunctionDeclaration node) {
231
+ // If the cursor is at the beginning of the declaration, include the
232
+ // compilation unit keywords. See dartbug.com/41039.
233
+ var returnType = node.returnType;
234
+ if ((returnType == null || returnType.beginToken == returnType.endToken) &&
235
+ offset <= node.name.offset) {
236
+ collector.completionLocation = 'FunctionDeclaration_returnType' ;
237
+ keywordHelper.addKeyword (Keyword .DYNAMIC );
238
+ keywordHelper.addKeyword (Keyword .VOID );
239
+ }
240
+ }
241
+
149
242
@override
150
243
void visitIntegerLiteral (IntegerLiteral node) {
151
244
_visitParentIfAtOrBeforeNode (node);
@@ -204,6 +297,42 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
204
297
_forPattern ();
205
298
}
206
299
300
+ @override
301
+ void visitMixinDeclaration (MixinDeclaration node) {
302
+ if (offset < node.mixinKeyword.offset) {
303
+ keywordHelper.addMixinModifiers (node);
304
+ return ;
305
+ }
306
+ if (offset <= node.mixinKeyword.end) {
307
+ keywordHelper.addKeyword (Keyword .MIXIN );
308
+ return ;
309
+ }
310
+ if (offset <= node.name.end) {
311
+ // TODO(brianwilkerson) Suggest a name for the mixin.
312
+ return ;
313
+ }
314
+ if (offset <= node.leftBracket.offset) {
315
+ keywordHelper.addMixinDeclarationKeywords (node);
316
+ return ;
317
+ }
318
+ if (offset >= node.leftBracket.end && offset <= node.rightBracket.offset) {
319
+ collector.completionLocation = 'MixinDeclaration_member' ;
320
+ _forMixinMember ();
321
+ var element = node.members.elementBefore (offset);
322
+ if (element is MethodDeclaration ) {
323
+ var body = element.body;
324
+ if (body.isEmpty) {
325
+ keywordHelper.addFunctionBodyModifiers (body);
326
+ }
327
+ }
328
+ }
329
+ }
330
+
331
+ @override
332
+ void visitNullLiteral (NullLiteral node) {
333
+ _forExpression (node);
334
+ }
335
+
207
336
@override
208
337
void visitParenthesizedPattern (ParenthesizedPattern node) {
209
338
collector.completionLocation = 'ParenthesizedPattern_expression' ;
@@ -274,6 +403,53 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
274
403
_visitParentIfAtOrBeforeNode (node);
275
404
}
276
405
406
+ @override
407
+ void visitSymbolLiteral (SymbolLiteral node) {
408
+ _forExpression (node);
409
+ }
410
+
411
+ @override
412
+ void visitThisExpression (ThisExpression node) {
413
+ _forExpression (node);
414
+ }
415
+
416
+ @override
417
+ void visitThrowExpression (ThrowExpression node) {
418
+ collector.completionLocation = 'ThrowExpression_expression' ;
419
+ _forExpression (node);
420
+ }
421
+
422
+ @override
423
+ void visitTopLevelVariableDeclaration (TopLevelVariableDeclaration node) {
424
+ var variableDeclarationList = node.variables;
425
+ var variables = variableDeclarationList.variables;
426
+ if (variables.isEmpty || offset > variables.first.beginToken.end) {
427
+ return ;
428
+ }
429
+ if (node.externalKeyword == null ) {
430
+ keywordHelper.addKeyword (Keyword .EXTERNAL );
431
+ }
432
+ if (variableDeclarationList.lateKeyword == null &&
433
+ featureSet.isEnabled (Feature .non_nullable)) {
434
+ keywordHelper.addKeyword (Keyword .LATE );
435
+ }
436
+ if (! variables.first.isConst) {
437
+ keywordHelper.addKeyword (Keyword .CONST );
438
+ }
439
+ if (! variables.first.isFinal) {
440
+ keywordHelper.addKeyword (Keyword .FINAL );
441
+ }
442
+ }
443
+
444
+ @override
445
+ void visitVariableDeclaration (VariableDeclaration node) {
446
+ var equals = node.equals;
447
+ if (equals != null && offset >= equals.end) {
448
+ collector.completionLocation = 'VariableDeclaration_initializer' ;
449
+ _forExpression (node);
450
+ }
451
+ }
452
+
277
453
/// Add the suggestions that are appropriate when the selection is at the
278
454
/// beginning of a class member.
279
455
void _forClassMember () {
@@ -304,6 +480,12 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
304
480
// _addVariablesInScope(node, mustBeConstant: true);
305
481
}
306
482
483
+ /// Add the suggestions that are appropriate when the selection is at the
484
+ /// beginning of an enum member.
485
+ void _forEnumMember () {
486
+ keywordHelper.addEnumMemberKeywords ();
487
+ }
488
+
307
489
/// Add the suggestions that are appropriate when the selection is at the
308
490
/// beginning of an expression. The [node] provides context to determine which
309
491
/// keywords to include.
@@ -314,6 +496,18 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
314
496
// _addVariablesInScope(node);
315
497
}
316
498
499
+ /// Add the suggestions that are appropriate when the selection is at the
500
+ /// beginning of an extension member.
501
+ void _forExtensionMember () {
502
+ keywordHelper.addExtensionMemberKeywords ();
503
+ }
504
+
505
+ /// Add the suggestions that are appropriate when the selection is at the
506
+ /// beginning of a mixin member.
507
+ void _forMixinMember () {
508
+ keywordHelper.addMixinMemberKeywords ();
509
+ }
510
+
317
511
/// Add the suggestions that are appropriate when the selection is at the
318
512
/// beginning of a pattern.
319
513
void _forPattern () {
0 commit comments