| 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/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
| 12 import 'package:analysis_server/src/protocol.dart'; | 12 import 'package:analysis_server/src/protocol.dart'; |
| 13 import 'package:analysis_server/src/services/completion/arglist_contributor.dart
'; | 13 import 'package:analysis_server/src/services/completion/arglist_contributor.dart
'; |
| 14 import 'package:analysis_server/src/services/completion/combinator_contributor.d
art'; | 14 import 'package:analysis_server/src/services/completion/combinator_contributor.d
art'; |
| 15 import 'package:analysis_server/src/services/completion/common_usage_computer.da
rt'; | 15 import 'package:analysis_server/src/services/completion/common_usage_computer.da
rt'; |
| 16 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; | 16 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; |
| 17 import 'package:analysis_server/src/services/completion/completion_target.dart'; | 17 import 'package:analysis_server/src/services/completion/completion_target.dart'; |
| 18 import 'package:analysis_server/src/services/completion/contribution_sorter.dart
'; |
| 18 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; | 19 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; |
| 19 import 'package:analysis_server/src/services/completion/uri_contributor.dart'; | |
| 20 import 'package:analysis_server/src/services/completion/imported_reference_contr
ibutor.dart'; | 20 import 'package:analysis_server/src/services/completion/imported_reference_contr
ibutor.dart'; |
| 21 import 'package:analysis_server/src/services/completion/keyword_contributor.dart
'; | 21 import 'package:analysis_server/src/services/completion/keyword_contributor.dart
'; |
| 22 import 'package:analysis_server/src/services/completion/local_reference_contribu
tor.dart'; | 22 import 'package:analysis_server/src/services/completion/local_reference_contribu
tor.dart'; |
| 23 import 'package:analysis_server/src/services/completion/optype.dart'; | 23 import 'package:analysis_server/src/services/completion/optype.dart'; |
| 24 import 'package:analysis_server/src/services/completion/prefixed_element_contrib
utor.dart'; | 24 import 'package:analysis_server/src/services/completion/prefixed_element_contrib
utor.dart'; |
| 25 import 'package:analysis_server/src/services/completion/uri_contributor.dart'; |
| 25 import 'package:analysis_server/src/services/search/search_engine.dart'; | 26 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 26 import 'package:analyzer/src/generated/ast.dart'; | 27 import 'package:analyzer/src/generated/ast.dart'; |
| 27 import 'package:analyzer/src/generated/engine.dart'; | 28 import 'package:analyzer/src/generated/engine.dart'; |
| 28 import 'package:analyzer/src/generated/scanner.dart'; | 29 import 'package:analyzer/src/generated/scanner.dart'; |
| 29 import 'package:analyzer/src/generated/source.dart'; | 30 import 'package:analyzer/src/generated/source.dart'; |
| 30 | 31 |
| 31 const int DART_RELEVANCE_COMMON_USAGE = 1200; | 32 const int DART_RELEVANCE_COMMON_USAGE = 1200; |
| 32 const int DART_RELEVANCE_DEFAULT = 1000; | 33 const int DART_RELEVANCE_DEFAULT = 1000; |
| 33 const int DART_RELEVANCE_HIGH = 2000; | 34 const int DART_RELEVANCE_HIGH = 2000; |
| 34 const int DART_RELEVANCE_INHERITED_ACCESSOR = 1057; | 35 const int DART_RELEVANCE_INHERITED_ACCESSOR = 1057; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 65 * in the given completion context are resolved. | 66 * in the given completion context are resolved. |
| 66 * Returns `true` if the receiver modified the list of suggestions. | 67 * Returns `true` if the receiver modified the list of suggestions. |
| 67 */ | 68 */ |
| 68 Future<bool> computeFull(DartCompletionRequest request); | 69 Future<bool> computeFull(DartCompletionRequest request); |
| 69 } | 70 } |
| 70 | 71 |
| 71 /** | 72 /** |
| 72 * Manages code completion for a given Dart file completion request. | 73 * Manages code completion for a given Dart file completion request. |
| 73 */ | 74 */ |
| 74 class DartCompletionManager extends CompletionManager { | 75 class DartCompletionManager extends CompletionManager { |
| 76 |
| 77 /** |
| 78 * The [defaultContributionSorter] is a long-lived object that isn't allowed |
| 79 * to maintain state between calls to [ContributionSorter#sort(...)]. |
| 80 */ |
| 81 static ContributionSorter defaultContributionSorter = new CommonUsageComputer(
); |
| 82 |
| 75 final SearchEngine searchEngine; | 83 final SearchEngine searchEngine; |
| 76 final DartCompletionCache cache; | 84 final DartCompletionCache cache; |
| 77 List<DartCompletionContributor> contributors; | 85 List<DartCompletionContributor> contributors; |
| 78 CommonUsageComputer commonUsageComputer; | 86 ContributionSorter contributionSorter; |
| 79 | 87 |
| 80 DartCompletionManager( | 88 DartCompletionManager( |
| 81 AnalysisContext context, this.searchEngine, Source source, this.cache, | 89 AnalysisContext context, this.searchEngine, Source source, this.cache, |
| 82 [this.contributors, this.commonUsageComputer]) | 90 [this.contributors, this.contributionSorter]) |
| 83 : super(context, source) { | 91 : super(context, source) { |
| 84 if (contributors == null) { | 92 if (contributors == null) { |
| 85 contributors = [ | 93 contributors = [ |
| 86 // LocalReferenceContributor before ImportedReferenceContributor | 94 // LocalReferenceContributor before ImportedReferenceContributor |
| 87 // because local suggestions take precedence | 95 // because local suggestions take precedence |
| 88 // and can hide other suggestions with the same name | 96 // and can hide other suggestions with the same name |
| 89 new LocalReferenceContributor(), | 97 new LocalReferenceContributor(), |
| 90 new ImportedReferenceContributor(), | 98 new ImportedReferenceContributor(), |
| 91 new KeywordContributor(), | 99 new KeywordContributor(), |
| 92 new ArgListContributor(), | 100 new ArgListContributor(), |
| 93 new CombinatorContributor(), | 101 new CombinatorContributor(), |
| 94 new PrefixedElementContributor(), | 102 new PrefixedElementContributor(), |
| 95 new UriContributor(), | 103 new UriContributor(), |
| 96 ]; | 104 ]; |
| 97 } | 105 } |
| 98 if (commonUsageComputer == null) { | 106 if (contributionSorter == null) { |
| 99 commonUsageComputer = new CommonUsageComputer(); | 107 contributionSorter = defaultContributionSorter; |
| 100 } | 108 } |
| 101 } | 109 } |
| 102 | 110 |
| 103 /** | 111 /** |
| 104 * Create a new initialized Dart source completion manager | 112 * Create a new initialized Dart source completion manager |
| 105 */ | 113 */ |
| 106 factory DartCompletionManager.create( | 114 factory DartCompletionManager.create( |
| 107 AnalysisContext context, SearchEngine searchEngine, Source source) { | 115 AnalysisContext context, SearchEngine searchEngine, Source source) { |
| 108 return new DartCompletionManager(context, searchEngine, source, | 116 return new DartCompletionManager(context, searchEngine, source, |
| 109 new DartCompletionCache(context, source)); | 117 new DartCompletionCache(context, source)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 168 } |
| 161 } | 169 } |
| 162 } | 170 } |
| 163 | 171 |
| 164 List<DartCompletionContributor> todo = new List.from(contributors); | 172 List<DartCompletionContributor> todo = new List.from(contributors); |
| 165 todo.removeWhere((DartCompletionContributor c) { | 173 todo.removeWhere((DartCompletionContributor c) { |
| 166 return performance.logElapseTime('computeFast ${c.runtimeType}', () { | 174 return performance.logElapseTime('computeFast ${c.runtimeType}', () { |
| 167 return c.computeFast(request); | 175 return c.computeFast(request); |
| 168 }); | 176 }); |
| 169 }); | 177 }); |
| 170 commonUsageComputer.computeFast(request); | 178 contributionSorter.sort(request); |
| 171 sendResults(request, todo.isEmpty); | 179 sendResults(request, todo.isEmpty); |
| 172 return todo; | 180 return todo; |
| 173 }); | 181 }); |
| 174 } | 182 } |
| 175 | 183 |
| 176 /** | 184 /** |
| 177 * If there is remaining work to be done, then wait for the unit to be | 185 * If there is remaining work to be done, then wait for the unit to be |
| 178 * resolved and request that each remaining contributor finish their work. | 186 * resolved and request that each remaining contributor finish their work. |
| 179 * Return a [Future] that completes when the last notification has been sent. | 187 * Return a [Future] that completes when the last notification has been sent. |
| 180 */ | 188 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 198 int count = todo.length; | 206 int count = todo.length; |
| 199 todo.forEach((DartCompletionContributor c) { | 207 todo.forEach((DartCompletionContributor c) { |
| 200 String name = c.runtimeType.toString(); | 208 String name = c.runtimeType.toString(); |
| 201 String completeTag = 'computeFull $name complete'; | 209 String completeTag = 'computeFull $name complete'; |
| 202 performance.logStartTime(completeTag); | 210 performance.logStartTime(completeTag); |
| 203 performance.logElapseTime('computeFull $name', () { | 211 performance.logElapseTime('computeFull $name', () { |
| 204 c.computeFull(request).then((bool changed) { | 212 c.computeFull(request).then((bool changed) { |
| 205 performance.logElapseTime(completeTag); | 213 performance.logElapseTime(completeTag); |
| 206 bool last = --count == 0; | 214 bool last = --count == 0; |
| 207 if (changed || last) { | 215 if (changed || last) { |
| 208 commonUsageComputer.computeFull(request); | 216 contributionSorter.sort(request); |
| 209 sendResults(request, last); | 217 sendResults(request, last); |
| 210 } | 218 } |
| 211 }); | 219 }); |
| 212 }); | 220 }); |
| 213 }); | 221 }); |
| 214 }); | 222 }); |
| 215 }); | 223 }); |
| 216 } | 224 } |
| 217 | 225 |
| 218 @override | 226 @override |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 parameterNames: suggestion.parameterNames, | 400 parameterNames: suggestion.parameterNames, |
| 393 parameterTypes: suggestion.parameterTypes, | 401 parameterTypes: suggestion.parameterTypes, |
| 394 requiredParameterCount: suggestion.requiredParameterCount, | 402 requiredParameterCount: suggestion.requiredParameterCount, |
| 395 hasNamedParameters: suggestion.hasNamedParameters, | 403 hasNamedParameters: suggestion.hasNamedParameters, |
| 396 returnType: suggestion.returnType, | 404 returnType: suggestion.returnType, |
| 397 element: suggestion.element); | 405 element: suggestion.element); |
| 398 } | 406 } |
| 399 } | 407 } |
| 400 } | 408 } |
| 401 } | 409 } |
| OLD | NEW |