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.completion.completion_dart; | 5 library analysis_server.completion.completion_dart; |
6 | 6 |
7 import 'package:analysis_server/completion/completion_core.dart'; | 7 import 'package:analysis_server/completion/completion_core.dart'; |
| 8 import 'package:analysis_server/src/services/completion/completion_dart.dart'; |
8 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; |
9 | 12 |
10 /** | 13 /** |
11 * An object used to produce completions for a specific error within a Dart | 14 * An object used to produce completions for a specific error within a Dart |
12 * file. Completion contributors are long-lived objects and must not retain any | 15 * file. Completion contributors are long-lived objects and must not retain any |
13 * state between invocations of [computeSuggestions]. | 16 * state between invocations of [computeSuggestions]. |
14 * | 17 * |
15 * Clients are expected to subtype this class when implementing plugins. | 18 * Clients are expected to subtype this class when implementing plugins. |
16 */ | 19 */ |
17 abstract class DartCompletionContributor extends CompletionContributor { | 20 abstract class DartCompletionContributor extends CompletionContributor { |
18 @override | 21 @override |
19 CompletionResult computeSuggestions(CompletionRequest request) { | 22 CompletionResult computeSuggestions(CompletionRequest request) { |
20 // TODO(brianwilkerson) Implement this by getting the information required | 23 if (request is DartCompletionRequest) { |
21 // to create a DartCompletionRequest and calling: | 24 return internalComputeSuggestions(request); |
22 // return internalComputeSuggestions(dartRequest); | 25 } |
23 return null; | 26 AnalysisContext context = request.context; |
| 27 Source source = request.source; |
| 28 List<Source> libraries = context.getLibrariesContaining(source); |
| 29 if (libraries.length < 1) { |
| 30 return null; |
| 31 } |
| 32 CompilationUnit unit = |
| 33 context.getResolvedCompilationUnit2(source, libraries[0]); |
| 34 bool isResolved = true; |
| 35 if (unit == null) { |
| 36 // TODO(brianwilkerson) Implement a method for getting a parsed |
| 37 // compilation unit without parsing the unit if it hasn't been parsed. |
| 38 // unit = context.getParsedCompilationUnit(source); |
| 39 if (unit == null) { |
| 40 return null; |
| 41 } |
| 42 isResolved = false; |
| 43 } |
| 44 DartCompletionRequest dartRequest = |
| 45 new DartCompletionRequestImpl(request, unit, isResolved); |
| 46 return internalComputeSuggestions(dartRequest); |
24 } | 47 } |
25 | 48 |
26 /** | 49 /** |
27 * Compute a list of completion suggestions based on the given completion | 50 * Compute a list of completion suggestions based on the given completion |
28 * [request] and return a result that includes those suggestions. This method | 51 * [request] and return a result that includes those suggestions. This method |
29 * is called after specific phases of analysis until the contributor indicates | 52 * is called after specific phases of analysis until the contributor indicates |
30 * computation is complete by setting [CompletionResult.isLast] to `true`. | 53 * computation is complete by setting [CompletionResult.isLast] to `true`. |
31 */ | 54 */ |
32 CompletionResult internalComputeSuggestions(DartCompletionRequest request); | 55 CompletionResult internalComputeSuggestions(DartCompletionRequest request); |
33 } | 56 } |
34 | 57 |
35 /** | 58 /** |
36 * The information about a requested list of completions within a Dart file. | 59 * The information about a requested list of completions within a Dart file. |
37 */ | 60 */ |
38 abstract class DartCompletionRequest extends CompletionRequest { | 61 abstract class DartCompletionRequest extends CompletionRequest { |
39 /** | 62 /** |
40 * Return `true` if the compilation [unit] is resolved. | 63 * Return `true` if the compilation [unit] is resolved. |
41 */ | 64 */ |
42 bool get isResolved; | 65 bool get isResolved; |
43 | 66 |
44 /** | 67 /** |
45 * The compilation unit in which the completion was requested. | 68 * Return the compilation unit in which the completion was requested. |
46 */ | 69 */ |
47 CompilationUnit get unit; | 70 CompilationUnit get unit; |
48 | 71 |
49 /** | 72 /** |
50 * Cached information from a prior code completion operation. | 73 * Cached information from a prior code completion operation. |
51 */ | 74 */ |
52 //DartCompletionCache get cache; | 75 //DartCompletionCache get cache; |
53 | 76 |
54 /** | 77 /** |
55 * The completion target. This determines what part of the parse tree | 78 * Return the completion target. This determines what part of the parse tree |
56 * will receive the newly inserted text. | 79 * will receive the newly inserted text. |
57 */ | 80 */ |
58 //CompletionTarget get target; | 81 //CompletionTarget get target; |
59 | 82 |
60 /** | 83 /** |
61 * Information about the types of suggestions that should be included. | 84 * Information about the types of suggestions that should be included. |
62 */ | 85 */ |
63 //OpType get _optype; | 86 //OpType get _optype; |
64 } | 87 } |
OLD | NEW |