| 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/completion/completion_core.dart' | 9 import 'package:analysis_server/completion/completion_core.dart' |
| 10 show CompletionRequest; | 10 show CompletionRequest; |
| 11 import 'package:analysis_server/completion/completion_dart.dart' as newApi; | 11 import 'package:analysis_server/completion/completion_dart.dart' as newApi; |
| 12 import 'package:analysis_server/completion/dart/completion_target.dart'; |
| 12 import 'package:analysis_server/src/analysis_server.dart'; | 13 import 'package:analysis_server/src/analysis_server.dart'; |
| 13 import 'package:analysis_server/src/protocol.dart'; | 14 import 'package:analysis_server/src/protocol.dart'; |
| 14 import 'package:analysis_server/src/services/completion/arglist_contributor.dart
'; | 15 import 'package:analysis_server/src/services/completion/arglist_contributor.dart
'; |
| 15 import 'package:analysis_server/src/services/completion/combinator_contributor.d
art'; | 16 import 'package:analysis_server/src/services/completion/combinator_contributor.d
art'; |
| 16 import 'package:analysis_server/src/services/completion/common_usage_computer.da
rt'; | 17 import 'package:analysis_server/src/services/completion/common_usage_computer.da
rt'; |
| 17 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; | 18 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; |
| 18 import 'package:analysis_server/src/services/completion/completion_target.dart'; | |
| 19 import 'package:analysis_server/src/services/completion/contribution_sorter.dart
'; | 19 import 'package:analysis_server/src/services/completion/contribution_sorter.dart
'; |
| 20 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; | 20 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; |
| 21 import 'package:analysis_server/src/services/completion/imported_reference_contr
ibutor.dart'; | 21 import 'package:analysis_server/src/services/completion/imported_reference_contr
ibutor.dart'; |
| 22 import 'package:analysis_server/src/services/completion/inherited_computer.dart'
; | 22 import 'package:analysis_server/src/services/completion/inherited_computer.dart'
; |
| 23 import 'package:analysis_server/src/services/completion/keyword_contributor.dart
'; | 23 import 'package:analysis_server/src/services/completion/keyword_contributor.dart
'; |
| 24 import 'package:analysis_server/src/services/completion/local_reference_contribu
tor.dart'; | 24 import 'package:analysis_server/src/services/completion/local_reference_contribu
tor.dart'; |
| 25 import 'package:analysis_server/src/services/completion/optype.dart'; | 25 import 'package:analysis_server/src/services/completion/optype.dart'; |
| 26 import 'package:analysis_server/src/services/completion/prefixed_element_contrib
utor.dart'; | 26 import 'package:analysis_server/src/services/completion/prefixed_element_contrib
utor.dart'; |
| 27 import 'package:analysis_server/src/services/completion/uri_contributor.dart'; | 27 import 'package:analysis_server/src/services/completion/uri_contributor.dart'; |
| 28 import 'package:analysis_server/src/services/search/search_engine.dart'; | 28 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 * in the given completion context are resolved. | 69 * in the given completion context are resolved. |
| 70 * Returns `true` if the receiver modified the list of suggestions. | 70 * Returns `true` if the receiver modified the list of suggestions. |
| 71 */ | 71 */ |
| 72 Future<bool> computeFull(DartCompletionRequest request); | 72 Future<bool> computeFull(DartCompletionRequest request); |
| 73 } | 73 } |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Manages code completion for a given Dart file completion request. | 76 * Manages code completion for a given Dart file completion request. |
| 77 */ | 77 */ |
| 78 class DartCompletionManager extends CompletionManager { | 78 class DartCompletionManager extends CompletionManager { |
| 79 | |
| 80 /** | 79 /** |
| 81 * The [defaultContributionSorter] is a long-lived object that isn't allowed | 80 * The [defaultContributionSorter] is a long-lived object that isn't allowed |
| 82 * to maintain state between calls to [ContributionSorter#sort(...)]. | 81 * to maintain state between calls to [ContributionSorter#sort(...)]. |
| 83 */ | 82 */ |
| 84 static ContributionSorter defaultContributionSorter = new CommonUsageComputer(
); | 83 static ContributionSorter defaultContributionSorter = |
| 84 new CommonUsageComputer(); |
| 85 | 85 |
| 86 final SearchEngine searchEngine; | 86 final SearchEngine searchEngine; |
| 87 final DartCompletionCache cache; | 87 final DartCompletionCache cache; |
| 88 List<DartCompletionContributor> contributors; | 88 List<DartCompletionContributor> contributors; |
| 89 ContributionSorter contributionSorter; | 89 ContributionSorter contributionSorter; |
| 90 | 90 |
| 91 DartCompletionManager( | 91 DartCompletionManager( |
| 92 AnalysisContext context, this.searchEngine, Source source, this.cache, | 92 AnalysisContext context, this.searchEngine, Source source, this.cache, |
| 93 [this.contributors, this.contributionSorter]) | 93 [this.contributors, this.contributionSorter]) |
| 94 : super(context, source) { | 94 : super(context, source) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 List<DartCompletionContributor> todo = new List.from(contributors); | 178 List<DartCompletionContributor> todo = new List.from(contributors); |
| 179 todo.removeWhere((DartCompletionContributor c) { | 179 todo.removeWhere((DartCompletionContributor c) { |
| 180 return performance.logElapseTime('computeFast ${c.runtimeType}', () { | 180 return performance.logElapseTime('computeFast ${c.runtimeType}', () { |
| 181 return c.computeFast(request); | 181 return c.computeFast(request); |
| 182 }); | 182 }); |
| 183 }); | 183 }); |
| 184 contributionSorter.sort(request); | 184 contributionSorter.sort( |
| 185 new OldRequestWrapper(request), request.suggestions); |
| 185 sendResults(request, todo.isEmpty); | 186 sendResults(request, todo.isEmpty); |
| 186 return todo; | 187 return todo; |
| 187 }); | 188 }); |
| 188 } | 189 } |
| 189 | 190 |
| 190 /** | 191 /** |
| 191 * If there is remaining work to be done, then wait for the unit to be | 192 * If there is remaining work to be done, then wait for the unit to be |
| 192 * resolved and request that each remaining contributor finish their work. | 193 * resolved and request that each remaining contributor finish their work. |
| 193 * Return a [Future] that completes when the last notification has been sent. | 194 * Return a [Future] that completes when the last notification has been sent. |
| 194 */ | 195 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 212 int count = todo.length; | 213 int count = todo.length; |
| 213 todo.forEach((DartCompletionContributor c) { | 214 todo.forEach((DartCompletionContributor c) { |
| 214 String name = c.runtimeType.toString(); | 215 String name = c.runtimeType.toString(); |
| 215 String completeTag = 'computeFull $name complete'; | 216 String completeTag = 'computeFull $name complete'; |
| 216 performance.logStartTime(completeTag); | 217 performance.logStartTime(completeTag); |
| 217 performance.logElapseTime('computeFull $name', () { | 218 performance.logElapseTime('computeFull $name', () { |
| 218 c.computeFull(request).then((bool changed) { | 219 c.computeFull(request).then((bool changed) { |
| 219 performance.logElapseTime(completeTag); | 220 performance.logElapseTime(completeTag); |
| 220 bool last = --count == 0; | 221 bool last = --count == 0; |
| 221 if (changed || last) { | 222 if (changed || last) { |
| 222 contributionSorter.sort(request); | 223 contributionSorter.sort( |
| 224 new OldRequestWrapper(request), request.suggestions); |
| 223 sendResults(request, last); | 225 sendResults(request, last); |
| 224 } | 226 } |
| 225 }); | 227 }); |
| 226 }); | 228 }); |
| 227 }); | 229 }); |
| 228 }); | 230 }); |
| 229 }); | 231 }); |
| 230 } | 232 } |
| 231 | 233 |
| 232 @override | 234 @override |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 @override | 479 @override |
| 478 int get offset => request.offset; | 480 int get offset => request.offset; |
| 479 | 481 |
| 480 @override | 482 @override |
| 481 ResourceProvider get resourceProvider => request.resourceProvider; | 483 ResourceProvider get resourceProvider => request.resourceProvider; |
| 482 | 484 |
| 483 @override | 485 @override |
| 484 Source get source => request.source; | 486 Source get source => request.source; |
| 485 | 487 |
| 486 @override | 488 @override |
| 489 CompletionTarget get target => request.target; |
| 490 |
| 491 @override |
| 487 CompilationUnit get unit => request.unit; | 492 CompilationUnit get unit => request.unit; |
| 488 | 493 |
| 489 @override | 494 @override |
| 490 String toString() => 'wrapped $request'; | 495 String toString() => 'wrapped $request'; |
| 491 } | 496 } |
| OLD | NEW |