| OLD | NEW |
| 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 Loading... |
| 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 Token previous = node.inKeyword.previous; |
| 156 if (previous is SyntheticStringToken && previous.lexeme == 'in') { |
| 157 previous = previous.previous; |
| 158 } |
| 159 if (previous != null && previous.type == TokenType.EQ) { |
| 160 _addSuggestions( |
| 161 [Keyword.FALSE, Keyword.NEW, Keyword.NULL, Keyword.TRUE]); |
| 162 } else { |
| 163 _addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH); |
| 164 } |
| 165 } |
| 166 } |
| 167 |
| 168 @override |
| 160 visitFormalParameterList(FormalParameterList node) { | 169 visitFormalParameterList(FormalParameterList node) { |
| 161 AstNode constructorDecl = | 170 AstNode constructorDecl = |
| 162 node.getAncestor((p) => p is ConstructorDeclaration); | 171 node.getAncestor((p) => p is ConstructorDeclaration); |
| 163 if (constructorDecl != null) { | 172 if (constructorDecl != null) { |
| 164 _addSuggestions([Keyword.THIS]); | 173 _addSuggestions([Keyword.THIS]); |
| 165 } | 174 } |
| 166 } | 175 } |
| 167 | 176 |
| 168 @override | 177 @override |
| 178 visitForStatement(ForStatement node) { |
| 179 if (entity == node.rightSeparator && entity.toString() != ';') { |
| 180 // Handle the degenerate case while typing - for (int x i^) |
| 181 _addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH); |
| 182 } |
| 183 } |
| 184 |
| 185 @override |
| 169 visitFunctionExpression(FunctionExpression node) { | 186 visitFunctionExpression(FunctionExpression node) { |
| 170 if (entity == node.body) { | 187 if (entity == node.body) { |
| 171 if (!node.body.isAsynchronous) { | 188 if (!node.body.isAsynchronous) { |
| 172 _addSuggestion2(ASYNC, relevance: DART_RELEVANCE_HIGH); | 189 _addSuggestion2(ASYNC, relevance: DART_RELEVANCE_HIGH); |
| 173 } | 190 } |
| 174 if (node.body is EmptyFunctionBody && | 191 if (node.body is EmptyFunctionBody && |
| 175 node.parent is FunctionDeclaration && | 192 node.parent is FunctionDeclaration && |
| 176 node.parent.parent is CompilationUnit) { | 193 node.parent.parent is CompilationUnit) { |
| 177 _addCompilationUnitKeywords(); | 194 _addCompilationUnitKeywords(); |
| 178 } | 195 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } | 270 } |
| 254 | 271 |
| 255 @override | 272 @override |
| 256 visitPrefixedIdentifier(PrefixedIdentifier node) { | 273 visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 257 if (entity != node.identifier) { | 274 if (entity != node.identifier) { |
| 258 _addExpressionKeywords(node); | 275 _addExpressionKeywords(node); |
| 259 } | 276 } |
| 260 } | 277 } |
| 261 | 278 |
| 262 @override | 279 @override |
| 280 visitPropertyAccess(PropertyAccess node) { |
| 281 // suggestions before '.' but not after |
| 282 if (entity != node.propertyName) { |
| 283 super.visitPropertyAccess(node); |
| 284 } |
| 285 } |
| 286 |
| 287 @override |
| 263 visitReturnStatement(ReturnStatement node) { | 288 visitReturnStatement(ReturnStatement node) { |
| 264 if (entity == node.expression) { | 289 if (entity == node.expression) { |
| 265 _addExpressionKeywords(node); | 290 _addExpressionKeywords(node); |
| 266 } | 291 } |
| 267 } | 292 } |
| 268 | 293 |
| 269 @override | 294 @override |
| 270 visitStringLiteral(StringLiteral node) { | 295 visitStringLiteral(StringLiteral node) { |
| 271 // ignored | 296 // ignored |
| 272 } | 297 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 return false; | 457 return false; |
| 433 } | 458 } |
| 434 AstNode parent = body.parent; | 459 AstNode parent = body.parent; |
| 435 if (parent is ConstructorDeclaration || parent is MethodDeclaration) { | 460 if (parent is ConstructorDeclaration || parent is MethodDeclaration) { |
| 436 return true; | 461 return true; |
| 437 } | 462 } |
| 438 node = parent; | 463 node = parent; |
| 439 } | 464 } |
| 440 } | 465 } |
| 441 } | 466 } |
| OLD | NEW |