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 services.completion.dart.manager; | 5 library services.completion.dart.manager; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:analysis_server/src/provisional/completion/completion_core.dart' | 10 import 'package:analysis_server/src/provisional/completion/completion_core.dart' |
11 show CompletionContributor, CompletionRequest; | 11 show CompletionContributor, CompletionRequest; |
12 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; | 12 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; |
13 import 'package:analysis_server/src/provisional/completion/dart/completion_plugi
n.dart'; | 13 import 'package:analysis_server/src/provisional/completion/dart/completion_plugi
n.dart'; |
14 import 'package:analysis_server/src/provisional/completion/dart/completion_targe
t.dart'; | 14 import 'package:analysis_server/src/provisional/completion/dart/completion_targe
t.dart'; |
15 import 'package:analysis_server/src/services/completion/completion_core.dart'; | 15 import 'package:analysis_server/src/services/completion/completion_core.dart'; |
16 import 'package:analysis_server/src/services/search/search_engine.dart'; | 16 import 'package:analysis_server/src/services/search/search_engine.dart'; |
17 import 'package:analyzer/file_system/file_system.dart'; | 17 import 'package:analyzer/file_system/file_system.dart'; |
18 import 'package:analyzer/src/context/context.dart' | 18 import 'package:analyzer/src/context/context.dart' |
19 show AnalysisFutureHelper, AnalysisContextImpl; | 19 show AnalysisFutureHelper, AnalysisContextImpl; |
20 import 'package:analyzer/src/generated/ast.dart'; | 20 import 'package:analyzer/src/generated/ast.dart'; |
21 import 'package:analyzer/src/generated/element.dart'; | 21 import 'package:analyzer/src/generated/element.dart'; |
22 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl; | 22 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl; |
23 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
24 import 'package:analyzer/src/task/dart.dart'; | 24 import 'package:analyzer/src/task/dart.dart'; |
25 import 'package:analyzer/task/dart.dart'; | 25 import 'package:analyzer/task/dart.dart'; |
| 26 import 'package:analysis_server/src/services/completion/optype.dart'; |
26 | 27 |
27 /** | 28 /** |
28 * [DartCompletionManager] determines if a completion request is Dart specific | 29 * [DartCompletionManager] determines if a completion request is Dart specific |
29 * and forwards those requests to all [DartCompletionContributor]s. | 30 * and forwards those requests to all [DartCompletionContributor]s. |
30 */ | 31 */ |
31 class DartCompletionManager implements CompletionContributor { | 32 class DartCompletionManager implements CompletionContributor { |
32 @override | 33 @override |
33 Future<List<CompletionSuggestion>> computeSuggestions( | 34 Future<List<CompletionSuggestion>> computeSuggestions( |
34 CompletionRequest request) async { | 35 CompletionRequest request) async { |
35 if (!AnalysisEngine.isDartFileName(request.source.shortName)) { | 36 if (!AnalysisEngine.isDartFileName(request.source.shortName)) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 * The [DartType] for Object in dart:core | 105 * The [DartType] for Object in dart:core |
105 */ | 106 */ |
106 InterfaceType _objectType; | 107 InterfaceType _objectType; |
107 | 108 |
108 @override | 109 @override |
109 Expression dotTarget; | 110 Expression dotTarget; |
110 | 111 |
111 @override | 112 @override |
112 Source librarySource; | 113 Source librarySource; |
113 | 114 |
| 115 OpType _opType; |
| 116 |
114 @override | 117 @override |
115 CompletionTarget target; | 118 CompletionTarget target; |
116 | 119 |
117 @override | 120 @override |
| 121 bool get includeIdentifiers { |
| 122 if (_opType == null) { |
| 123 _opType = new OpType.forCompletion(target, offset); |
| 124 } |
| 125 return !_opType.isPrefixed && |
| 126 (_opType.includeReturnValueSuggestions || |
| 127 _opType.includeTypeNameSuggestions || |
| 128 _opType.includeVoidReturnSuggestions || |
| 129 _opType.includeConstructorSuggestions); |
| 130 } |
| 131 |
| 132 @override |
118 LibraryElement get libraryElement { | 133 LibraryElement get libraryElement { |
119 //TODO(danrubel) build the library element rather than all the declarations | 134 //TODO(danrubel) build the library element rather than all the declarations |
120 CompilationUnit unit = target.unit; | 135 CompilationUnit unit = target.unit; |
121 if (unit != null) { | 136 if (unit != null) { |
122 CompilationUnitElement elem = unit.element; | 137 CompilationUnitElement elem = unit.element; |
123 if (elem != null) { | 138 if (elem != null) { |
124 return elem.library; | 139 return elem.library; |
125 } | 140 } |
126 } | 141 } |
127 return null; | 142 return null; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 198 } |
184 | 199 |
185 // Recompute the target for the newly resolved unit | 200 // Recompute the target for the newly resolved unit |
186 _updateTargets(resolvedUnit); | 201 _updateTargets(resolvedUnit); |
187 } | 202 } |
188 | 203 |
189 /** | 204 /** |
190 * Update the completion [target] and [dotTarget] based on the given [unit]. | 205 * Update the completion [target] and [dotTarget] based on the given [unit]. |
191 */ | 206 */ |
192 void _updateTargets(CompilationUnit unit) { | 207 void _updateTargets(CompilationUnit unit) { |
| 208 _opType = null; |
193 dotTarget = null; | 209 dotTarget = null; |
194 target = new CompletionTarget.forOffset(unit, offset); | 210 target = new CompletionTarget.forOffset(unit, offset); |
195 AstNode node = target.containingNode; | 211 AstNode node = target.containingNode; |
196 if (node is MethodInvocation) { | 212 if (node is MethodInvocation) { |
197 if (identical(node.methodName, target.entity)) { | 213 if (identical(node.methodName, target.entity)) { |
198 dotTarget = node.realTarget; | 214 dotTarget = node.realTarget; |
199 } else if (node.isCascaded && node.operator.offset + 1 == target.offset) { | 215 } else if (node.isCascaded && node.operator.offset + 1 == target.offset) { |
200 dotTarget = node.realTarget; | 216 dotTarget = node.realTarget; |
201 } | 217 } |
202 } | 218 } |
203 if (node is PropertyAccess) { | 219 if (node is PropertyAccess) { |
204 if (identical(node.propertyName, target.entity)) { | 220 if (identical(node.propertyName, target.entity)) { |
205 dotTarget = node.realTarget; | 221 dotTarget = node.realTarget; |
206 } else if (node.isCascaded && node.operator.offset + 1 == target.offset) { | 222 } else if (node.isCascaded && node.operator.offset + 1 == target.offset) { |
207 dotTarget = node.realTarget; | 223 dotTarget = node.realTarget; |
208 } | 224 } |
209 } | 225 } |
210 if (node is PrefixedIdentifier) { | 226 if (node is PrefixedIdentifier) { |
211 if (identical(node.identifier, target.entity)) { | 227 if (identical(node.identifier, target.entity)) { |
212 dotTarget = node.prefix; | 228 dotTarget = node.prefix; |
213 } | 229 } |
214 } | 230 } |
215 } | 231 } |
216 } | 232 } |
OLD | NEW |