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 | 2 |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 library services.completion.contributor.dart.keyword; | 6 library services.completion.contributor.dart.keyword; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 10 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
11 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 11 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
12 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
13 import 'package:analyzer/src/generated/scanner.dart'; | 13 import 'package:analyzer/src/generated/scanner.dart'; |
14 | 14 |
15 const ASYNC = 'async'; | 15 const ASYNC = 'async'; |
16 const AWAIT = 'await'; | 16 const AWAIT = 'await'; |
17 | 17 |
18 /** | 18 /** |
19 * A contributor for calculating `completion.getSuggestions` request results | 19 * A contributor for calculating `completion.getSuggestions` request results |
20 * for the local library in which the completion is requested. | 20 * for the local library in which the completion is requested. |
21 */ | 21 */ |
22 class KeywordContributor extends DartCompletionContributor { | 22 class KeywordContributor extends DartCompletionContributor { |
23 @override | 23 @override |
24 bool computeFast(DartCompletionRequest request) { | 24 bool computeFast(DartCompletionRequest request) { |
25 request.target.containingNode.accept(new _KeywordVisitor(request)); | 25 if (!request.target.isCommentText) { |
| 26 request.target.containingNode.accept(new _KeywordVisitor(request)); |
| 27 } |
26 return true; | 28 return true; |
27 } | 29 } |
28 | 30 |
29 @override | 31 @override |
30 Future<bool> computeFull(DartCompletionRequest request) { | 32 Future<bool> computeFull(DartCompletionRequest request) { |
31 return new Future.value(false); | 33 return new Future.value(false); |
32 } | 34 } |
33 } | 35 } |
34 | 36 |
35 /** | 37 /** |
36 * A vistor for generating keyword suggestions. | 38 * A visitor for generating keyword suggestions. |
37 */ | 39 */ |
38 class _KeywordVisitor extends GeneralizingAstVisitor { | 40 class _KeywordVisitor extends GeneralizingAstVisitor { |
39 final DartCompletionRequest request; | 41 final DartCompletionRequest request; |
40 final Object entity; | 42 final Object entity; |
41 | 43 |
42 _KeywordVisitor(DartCompletionRequest request) | 44 _KeywordVisitor(DartCompletionRequest request) |
43 : this.request = request, | 45 : this.request = request, |
44 this.entity = request.target.entity; | 46 this.entity = request.target.entity; |
45 | 47 |
46 @override | 48 @override |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 Keyword.TRUE | 171 Keyword.TRUE |
170 ]); | 172 ]); |
171 } else { | 173 } else { |
172 _addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH); | 174 _addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH); |
173 } | 175 } |
174 } | 176 } |
175 } | 177 } |
176 | 178 |
177 @override | 179 @override |
178 visitFormalParameterList(FormalParameterList node) { | 180 visitFormalParameterList(FormalParameterList node) { |
179 AstNode constructorDecl = | 181 AstNode constructorDeclaration = |
180 node.getAncestor((p) => p is ConstructorDeclaration); | 182 node.getAncestor((p) => p is ConstructorDeclaration); |
181 if (constructorDecl != null) { | 183 if (constructorDeclaration != null) { |
182 _addSuggestions([Keyword.THIS]); | 184 _addSuggestions([Keyword.THIS]); |
183 } | 185 } |
184 } | 186 } |
185 | 187 |
186 @override | 188 @override |
187 visitForStatement(ForStatement node) { | 189 visitForStatement(ForStatement node) { |
188 if (entity == node.rightSeparator && entity.toString() != ';') { | 190 if (entity == node.rightSeparator && entity.toString() != ';') { |
189 // Handle the degenerate case while typing - for (int x i^) | 191 // Handle the degenerate case while typing - for (int x i^) |
190 _addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH); | 192 _addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH); |
191 } | 193 } |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 512 |
511 bool _inLoop(AstNode node) => | 513 bool _inLoop(AstNode node) => |
512 _inDoLoop(node) || _inForLoop(node) || _inWhileLoop(node); | 514 _inDoLoop(node) || _inForLoop(node) || _inWhileLoop(node); |
513 | 515 |
514 bool _inSwitch(AstNode node) => | 516 bool _inSwitch(AstNode node) => |
515 node.getAncestor((p) => p is SwitchStatement) != null; | 517 node.getAncestor((p) => p is SwitchStatement) != null; |
516 | 518 |
517 bool _inWhileLoop(AstNode node) => | 519 bool _inWhileLoop(AstNode node) => |
518 node.getAncestor((p) => p is WhileStatement) != null; | 520 node.getAncestor((p) => p is WhileStatement) != null; |
519 } | 521 } |
OLD | NEW |