| 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'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | |
| 12 import 'package:analyzer/src/generated/source.dart'; | |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * An object used to produce completions for a specific error within a Dart | 15 * An object used to produce completions |
| 16 * file. Completion contributors are long-lived objects and must not retain any | 16 * at a specific location within a Dart file. |
| 17 * state between invocations of [computeSuggestions]. | |
| 18 * | 17 * |
| 19 * Clients may extend this class when implementing plugins. | 18 * Clients may implement this class when implementing plugins. |
| 20 */ | 19 */ |
| 21 abstract class DartCompletionContributor implements CompletionContributor { | 20 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 /** | 21 /** |
| 52 * Compute a list of completion suggestions based on the given completion | 22 * Return a [Future] that completes with a list of suggestions |
| 53 * [request]. Return the suggestions that were computed. | 23 * for the given completion [request]. |
| 54 */ | 24 */ |
| 55 List<CompletionSuggestion> internalComputeSuggestions( | 25 Future<List<CompletionSuggestion>> computeSuggestions( |
| 56 DartCompletionRequest request); | 26 DartCompletionRequest request); |
| 57 } | 27 } |
| 58 | 28 |
| 59 /** | 29 /** |
| 60 * The information about a requested list of completions within a Dart file. | 30 * The information about a requested list of completions within a Dart file. |
| 61 * | 31 * |
| 62 * Clients may not extend, implement or mix-in this class. | 32 * Clients may not extend, implement or mix-in this class. |
| 63 */ | 33 */ |
| 64 abstract class DartCompletionRequest extends CompletionRequest { | 34 abstract class DartCompletionRequest extends CompletionRequest { |
| 65 /** | 35 /** |
| 66 * Return `true` if the compilation [unit] is resolved. | |
| 67 */ | |
| 68 bool get isResolved; | |
| 69 | |
| 70 /** | |
| 71 * Return the completion target. This determines what part of the parse tree | 36 * Return the completion target. This determines what part of the parse tree |
| 72 * will receive the newly inserted text. | 37 * will receive the newly inserted text. |
| 73 */ | 38 */ |
| 74 CompletionTarget get target; | 39 CompletionTarget get target; |
| 75 | 40 |
| 76 /** | 41 /** |
| 77 * Cached information from a prior code completion operation. | 42 * Return a [Future] that completes with a compilation unit in which |
| 43 * all declarations in all scopes containing [target] have been resolved. |
| 44 * The [Future] may return `null` if the unit cannot be resolved |
| 45 * (e.g. unlinked part file). |
| 46 * Any information obtained from [target] prior to calling this method |
| 47 * should be discarded as it may have changed. |
| 78 */ | 48 */ |
| 79 //DartCompletionCache get cache; | 49 Future<CompilationUnit> resolveDeclarationsInScope(); |
| 80 | |
| 81 /** | |
| 82 * Return the compilation unit in which the completion was requested. | |
| 83 */ | |
| 84 CompilationUnit get unit; | |
| 85 | |
| 86 /** | |
| 87 * Information about the types of suggestions that should be included. | |
| 88 */ | |
| 89 //OpType get _optype; | |
| 90 } | 50 } |
| OLD | NEW |