| 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.invocation; | 5 library services.completion.contributor.dart.invocation; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 9 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 10 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; | 10 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; |
| 11 import 'package:analysis_server/src/services/completion/optype.dart'; | 11 import 'package:analysis_server/src/services/completion/optype.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:analyzer/src/generated/ast.dart'; | 13 import 'package:analyzer/src/generated/ast.dart'; |
| 14 import 'package:analyzer/src/generated/element.dart'; | 14 import 'package:analyzer/src/generated/element.dart'; |
| 15 | 15 |
| 16 import '../../protocol_server.dart' show CompletionSuggestionKind; | 16 import '../../protocol_server.dart' as protocol; |
| 17 import '../../protocol_server.dart' |
| 18 show CompletionSuggestion, CompletionSuggestionKind; |
| 17 | 19 |
| 18 /** | 20 /** |
| 19 * A contributor for calculating invocation / access suggestions | 21 * A contributor for calculating invocation / access suggestions |
| 20 * `completion.getSuggestions` request results. | 22 * `completion.getSuggestions` request results. |
| 21 */ | 23 */ |
| 22 class PrefixedElementContributor extends DartCompletionContributor { | 24 class PrefixedElementContributor extends DartCompletionContributor { |
| 23 SuggestionBuilder builder; | 25 SuggestionBuilder builder; |
| 24 | 26 |
| 25 @override | 27 @override |
| 26 bool computeFast(DartCompletionRequest request) { | 28 bool computeFast(DartCompletionRequest request) { |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 return new Future.value(false); | 298 return new Future.value(false); |
| 297 } | 299 } |
| 298 | 300 |
| 299 @override | 301 @override |
| 300 Future<bool> visitElement(Element element) { | 302 Future<bool> visitElement(Element element) { |
| 301 return new Future.value(false); | 303 return new Future.value(false); |
| 302 } | 304 } |
| 303 | 305 |
| 304 @override | 306 @override |
| 305 Future<bool> visitPrefixElement(PrefixElement element) { | 307 Future<bool> visitPrefixElement(PrefixElement element) { |
| 306 //TODO (danrubel) reimplement to use prefixElement.importedLibraries | |
| 307 // once that accessor is implemented and available in Dart | |
| 308 bool modified = false; | 308 bool modified = false; |
| 309 // Find the import directive with the given prefix | 309 // Find the import directive with the given prefix |
| 310 for (Directive directive in request.unit.directives) { | 310 for (Directive directive in request.unit.directives) { |
| 311 if (directive is ImportDirective) { | 311 if (directive is ImportDirective) { |
| 312 if (directive.prefix != null) { | 312 if (directive.prefix != null) { |
| 313 if (directive.prefix.name == element.name) { | 313 if (directive.prefix.name == element.name) { |
| 314 // Suggest elements from the imported library | 314 // Suggest elements from the imported library |
| 315 LibraryElement library = directive.uriElement; | 315 LibraryElement library = directive.uriElement; |
| 316 LibraryElementSuggestionBuilder.suggestionsFor(request, | 316 LibraryElementSuggestionBuilder.suggestionsFor(request, |
| 317 CompletionSuggestionKind.INVOCATION, library, | 317 CompletionSuggestionKind.INVOCATION, library, |
| 318 request.target.containingNode.parent is TypeName); | 318 request.target.containingNode.parent is TypeName); |
| 319 modified = true; | 319 modified = true; |
| 320 if (directive.deferredKeyword != null) { |
| 321 String completion = 'loadLibrary'; |
| 322 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 323 CompletionSuggestionKind.INVOCATION, DART_RELEVANCE_DEFAULT, |
| 324 completion, completion.length, 0, false, false, |
| 325 parameterNames: [], |
| 326 parameterTypes: [], |
| 327 requiredParameterCount: 0, |
| 328 hasNamedParameters: false, |
| 329 returnType: 'void'); |
| 330 suggestion.element = new protocol.Element( |
| 331 protocol.ElementKind.FUNCTION, completion, |
| 332 protocol.Element.makeFlags(), |
| 333 parameters: '()', returnType: 'void'); |
| 334 request.addSuggestion(suggestion); |
| 335 } |
| 320 } | 336 } |
| 321 } | 337 } |
| 322 } | 338 } |
| 323 } | 339 } |
| 324 return new Future.value(modified); | 340 return new Future.value(modified); |
| 325 } | 341 } |
| 326 | 342 |
| 327 @override | 343 @override |
| 328 Future<bool> visitPropertyAccessorElement(PropertyAccessorElement element) { | 344 Future<bool> visitPropertyAccessorElement(PropertyAccessorElement element) { |
| 329 if (element != null) { | 345 if (element != null) { |
| 330 PropertyInducingElement elemVar = element.variable; | 346 PropertyInducingElement elemVar = element.variable; |
| 331 if (elemVar != null) { | 347 if (elemVar != null) { |
| 332 InterfaceTypeSuggestionBuilder.suggestionsFor(request, elemVar.type); | 348 InterfaceTypeSuggestionBuilder.suggestionsFor(request, elemVar.type); |
| 333 } | 349 } |
| 334 return new Future.value(true); | 350 return new Future.value(true); |
| 335 } | 351 } |
| 336 return new Future.value(false); | 352 return new Future.value(false); |
| 337 } | 353 } |
| 338 | 354 |
| 339 @override | 355 @override |
| 340 Future<bool> visitVariableElement(VariableElement element) { | 356 Future<bool> visitVariableElement(VariableElement element) { |
| 341 InterfaceTypeSuggestionBuilder.suggestionsFor(request, element.type); | 357 InterfaceTypeSuggestionBuilder.suggestionsFor(request, element.type); |
| 342 return new Future.value(true); | 358 return new Future.value(true); |
| 343 } | 359 } |
| 344 } | 360 } |
| OLD | NEW |