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.dart; | 5 library services.completion.dart; |
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/analysis_server.dart'; | |
11 import 'package:analysis_server/src/provisional/completion/completion_core.dart' | 10 import 'package:analysis_server/src/provisional/completion/completion_core.dart' |
12 show AnalysisRequest, CompletionContributor, CompletionRequest; | 11 show AnalysisRequest, CompletionContributor, CompletionRequest; |
13 import 'package:analysis_server/src/provisional/completion/dart/completion_targe
t.dart'; | 12 import 'package:analysis_server/src/provisional/completion/dart/completion_targe
t.dart'; |
14 import 'package:analysis_server/src/services/completion/arglist_contributor.dart
'; | 13 import 'package:analysis_server/src/services/completion/arglist_contributor.dart
'; |
15 import 'package:analysis_server/src/services/completion/combinator_contributor.d
art'; | 14 import 'package:analysis_server/src/services/completion/combinator_contributor.d
art'; |
16 import 'package:analysis_server/src/services/completion/completion_core.dart'; | 15 import 'package:analysis_server/src/services/completion/completion_core.dart'; |
17 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; | 16 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; |
18 import 'package:analysis_server/src/services/completion/dart/common_usage_sorter
.dart'; | 17 import 'package:analysis_server/src/services/completion/dart/common_usage_sorter
.dart'; |
19 import 'package:analysis_server/src/services/completion/dart/completion_manager.
dart' | 18 import 'package:analysis_server/src/services/completion/dart/completion_manager.
dart' |
20 as newImpl; | 19 as newImpl; |
21 import 'package:analysis_server/src/services/completion/dart/contribution_sorter
.dart'; | 20 import 'package:analysis_server/src/services/completion/dart/contribution_sorter
.dart'; |
22 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; | 21 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; |
23 import 'package:analysis_server/src/services/completion/imported_reference_contr
ibutor.dart'; | 22 import 'package:analysis_server/src/services/completion/imported_reference_contr
ibutor.dart'; |
24 import 'package:analysis_server/src/services/completion/local_reference_contribu
tor.dart'; | 23 import 'package:analysis_server/src/services/completion/local_reference_contribu
tor.dart'; |
25 import 'package:analysis_server/src/services/completion/optype.dart'; | 24 import 'package:analysis_server/src/services/completion/optype.dart'; |
26 import 'package:analysis_server/src/services/completion/prefixed_element_contrib
utor.dart'; | 25 import 'package:analysis_server/src/services/completion/prefixed_element_contrib
utor.dart'; |
27 import 'package:analysis_server/src/services/completion/uri_contributor.dart'; | 26 import 'package:analysis_server/src/services/completion/uri_contributor.dart'; |
28 import 'package:analysis_server/src/services/search/search_engine.dart'; | 27 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 28 import 'package:analyzer/file_system/file_system.dart'; |
29 import 'package:analyzer/src/generated/ast.dart'; | 29 import 'package:analyzer/src/generated/ast.dart'; |
30 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl; | 30 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl; |
31 import 'package:analyzer/src/generated/scanner.dart'; | 31 import 'package:analyzer/src/generated/scanner.dart'; |
32 import 'package:analyzer/src/generated/source.dart'; | 32 import 'package:analyzer/src/generated/source.dart'; |
33 | 33 |
34 export 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart' | 34 export 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart' |
35 show | 35 show |
36 DART_RELEVANCE_COMMON_USAGE, | 36 DART_RELEVANCE_COMMON_USAGE, |
37 DART_RELEVANCE_DEFAULT, | 37 DART_RELEVANCE_DEFAULT, |
38 DART_RELEVANCE_HIGH, | 38 DART_RELEVANCE_HIGH, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 /** | 196 /** |
197 * If there is remaining work to be done, then wait for the unit to be | 197 * If there is remaining work to be done, then wait for the unit to be |
198 * resolved and request that each remaining contributor finish their work. | 198 * resolved and request that each remaining contributor finish their work. |
199 * Return a [Future] that completes when the last notification has been sent. | 199 * Return a [Future] that completes when the last notification has been sent. |
200 */ | 200 */ |
201 Future computeFull( | 201 Future computeFull( |
202 DartCompletionRequest request, | 202 DartCompletionRequest request, |
203 CompletionPerformance performance, | 203 CompletionPerformance performance, |
204 List<DartCompletionContributor> todo) async { | 204 List<DartCompletionContributor> todo) async { |
205 | |
206 // Compute suggestions using the new API | 205 // Compute suggestions using the new API |
207 performance.logStartTime('computeSuggestions'); | 206 performance.logStartTime('computeSuggestions'); |
208 for (CompletionContributor contributor in newContributors) { | 207 for (CompletionContributor contributor in newContributors) { |
209 String contributorTag = 'computeSuggestions - ${contributor.runtimeType}'; | 208 String contributorTag = 'computeSuggestions - ${contributor.runtimeType}'; |
210 performance.logStartTime(contributorTag); | 209 performance.logStartTime(contributorTag); |
211 List<CompletionSuggestion> newSuggestions = | 210 List<CompletionSuggestion> newSuggestions = |
212 await contributor.computeSuggestions(request); | 211 await contributor.computeSuggestions(request); |
213 for (CompletionSuggestion suggestion in newSuggestions) { | 212 for (CompletionSuggestion suggestion in newSuggestions) { |
214 request.addSuggestion(suggestion); | 213 request.addSuggestion(suggestion); |
215 } | 214 } |
216 performance.logElapseTime(contributorTag); | 215 performance.logElapseTime(contributorTag); |
217 } | 216 } |
218 performance.logElapseTime('computeSuggestions'); | 217 performance.logElapseTime('computeSuggestions'); |
219 performance.logStartTime('waitForAnalysis'); | 218 performance.logStartTime('waitForAnalysis'); |
220 | 219 |
221 if (todo.isEmpty) { | 220 if (todo.isEmpty) { |
222 // TODO(danrubel) current sorter requires no additional analysis, | 221 // TODO(danrubel) current sorter requires no additional analysis, |
223 // but need to handle the returned future the same way that futures | 222 // but need to handle the returned future the same way that futures |
224 // returned from contributors are handled once this method is refactored | 223 // returned from contributors are handled once this method is refactored |
225 // to be async. | 224 // to be async. |
226 /* await */ contributionSorter.sort( | 225 /* await */ contributionSorter.sort(request, request.suggestions); |
227 request, request.suggestions); | |
228 // TODO (danrubel) if request is obsolete | 226 // TODO (danrubel) if request is obsolete |
229 // (processAnalysisRequest returns false) | 227 // (processAnalysisRequest returns false) |
230 // then send empty results | 228 // then send empty results |
231 sendResults(request, true); | 229 sendResults(request, true); |
232 } | 230 } |
233 | 231 |
234 // Compute the other suggestions | 232 // Compute the other suggestions |
235 return waitForAnalysis().then((CompilationUnit unit) { | 233 return waitForAnalysis().then((CompilationUnit unit) { |
236 if (controller.isClosed) { | 234 if (controller.isClosed) { |
237 return; | 235 return; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 /** | 366 /** |
369 * The list of suggestions to be sent to the client. | 367 * The list of suggestions to be sent to the client. |
370 */ | 368 */ |
371 final List<CompletionSuggestion> _suggestions = <CompletionSuggestion>[]; | 369 final List<CompletionSuggestion> _suggestions = <CompletionSuggestion>[]; |
372 | 370 |
373 /** | 371 /** |
374 * The set of completions used to prevent duplicates | 372 * The set of completions used to prevent duplicates |
375 */ | 373 */ |
376 final Set<String> _completions = new Set<String>(); | 374 final Set<String> _completions = new Set<String>(); |
377 | 375 |
378 DartCompletionRequest(AnalysisServer server, AnalysisContext context, | 376 DartCompletionRequest( |
379 Source source, int offset, this.cache) | 377 AnalysisContext context, |
380 : super(server, context, source, offset); | 378 ResourceProvider resourceProvider, |
| 379 SearchEngine searchEngine, |
| 380 Source source, |
| 381 int offset, |
| 382 this.cache) |
| 383 : super(context, resourceProvider, searchEngine, source, offset); |
381 | 384 |
382 factory DartCompletionRequest.from( | 385 factory DartCompletionRequest.from( |
383 CompletionRequestImpl request, DartCompletionCache cache) => | 386 CompletionRequestImpl request, DartCompletionCache cache) => |
384 new DartCompletionRequest(request.server, request.context, request.source, | 387 new DartCompletionRequest(request.context, request.resourceProvider, |
385 request.offset, cache); | 388 request.searchEngine, request.source, request.offset, cache); |
386 | 389 |
387 /** | 390 /** |
388 * Return the original text from the [replacementOffset] to the [offset] | 391 * Return the original text from the [replacementOffset] to the [offset] |
389 * that can be used to filter the suggestions on the server side. | 392 * that can be used to filter the suggestions on the server side. |
390 */ | 393 */ |
391 String get filterText { | 394 String get filterText { |
392 return context | 395 return context |
393 .getContents(source) | 396 .getContents(source) |
394 .data | 397 .data |
395 .substring(replacementOffset, offset); | 398 .substring(replacementOffset, offset); |
396 } | 399 } |
397 | 400 |
398 /** | 401 /** |
399 * Information about the types of suggestions that should be included. | 402 * Information about the types of suggestions that should be included. |
400 * The [target] must be set first. | 403 * The [target] must be set first. |
401 */ | 404 */ |
402 OpType get optype { | 405 OpType get optype { |
403 if (_optype == null) { | 406 if (_optype == null) { |
404 _optype = new OpType.forCompletion(target, offset); | 407 _optype = new OpType.forCompletion(target, offset); |
405 } | 408 } |
406 return _optype; | 409 return _optype; |
407 } | 410 } |
408 | 411 |
409 /** | 412 /** |
410 * The search engine for use when building suggestions. | |
411 */ | |
412 SearchEngine get searchEngine => server.searchEngine; | |
413 | |
414 /** | |
415 * The list of suggestions to be sent to the client. | 413 * The list of suggestions to be sent to the client. |
416 */ | 414 */ |
417 Iterable<CompletionSuggestion> get suggestions => _suggestions; | 415 Iterable<CompletionSuggestion> get suggestions => _suggestions; |
418 | 416 |
419 /** | 417 /** |
420 * Add the given suggestion to the list that is returned to the client as long | 418 * Add the given suggestion to the list that is returned to the client as long |
421 * as a suggestion with an identical completion has not already been added. | 419 * as a suggestion with an identical completion has not already been added. |
422 */ | 420 */ |
423 void addSuggestion(CompletionSuggestion suggestion) { | 421 void addSuggestion(CompletionSuggestion suggestion) { |
424 if (_completions.add(suggestion.completion)) { | 422 if (_completions.add(suggestion.completion)) { |
(...skipping 24 matching lines...) Expand all Loading... |
449 parameterNames: suggestion.parameterNames, | 447 parameterNames: suggestion.parameterNames, |
450 parameterTypes: suggestion.parameterTypes, | 448 parameterTypes: suggestion.parameterTypes, |
451 requiredParameterCount: suggestion.requiredParameterCount, | 449 requiredParameterCount: suggestion.requiredParameterCount, |
452 hasNamedParameters: suggestion.hasNamedParameters, | 450 hasNamedParameters: suggestion.hasNamedParameters, |
453 returnType: suggestion.returnType, | 451 returnType: suggestion.returnType, |
454 element: suggestion.element); | 452 element: suggestion.element); |
455 } | 453 } |
456 } | 454 } |
457 } | 455 } |
458 } | 456 } |
OLD | NEW |