Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/keyword_contributor.dart

Issue 1285573003: suggest "in" in for statement (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library services.completion.contributor.dart.keyword; 5 library services.completion.contributor.dart.keyword;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // then the user is probably finishing that 117 // then the user is probably finishing that
118 _addImportDirectiveKeywords(previousMember); 118 _addImportDirectiveKeywords(previousMember);
119 return; 119 return;
120 } 120 }
121 } 121 }
122 if (previousMember == null || previousMember is Directive) { 122 if (previousMember == null || previousMember is Directive) {
123 if (previousMember == null && 123 if (previousMember == null &&
124 !node.directives.any((d) => d is LibraryDirective)) { 124 !node.directives.any((d) => d is LibraryDirective)) {
125 _addSuggestions([Keyword.LIBRARY], DART_RELEVANCE_HIGH); 125 _addSuggestions([Keyword.LIBRARY], DART_RELEVANCE_HIGH);
126 } 126 }
127 _addSuggestions([Keyword.IMPORT, Keyword.EXPORT, Keyword.PART], DART_RELEV ANCE_HIGH); 127 _addSuggestions(
128 [Keyword.IMPORT, Keyword.EXPORT, Keyword.PART], DART_RELEVANCE_HIGH);
128 } 129 }
129 if (entity == null || entity is Declaration) { 130 if (entity == null || entity is Declaration) {
130 if (previousMember is FunctionDeclaration && 131 if (previousMember is FunctionDeclaration &&
131 previousMember.functionExpression is FunctionExpression && 132 previousMember.functionExpression is FunctionExpression &&
132 previousMember.functionExpression.body is EmptyFunctionBody) { 133 previousMember.functionExpression.body is EmptyFunctionBody) {
133 _addSuggestion2(ASYNC, relevance: DART_RELEVANCE_HIGH); 134 _addSuggestion2(ASYNC, relevance: DART_RELEVANCE_HIGH);
134 } 135 }
135 _addCompilationUnitKeywords(); 136 _addCompilationUnitKeywords();
136 } 137 }
137 } 138 }
138 139
139 @override 140 @override
140 visitPropertyAccess(PropertyAccess node) {
141 // suggestions before '.' but not after
142 if (entity != node.propertyName) {
143 super.visitPropertyAccess(node);
144 }
145 }
146
147 @override
148 visitExpression(Expression node) { 141 visitExpression(Expression node) {
149 _addExpressionKeywords(node); 142 _addExpressionKeywords(node);
150 } 143 }
151 144
152 @override 145 @override
153 visitExpressionFunctionBody(ExpressionFunctionBody node) { 146 visitExpressionFunctionBody(ExpressionFunctionBody node) {
154 if (entity == node.expression) { 147 if (entity == node.expression) {
155 _addExpressionKeywords(node); 148 _addExpressionKeywords(node);
156 } 149 }
157 } 150 }
158 151
159 @override 152 @override
153 visitForEachStatement(ForEachStatement node) {
154 if (entity == node.inKeyword) {
155 _addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH);
156 }
157 }
158
159 @override
160 visitFormalParameterList(FormalParameterList node) { 160 visitFormalParameterList(FormalParameterList node) {
161 AstNode constructorDecl = 161 AstNode constructorDecl =
162 node.getAncestor((p) => p is ConstructorDeclaration); 162 node.getAncestor((p) => p is ConstructorDeclaration);
163 if (constructorDecl != null) { 163 if (constructorDecl != null) {
164 _addSuggestions([Keyword.THIS]); 164 _addSuggestions([Keyword.THIS]);
165 } 165 }
166 } 166 }
167 167
168 @override 168 @override
169 visitForStatement(ForStatement node) {
170 if (entity == node.rightSeparator && entity.toString() != ';') {
171 // Handle the degenerate case while typing - for (int x i^)
172 _addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH);
173 }
174 }
175
176 @override
169 visitFunctionExpression(FunctionExpression node) { 177 visitFunctionExpression(FunctionExpression node) {
170 if (entity == node.body) { 178 if (entity == node.body) {
171 if (!node.body.isAsynchronous) { 179 if (!node.body.isAsynchronous) {
172 _addSuggestion2(ASYNC, relevance: DART_RELEVANCE_HIGH); 180 _addSuggestion2(ASYNC, relevance: DART_RELEVANCE_HIGH);
173 } 181 }
174 if (node.body is EmptyFunctionBody && 182 if (node.body is EmptyFunctionBody &&
175 node.parent is FunctionDeclaration && 183 node.parent is FunctionDeclaration &&
176 node.parent.parent is CompilationUnit) { 184 node.parent.parent is CompilationUnit) {
177 _addCompilationUnitKeywords(); 185 _addCompilationUnitKeywords();
178 } 186 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 261 }
254 262
255 @override 263 @override
256 visitPrefixedIdentifier(PrefixedIdentifier node) { 264 visitPrefixedIdentifier(PrefixedIdentifier node) {
257 if (entity != node.identifier) { 265 if (entity != node.identifier) {
258 _addExpressionKeywords(node); 266 _addExpressionKeywords(node);
259 } 267 }
260 } 268 }
261 269
262 @override 270 @override
271 visitPropertyAccess(PropertyAccess node) {
272 // suggestions before '.' but not after
273 if (entity != node.propertyName) {
274 super.visitPropertyAccess(node);
275 }
276 }
277
278 @override
263 visitReturnStatement(ReturnStatement node) { 279 visitReturnStatement(ReturnStatement node) {
264 if (entity == node.expression) { 280 if (entity == node.expression) {
265 _addExpressionKeywords(node); 281 _addExpressionKeywords(node);
266 } 282 }
267 } 283 }
268 284
269 @override 285 @override
270 visitStringLiteral(StringLiteral node) { 286 visitStringLiteral(StringLiteral node) {
271 // ignored 287 // ignored
272 } 288 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 return false; 448 return false;
433 } 449 }
434 AstNode parent = body.parent; 450 AstNode parent = body.parent;
435 if (parent is ConstructorDeclaration || parent is MethodDeclaration) { 451 if (parent is ConstructorDeclaration || parent is MethodDeclaration) {
436 return true; 452 return true;
437 } 453 }
438 node = parent; 454 node = parent;
439 } 455 }
440 } 456 }
441 } 457 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698