| 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.computer.dart.local; | 5 library services.completion.computer.dart.local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, | 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, |
| 10 ElementKind; | 10 ElementKind; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 _LocalVisitor localVisitor = new _LocalVisitor( | 28 _LocalVisitor localVisitor = new _LocalVisitor( |
| 29 request, | 29 request, |
| 30 request.offset, | 30 request.offset, |
| 31 optype.includeOnlyTypeNameSuggestions, | 31 optype.includeOnlyTypeNameSuggestions, |
| 32 !optype.includeVoidReturnSuggestions); | 32 !optype.includeVoidReturnSuggestions); |
| 33 | 33 |
| 34 // Collect suggestions from the specific child [AstNode] that contains | 34 // Collect suggestions from the specific child [AstNode] that contains |
| 35 // the completion offset and all of its parents recursively. | 35 // the completion offset and all of its parents recursively. |
| 36 request.node.accept(localVisitor); | 36 request.node.accept(localVisitor); |
| 37 } | 37 } |
| 38 if (optype.includeStatementLabelSuggestions) { | 38 if (optype.includeStatementLabelSuggestions || |
| 39 _LabelVisitor labelVisitor = new _LabelVisitor(request); | 39 optype.includeCaseLabelSuggestions) { |
| 40 _LabelVisitor labelVisitor = new _LabelVisitor( |
| 41 request, |
| 42 optype.includeStatementLabelSuggestions, |
| 43 optype.includeCaseLabelSuggestions); |
| 40 request.node.accept(labelVisitor); | 44 request.node.accept(labelVisitor); |
| 41 } | 45 } |
| 42 | 46 |
| 43 // If the unit is not a part and does not reference any parts | 47 // If the unit is not a part and does not reference any parts |
| 44 // then work is complete | 48 // then work is complete |
| 45 return !request.unit.directives.any( | 49 return !request.unit.directives.any( |
| 46 (Directive directive) => | 50 (Directive directive) => |
| 47 directive is PartOfDirective || directive is PartDirective); | 51 directive is PartOfDirective || directive is PartDirective); |
| 48 } | 52 } |
| 49 | 53 |
| 50 @override | 54 @override |
| 51 Future<bool> computeFull(DartCompletionRequest request) { | 55 Future<bool> computeFull(DartCompletionRequest request) { |
| 52 // TODO: implement computeFull | 56 // TODO: implement computeFull |
| 53 // include results from part files that are included in the library | 57 // include results from part files that are included in the library |
| 54 return new Future.value(false); | 58 return new Future.value(false); |
| 55 } | 59 } |
| 56 } | 60 } |
| 57 | 61 |
| 58 /** | 62 /** |
| 59 * A visitor for collecting suggestions for break and continue labels. | 63 * A visitor for collecting suggestions for break and continue labels. |
| 60 */ | 64 */ |
| 61 class _LabelVisitor extends LocalDeclarationVisitor { | 65 class _LabelVisitor extends LocalDeclarationVisitor { |
| 62 final DartCompletionRequest request; | 66 final DartCompletionRequest request; |
| 63 | 67 |
| 64 _LabelVisitor(DartCompletionRequest request) | 68 /** |
| 69 * True if statement labels should be included as suggestions. |
| 70 */ |
| 71 final bool includeStatementLabels; |
| 72 |
| 73 /** |
| 74 * True if case labels should be included as suggestions. |
| 75 */ |
| 76 final bool includeCaseLabels; |
| 77 |
| 78 _LabelVisitor(DartCompletionRequest request, this.includeStatementLabels, |
| 79 this.includeCaseLabels) |
| 65 : super(request.offset), | 80 : super(request.offset), |
| 66 request = request; | 81 request = request; |
| 67 | 82 |
| 68 @override | 83 @override |
| 69 void declaredClass(ClassDeclaration declaration) { | 84 void declaredClass(ClassDeclaration declaration) { |
| 70 // ignored | 85 // ignored |
| 71 } | 86 } |
| 72 | 87 |
| 73 @override | 88 @override |
| 74 void declaredClassTypeAlias(ClassTypeAlias declaration) { | 89 void declaredClassTypeAlias(ClassTypeAlias declaration) { |
| 75 // ignored | 90 // ignored |
| 76 } | 91 } |
| 77 | 92 |
| 78 @override | 93 @override |
| 79 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { | 94 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { |
| 80 // ignored | 95 // ignored |
| 81 } | 96 } |
| 82 | 97 |
| 83 @override | 98 @override |
| 84 void declaredFunction(FunctionDeclaration declaration) { | 99 void declaredFunction(FunctionDeclaration declaration) { |
| 85 // ignored | 100 // ignored |
| 86 } | 101 } |
| 87 | 102 |
| 88 @override | 103 @override |
| 89 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { | 104 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { |
| 90 // ignored | 105 // ignored |
| 91 } | 106 } |
| 92 | 107 |
| 93 @override | 108 @override |
| 94 void declaredLabel(Label label) { | 109 void declaredLabel(Label label, bool isCaseLabel) { |
| 95 CompletionSuggestion suggestion = _addSuggestion(label.label); | 110 if (isCaseLabel ? includeCaseLabels : includeStatementLabels) { |
| 96 if (suggestion != null) { | 111 CompletionSuggestion suggestion = _addSuggestion(label.label); |
| 97 suggestion.element = | 112 if (suggestion != null) { |
| 98 _createElement(protocol.ElementKind.LABEL, label.label); | 113 suggestion.element = |
| 114 _createElement(protocol.ElementKind.LABEL, label.label); |
| 115 } |
| 99 } | 116 } |
| 100 } | 117 } |
| 101 | 118 |
| 102 @override | 119 @override |
| 103 void declaredLocalVar(SimpleIdentifier name, TypeName type) { | 120 void declaredLocalVar(SimpleIdentifier name, TypeName type) { |
| 104 // ignored | 121 // ignored |
| 105 } | 122 } |
| 106 | 123 |
| 107 @override | 124 @override |
| 108 void declaredMethod(MethodDeclaration declaration) { | 125 void declaredMethod(MethodDeclaration declaration) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 protocol.ElementKind.FUNCTION_TYPE_ALIAS, | 296 protocol.ElementKind.FUNCTION_TYPE_ALIAS, |
| 280 declaration.name, | 297 declaration.name, |
| 281 null, | 298 null, |
| 282 NO_RETURN_TYPE, | 299 NO_RETURN_TYPE, |
| 283 true, | 300 true, |
| 284 isDeprecated); | 301 isDeprecated); |
| 285 } | 302 } |
| 286 } | 303 } |
| 287 | 304 |
| 288 @override | 305 @override |
| 289 void declaredLabel(Label label) { | 306 void declaredLabel(Label label, bool isCaseLabel) { |
| 290 // ignored | 307 // ignored |
| 291 } | 308 } |
| 292 | 309 |
| 293 @override | 310 @override |
| 294 void declaredLocalVar(SimpleIdentifier name, TypeName type) { | 311 void declaredLocalVar(SimpleIdentifier name, TypeName type) { |
| 295 if (typesOnly) { | 312 if (typesOnly) { |
| 296 return; | 313 return; |
| 297 } | 314 } |
| 298 CompletionSuggestion suggestion = _addSuggestion(name, type, null, false); | 315 CompletionSuggestion suggestion = _addSuggestion(name, type, null, false); |
| 299 if (suggestion != null) { | 316 if (suggestion != null) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 if (name == null || name.length <= 0) { | 495 if (name == null || name.length <= 0) { |
| 479 return DYNAMIC; | 496 return DYNAMIC; |
| 480 } | 497 } |
| 481 TypeArgumentList typeArgs = type.typeArguments; | 498 TypeArgumentList typeArgs = type.typeArguments; |
| 482 if (typeArgs != null) { | 499 if (typeArgs != null) { |
| 483 //TODO (danrubel) include type arguments | 500 //TODO (danrubel) include type arguments |
| 484 } | 501 } |
| 485 return name; | 502 return name; |
| 486 } | 503 } |
| 487 } | 504 } |
| OLD | NEW |