Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analysis_server.src.provisional.completion.completion_dart; | 5 library analysis_server.src.provisional.completion.completion_dart; |
| 6 | 6 |
| 7 import 'dart:async'; | |
| 8 | |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 8 import 'package:analysis_server/src/provisional/completion/completion_core.dart' ; | 10 import 'package:analysis_server/src/provisional/completion/completion_core.dart' ; |
| 9 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart'; | 11 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart'; |
| 12 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart' | |
| 13 show DART_RELEVANCE_DEFAULT; | |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 14 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/element.dart' as model; |
| 12 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/task/model.dart'; |
| 13 | 17 |
| 14 /** | 18 /** |
| 15 * An object used to produce completions for a specific error within a Dart | 19 * An object used to produce completions within a Dart file. |
|
Brian Wilkerson
2015/10/19 23:15:46
"completions within" --> "completions at a specifi
danrubel
2015/10/20 00:11:17
Done.
| |
| 16 * file. Completion contributors are long-lived objects and must not retain any | 20 * Contributors are long-lived objects and must not retain any state. |
|
Brian Wilkerson
2015/10/19 23:15:46
I think with the introduction of futures, they're
danrubel
2015/10/20 00:11:17
Done.
| |
| 17 * state between invocations of [computeSuggestions]. | |
| 18 * | 21 * |
| 19 * Clients may extend this class when implementing plugins. | 22 * Clients may extend this class when implementing plugins. |
| 20 */ | 23 */ |
| 21 abstract class DartCompletionContributor implements CompletionContributor { | 24 abstract class DartCompletionContributor { |
| 22 @override | |
| 23 List<CompletionSuggestion> computeSuggestions(CompletionRequest request) { | |
| 24 if (request is DartCompletionRequest) { | |
| 25 return internalComputeSuggestions(request); | |
| 26 } | |
| 27 AnalysisContext context = request.context; | |
| 28 Source source = request.source; | |
| 29 List<Source> libraries = context.getLibrariesContaining(source); | |
| 30 if (libraries.length < 1) { | |
| 31 return null; | |
| 32 } | |
| 33 // CompilationUnit unit = | |
| 34 // context.getResolvedCompilationUnit2(source, libraries[0]); | |
| 35 // bool isResolved = true; | |
| 36 // if (unit == null) { | |
| 37 // // TODO(brianwilkerson) Implement a method for getting a parsed | |
| 38 // // compilation unit without parsing the unit if it hasn't been parsed. | |
| 39 // unit = context.getParsedCompilationUnit(source); | |
| 40 // if (unit == null) { | |
| 41 // return null; | |
| 42 // } | |
| 43 // isResolved = false; | |
| 44 // } | |
| 45 // DartCompletionRequest dartRequest = | |
| 46 // new DartCompletionRequestImpl(request, unit, isResolved); | |
| 47 // return internalComputeSuggestions(dartRequest); | |
| 48 return null; | |
| 49 } | |
| 50 | |
| 51 /** | 25 /** |
| 52 * Compute a list of completion suggestions based on the given completion | 26 * Compute completion suggestions based upon the given completion [request] |
| 53 * [request]. Return the suggestions that were computed. | 27 * to the given completion [collector]. |
| 28 * Return a [Future] that completes when suggestions have been added | |
| 29 * or `null` if any suggestions to be added have been added | |
| 30 * when the method returns. | |
| 54 */ | 31 */ |
| 55 List<CompletionSuggestion> internalComputeSuggestions( | 32 Future computeSuggestions( |
| 56 DartCompletionRequest request); | 33 DartCompletionRequest request, DartSuggestionCollector collector); |
| 57 } | 34 } |
| 58 | 35 |
| 59 /** | 36 /** |
| 60 * The information about a requested list of completions within a Dart file. | 37 * The information about a requested list of completions within a Dart file. |
| 61 * | 38 * |
| 62 * Clients may not extend, implement or mix-in this class. | 39 * Clients may not extend, implement or mix-in this class. |
| 63 */ | 40 */ |
| 64 abstract class DartCompletionRequest extends CompletionRequest { | 41 abstract class DartCompletionRequest extends CompletionRequest { |
| 65 /** | 42 /** |
| 66 * Return `true` if the compilation [unit] is resolved. | 43 * Return the parsed completion target. This determines |
| 44 * what part of the parse tree will receive the newly inserted text. | |
| 45 * Use [resolvedDeclarationTarget] to obtain a resolved completion target. | |
| 67 */ | 46 */ |
| 68 bool get isResolved; | 47 CompletionTarget get parsedTarget; |
| 69 | 48 |
| 70 /** | 49 @deprecated // Use parsedTarget |
| 71 * Return the completion target. This determines what part of the parse tree | |
| 72 * will receive the newly inserted text. | |
| 73 */ | |
| 74 CompletionTarget get target; | 50 CompletionTarget get target; |
| 75 | 51 |
| 76 /** | 52 @deprecated // Use parsedTarget.unit or resolvedTarget(...).unit |
|
Brian Wilkerson
2015/10/19 23:15:46
"resolvedTarget(...)" --> "resolvedDeclarationTarg
danrubel
2015/10/20 00:11:17
Done.
| |
| 77 * Cached information from a prior code completion operation. | |
| 78 */ | |
| 79 //DartCompletionCache get cache; | |
| 80 | |
| 81 /** | |
| 82 * Return the compilation unit in which the completion was requested. | |
| 83 */ | |
| 84 CompilationUnit get unit; | 53 CompilationUnit get unit; |
| 85 | 54 |
| 86 /** | 55 /** |
| 87 * Information about the types of suggestions that should be included. | 56 * Return partially resolved completion target where each declarations |
| 57 * in the compilation unit has been bound to corresponding element. | |
| 58 * More specifically: | |
| 59 * | |
| 60 * * The [SimpleIdentifier]s at all declaration sites have been bound | |
| 61 * to the element defined by the declaration, | |
| 62 * including the constants defined in an 'enum' declaration. | |
| 63 * * The types associated with declarations have been resolved, including | |
| 64 * the types of superclasses, mixins, interfaces, fields, return types, | |
| 65 * parameters, and local variables. | |
| 66 * * Directives 'library', 'part' and 'part of' are resolved. | |
| 67 * * Imports, exports, publicNamespace, entryPoint, | |
| 68 * and exportNamespace are set. | |
| 88 */ | 69 */ |
| 89 //OpType get _optype; | 70 Future<CompletionTarget> get resolvedDeclarationTarget; |
| 90 } | 71 } |
| 72 | |
| 73 /** | |
| 74 * An object used to collect suggestions. | |
| 75 * | |
| 76 * Clients should not extend, implement, or instantiate this class. | |
| 77 */ | |
| 78 abstract class DartSuggestionCollector { | |
| 79 /** | |
| 80 * Add a suggestion. | |
| 81 */ | |
| 82 void addCompletionSuggestion(CompletionSuggestion suggestion); | |
| 83 | |
| 84 /** | |
| 85 * Add a suggestion based upon the given element. | |
| 86 */ | |
| 87 void addElementSuggestion(model.Element element, | |
| 88 {bool includePrivateElements: false, | |
| 89 String prefix, | |
| 90 int relevance: DART_RELEVANCE_DEFAULT}); | |
| 91 } | |
| OLD | NEW |