| 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; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 return false; | 32 return false; |
| 33 } | 33 } |
| 34 | 34 |
| 35 @override | 35 @override |
| 36 Future<bool> computeFull(DartCompletionRequest request) { | 36 Future<bool> computeFull(DartCompletionRequest request) { |
| 37 return request.node.accept(new _ImportedVisitor(request)); | 37 return request.node.accept(new _ImportedVisitor(request)); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * A visitor for determining which imported class and top level variable | 42 * A visitor for determining which imported classes and top level variables |
| 43 * should be suggested and building those suggestions. | 43 * should be suggested and building those suggestions. |
| 44 */ | 44 */ |
| 45 class _ImportedVisitor extends GeneralizingAstVisitor<Future<bool>> { | 45 class _ImportedVisitor extends GeneralizingAstVisitor<Future<bool>> { |
| 46 final DartCompletionRequest request; | 46 final DartCompletionRequest request; |
| 47 | 47 |
| 48 _ImportedVisitor(this.request); | 48 _ImportedVisitor(this.request); |
| 49 | 49 |
| 50 @override | 50 @override |
| 51 Future<bool> visitArgumentList(ArgumentList node) { | 51 Future<bool> visitArgumentList(ArgumentList node) { |
| 52 return _addImportedElementSuggestions(node, excludeVoidReturn: true); | 52 return _addImportedElementSuggestions(node, excludeVoidReturn: true); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 if (equals != null && request.offset >= equals.end) { | 187 if (equals != null && request.offset >= equals.end) { |
| 188 return _addImportedElementSuggestions(node, excludeVoidReturn: true); | 188 return _addImportedElementSuggestions(node, excludeVoidReturn: true); |
| 189 } | 189 } |
| 190 return new Future.value(false); | 190 return new Future.value(false); |
| 191 } | 191 } |
| 192 | 192 |
| 193 Future _addCombinatorSuggestions(Combinator node) { | 193 Future _addCombinatorSuggestions(Combinator node) { |
| 194 var directive = node.getAncestor((parent) => parent is NamespaceDirective); | 194 var directive = node.getAncestor((parent) => parent is NamespaceDirective); |
| 195 if (directive is NamespaceDirective) { | 195 if (directive is NamespaceDirective) { |
| 196 LibraryElement library = directive.uriElement; | 196 LibraryElement library = directive.uriElement; |
| 197 LibraryElementSuggestionBuilder.suggestionsFor(request, library); | 197 LibraryElementSuggestionBuilder.suggestionsFor( |
| 198 request, |
| 199 CompletionSuggestionKind.IDENTIFIER, |
| 200 library); |
| 198 return new Future.value(true); | 201 return new Future.value(true); |
| 199 } | 202 } |
| 200 | |
| 201 return new Future.value(false); | 203 return new Future.value(false); |
| 202 } | 204 } |
| 203 | 205 |
| 204 void _addElementSuggestion(Element element, bool typesOnly, | 206 void _addElementSuggestion(Element element, bool typesOnly, |
| 205 bool excludeVoidReturn, CompletionRelevance relevance) { | 207 bool excludeVoidReturn, CompletionRelevance relevance) { |
| 206 | 208 |
| 207 if (element is ExecutableElement) { | 209 if (element is ExecutableElement) { |
| 208 if (element.isOperator) { | 210 if (element.isOperator) { |
| 209 return; | 211 return; |
| 210 } | 212 } |
| 211 if (excludeVoidReturn) { | 213 if (excludeVoidReturn) { |
| 212 DartType returnType = element.returnType; | 214 DartType returnType = element.returnType; |
| 213 if (returnType != null && returnType.isVoid) { | 215 if (returnType != null && returnType.isVoid) { |
| 214 return; | 216 return; |
| 215 } | 217 } |
| 216 } | 218 } |
| 217 } | 219 } |
| 218 if (typesOnly && element is! ClassElement) { | 220 if (typesOnly && element is! ClassElement) { |
| 219 return; | 221 return; |
| 220 } | 222 } |
| 221 | 223 |
| 222 CompletionSuggestionKind kind = | |
| 223 newCompletionSuggestionKind_fromElementKind(element.kind); | |
| 224 | |
| 225 String completion = element.displayName; | 224 String completion = element.displayName; |
| 226 CompletionSuggestion suggestion = new CompletionSuggestion( | 225 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 227 kind, | 226 CompletionSuggestionKind.INVOCATION, |
| 228 relevance, | 227 relevance, |
| 229 completion, | 228 completion, |
| 230 completion.length, | 229 completion.length, |
| 231 0, | 230 0, |
| 232 element.isDeprecated, | 231 element.isDeprecated, |
| 233 false); | 232 false); |
| 234 | 233 |
| 235 suggestion.element = newElement_fromEngine(element); | 234 suggestion.element = newElement_fromEngine(element); |
| 236 | 235 |
| 237 DartType type; | 236 DartType type; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 373 } |
| 375 }); | 374 }); |
| 376 return true; | 375 return true; |
| 377 }); | 376 }); |
| 378 } | 377 } |
| 379 | 378 |
| 380 void _addLibraryPrefixSuggestion(ImportElement importElem) { | 379 void _addLibraryPrefixSuggestion(ImportElement importElem) { |
| 381 String completion = importElem.prefix.displayName; | 380 String completion = importElem.prefix.displayName; |
| 382 if (completion != null && completion.length > 0) { | 381 if (completion != null && completion.length > 0) { |
| 383 CompletionSuggestion suggestion = new CompletionSuggestion( | 382 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 384 CompletionSuggestionKind.LIBRARY_PREFIX, | 383 CompletionSuggestionKind.INVOCATION, |
| 385 CompletionRelevance.DEFAULT, | 384 CompletionRelevance.DEFAULT, |
| 386 completion, | 385 completion, |
| 387 completion.length, | 386 completion.length, |
| 388 0, | 387 0, |
| 389 importElem.isDeprecated, | 388 importElem.isDeprecated, |
| 390 false); | 389 false); |
| 391 LibraryElement lib = importElem.importedLibrary; | 390 LibraryElement lib = importElem.importedLibrary; |
| 392 if (lib != null) { | 391 if (lib != null) { |
| 393 suggestion.element = newElement_fromEngine(lib); | 392 suggestion.element = newElement_fromEngine(lib); |
| 394 } | 393 } |
| 395 request.suggestions.add(suggestion); | 394 request.suggestions.add(suggestion); |
| 396 } | 395 } |
| 397 } | 396 } |
| 398 } | 397 } |
| OLD | NEW |