| 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.toplevel; | 5 library services.completion.computer.dart.toplevel; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol_server.dart' hide Element, | 9 import 'package:analysis_server/src/protocol_server.dart' hide Element, |
| 10 ElementKind; | 10 ElementKind; |
| 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:analysis_server/src/services/completion/suggestion_builder.dart'
; | 12 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; |
| 13 import 'package:analysis_server/src/services/search/search_engine.dart'; | 13 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 14 import 'package:analyzer/src/generated/ast.dart'; | 14 import 'package:analyzer/src/generated/ast.dart'; |
| 15 import 'package:analyzer/src/generated/element.dart'; | 15 import 'package:analyzer/src/generated/element.dart'; |
| 16 import 'package:analyzer/src/generated/resolver.dart'; | 16 import 'package:analyzer/src/generated/resolver.dart'; |
| 17 import 'package:analyzer/src/generated/scanner.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 18 import 'package:analyzer/src/generated/source.dart'; |
| 18 | 19 |
| 19 /** | 20 /** |
| 20 * A computer for calculating imported class and top level variable | 21 * A computer for calculating imported class and top level variable |
| 21 * `completion.getSuggestions` request results. | 22 * `completion.getSuggestions` request results. |
| 22 */ | 23 */ |
| 23 class ImportedComputer extends DartCompletionComputer { | 24 class ImportedComputer extends DartCompletionComputer { |
| 24 | 25 |
| 25 @override | 26 @override |
| 26 bool computeFast(DartCompletionRequest request) { | 27 bool computeFast(DartCompletionRequest request) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 @override | 97 @override |
| 97 Future<bool> visitSimpleIdentifier(SimpleIdentifier node) { | 98 Future<bool> visitSimpleIdentifier(SimpleIdentifier node) { |
| 98 return node.parent.accept(this); | 99 return node.parent.accept(this); |
| 99 } | 100 } |
| 100 | 101 |
| 101 @override | 102 @override |
| 102 Future<bool> visitTypeName(TypeName node) { | 103 Future<bool> visitTypeName(TypeName node) { |
| 103 return _addImportedElementSuggestions(typesOnly: true); | 104 return _addImportedElementSuggestions(typesOnly: true); |
| 104 } | 105 } |
| 105 | 106 |
| 107 @override |
| 108 visitVariableDeclaration(VariableDeclaration node) { |
| 109 Token equals = node.equals; |
| 110 // Make suggestions for the RHS of a variable declaration |
| 111 if (equals != null && request.offset >= equals.end) { |
| 112 return _addImportedElementSuggestions(); |
| 113 } |
| 114 return new Future.value(false); |
| 115 } |
| 116 |
| 106 Future _addCombinatorSuggestions(Combinator node) { | 117 Future _addCombinatorSuggestions(Combinator node) { |
| 107 var directive = node.getAncestor((parent) => parent is NamespaceDirective); | 118 var directive = node.getAncestor((parent) => parent is NamespaceDirective); |
| 108 if (directive is NamespaceDirective) { | 119 if (directive is NamespaceDirective) { |
| 109 LibraryElement library = directive.uriElement; | 120 LibraryElement library = directive.uriElement; |
| 110 LibraryElementSuggestionBuilder.suggestionsFor(request, library); | 121 LibraryElementSuggestionBuilder.suggestionsFor(request, library); |
| 111 return new Future.value(true); | 122 return new Future.value(true); |
| 112 } | 123 } |
| 113 | 124 |
| 114 return new Future.value(false); | 125 return new Future.value(false); |
| 115 } | 126 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 importElem.isDeprecated, | 235 importElem.isDeprecated, |
| 225 false); | 236 false); |
| 226 LibraryElement lib = importElem.importedLibrary; | 237 LibraryElement lib = importElem.importedLibrary; |
| 227 if (lib != null) { | 238 if (lib != null) { |
| 228 suggestion.element = newElement_fromEngine(lib); | 239 suggestion.element = newElement_fromEngine(lib); |
| 229 } | 240 } |
| 230 request.suggestions.add(suggestion); | 241 request.suggestions.add(suggestion); |
| 231 } | 242 } |
| 232 } | 243 } |
| 233 } | 244 } |
| OLD | NEW |