| 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/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/completion/arglist_computer.dart'; | 10 import 'package:analysis_server/src/services/completion/arglist_computer.dart'; |
| 11 import 'package:analysis_server/src/services/completion/combinator_computer.dart
'; | 11 import 'package:analysis_server/src/services/completion/combinator_computer.dart
'; |
| 12 import 'package:analysis_server/src/services/completion/common_usage_computer.da
rt'; |
| 12 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; | 13 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; |
| 13 import 'package:analysis_server/src/services/completion/completion_target.dart'; | 14 import 'package:analysis_server/src/services/completion/completion_target.dart'; |
| 14 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; | 15 import 'package:analysis_server/src/services/completion/dart_completion_cache.da
rt'; |
| 15 import 'package:analysis_server/src/services/completion/imported_computer.dart'; | 16 import 'package:analysis_server/src/services/completion/imported_computer.dart'; |
| 16 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; | 17 import 'package:analysis_server/src/services/completion/invocation_computer.dart
'; |
| 17 import 'package:analysis_server/src/services/completion/keyword_computer.dart'; | 18 import 'package:analysis_server/src/services/completion/keyword_computer.dart'; |
| 18 import 'package:analysis_server/src/services/completion/local_computer.dart'; | 19 import 'package:analysis_server/src/services/completion/local_computer.dart'; |
| 19 import 'package:analysis_server/src/services/completion/optype.dart'; | 20 import 'package:analysis_server/src/services/completion/optype.dart'; |
| 20 import 'package:analysis_server/src/services/search/search_engine.dart'; | 21 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 21 import 'package:analyzer/src/generated/ast.dart'; | 22 import 'package:analyzer/src/generated/ast.dart'; |
| 22 import 'package:analyzer/src/generated/engine.dart'; | 23 import 'package:analyzer/src/generated/engine.dart'; |
| 24 import 'package:analyzer/src/generated/scanner.dart'; |
| 23 import 'package:analyzer/src/generated/source.dart'; | 25 import 'package:analyzer/src/generated/source.dart'; |
| 24 import 'package:analyzer/src/generated/scanner.dart'; | |
| 25 | 26 |
| 26 // Relevance highest to lowest | 27 const int DART_RELEVANCE_COMMON_USAGE = 1200; |
| 28 const int DART_RELEVANCE_DEFAULT = 1000; |
| 27 const int DART_RELEVANCE_HIGH = 2000; | 29 const int DART_RELEVANCE_HIGH = 2000; |
| 30 const int DART_RELEVANCE_INHERITED_ACCESSOR = 1057; |
| 31 const int DART_RELEVANCE_INHERITED_FIELD = 1058; |
| 32 const int DART_RELEVANCE_INHERITED_METHOD = 1057; |
| 33 const int DART_RELEVANCE_KEYWORD = 1055; |
| 34 const int DART_RELEVANCE_LOCAL_ACCESSOR = 1057; |
| 35 const int DART_RELEVANCE_LOCAL_FIELD = 1058; |
| 36 const int DART_RELEVANCE_LOCAL_FUNCTION = 1056; |
| 37 const int DART_RELEVANCE_LOCAL_METHOD = 1057; |
| 38 const int DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE = 1056; |
| 28 const int DART_RELEVANCE_LOCAL_VARIABLE = 1059; | 39 const int DART_RELEVANCE_LOCAL_VARIABLE = 1059; |
| 40 const int DART_RELEVANCE_LOW = 500; |
| 29 const int DART_RELEVANCE_PARAMETER = 1059; | 41 const int DART_RELEVANCE_PARAMETER = 1059; |
| 30 const int DART_RELEVANCE_INHERITED_FIELD = 1058; | |
| 31 const int DART_RELEVANCE_LOCAL_FIELD = 1058; | |
| 32 const int DART_RELEVANCE_INHERITED_ACCESSOR = 1057; | |
| 33 const int DART_RELEVANCE_INHERITED_METHOD = 1057; | |
| 34 const int DART_RELEVANCE_LOCAL_ACCESSOR = 1057; | |
| 35 const int DART_RELEVANCE_LOCAL_METHOD = 1057; | |
| 36 const int DART_RELEVANCE_LOCAL_FUNCTION = 1056; | |
| 37 const int DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE = 1056; | |
| 38 const int DART_RELEVANCE_KEYWORD = 1055; | |
| 39 const int DART_RELEVANCE_DEFAULT = 1000; | |
| 40 const int DART_RELEVANCE_LOW = 500; | |
| 41 | 42 |
| 42 /** | 43 /** |
| 43 * The base class for computing code completion suggestions. | 44 * The base class for computing code completion suggestions. |
| 44 */ | 45 */ |
| 45 abstract class DartCompletionComputer { | 46 abstract class DartCompletionComputer { |
| 46 /** | 47 /** |
| 47 * Computes the initial set of [CompletionSuggestion]s based on | 48 * Computes the initial set of [CompletionSuggestion]s based on |
| 48 * the given completion context. The compilation unit and completion node | 49 * the given completion context. The compilation unit and completion node |
| 49 * in the given completion context may not be resolved. | 50 * in the given completion context may not be resolved. |
| 50 * This method should execute quickly and not block waiting for any analysis. | 51 * This method should execute quickly and not block waiting for any analysis. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 62 Future<bool> computeFull(DartCompletionRequest request); | 63 Future<bool> computeFull(DartCompletionRequest request); |
| 63 } | 64 } |
| 64 | 65 |
| 65 /** | 66 /** |
| 66 * Manages code completion for a given Dart file completion request. | 67 * Manages code completion for a given Dart file completion request. |
| 67 */ | 68 */ |
| 68 class DartCompletionManager extends CompletionManager { | 69 class DartCompletionManager extends CompletionManager { |
| 69 final SearchEngine searchEngine; | 70 final SearchEngine searchEngine; |
| 70 final DartCompletionCache cache; | 71 final DartCompletionCache cache; |
| 71 List<DartCompletionComputer> computers; | 72 List<DartCompletionComputer> computers; |
| 73 CommonUsageComputer commonUsageComputer; |
| 72 | 74 |
| 73 DartCompletionManager(AnalysisContext context, this.searchEngine, | 75 DartCompletionManager(AnalysisContext context, this.searchEngine, |
| 74 Source source, this.cache, [this.computers]) | 76 Source source, this.cache, [this.computers, this.commonUsageComputer]) |
| 75 : super(context, source) { | 77 : super(context, source) { |
| 76 if (computers == null) { | 78 if (computers == null) { |
| 77 computers = [ | 79 computers = [ |
| 78 new KeywordComputer(), | 80 new KeywordComputer(), |
| 79 new LocalComputer(), | 81 new LocalComputer(), |
| 80 new ArgListComputer(), | 82 new ArgListComputer(), |
| 81 new CombinatorComputer(), | 83 new CombinatorComputer(), |
| 82 new ImportedComputer(), | 84 new ImportedComputer(), |
| 83 new InvocationComputer()]; | 85 new InvocationComputer()]; |
| 84 } | 86 } |
| 87 if (commonUsageComputer == null) { |
| 88 commonUsageComputer = new CommonUsageComputer(); |
| 89 } |
| 85 } | 90 } |
| 86 | 91 |
| 87 /** | 92 /** |
| 88 * Create a new initialized Dart source completion manager | 93 * Create a new initialized Dart source completion manager |
| 89 */ | 94 */ |
| 90 factory DartCompletionManager.create(AnalysisContext context, | 95 factory DartCompletionManager.create(AnalysisContext context, |
| 91 SearchEngine searchEngine, Source source) { | 96 SearchEngine searchEngine, Source source) { |
| 92 return new DartCompletionManager( | 97 return new DartCompletionManager( |
| 93 context, | 98 context, |
| 94 searchEngine, | 99 searchEngine, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 139 } |
| 135 | 140 |
| 136 List<DartCompletionComputer> todo = new List.from(computers); | 141 List<DartCompletionComputer> todo = new List.from(computers); |
| 137 todo.removeWhere((DartCompletionComputer c) { | 142 todo.removeWhere((DartCompletionComputer c) { |
| 138 return request.performance.logElapseTime( | 143 return request.performance.logElapseTime( |
| 139 'computeFast ${c.runtimeType}', | 144 'computeFast ${c.runtimeType}', |
| 140 () { | 145 () { |
| 141 return c.computeFast(request); | 146 return c.computeFast(request); |
| 142 }); | 147 }); |
| 143 }); | 148 }); |
| 149 commonUsageComputer.computeFast(request); |
| 144 sendResults(request, todo.isEmpty); | 150 sendResults(request, todo.isEmpty); |
| 145 return todo; | 151 return todo; |
| 146 }); | 152 }); |
| 147 } | 153 } |
| 148 | 154 |
| 149 /** | 155 /** |
| 150 * If there is remaining work to be done, then wait for the unit to be | 156 * If there is remaining work to be done, then wait for the unit to be |
| 151 * resolved and request that each remaining computer finish their work. | 157 * resolved and request that each remaining computer finish their work. |
| 152 * Return a [Future] that completes when the last notification has been sent. | 158 * Return a [Future] that completes when the last notification has been sent. |
| 153 */ | 159 */ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 172 int count = todo.length; | 178 int count = todo.length; |
| 173 todo.forEach((DartCompletionComputer c) { | 179 todo.forEach((DartCompletionComputer c) { |
| 174 String name = c.runtimeType.toString(); | 180 String name = c.runtimeType.toString(); |
| 175 String completeTag = 'computeFull $name complete'; | 181 String completeTag = 'computeFull $name complete'; |
| 176 request.performance.logStartTime(completeTag); | 182 request.performance.logStartTime(completeTag); |
| 177 request.performance.logElapseTime('computeFull $name', () { | 183 request.performance.logElapseTime('computeFull $name', () { |
| 178 c.computeFull(request).then((bool changed) { | 184 c.computeFull(request).then((bool changed) { |
| 179 request.performance.logElapseTime(completeTag); | 185 request.performance.logElapseTime(completeTag); |
| 180 bool last = --count == 0; | 186 bool last = --count == 0; |
| 181 if (changed || last) { | 187 if (changed || last) { |
| 188 commonUsageComputer.computeFull(request); |
| 182 sendResults(request, last); | 189 sendResults(request, last); |
| 183 } | 190 } |
| 184 }); | 191 }); |
| 185 }); | 192 }); |
| 186 }); | 193 }); |
| 187 }); | 194 }); |
| 188 }); | 195 }); |
| 189 } | 196 } |
| 190 | 197 |
| 191 @override | 198 @override |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 * Information about the types of suggestions that should be included. | 343 * Information about the types of suggestions that should be included. |
| 337 * The [target] must be set first. | 344 * The [target] must be set first. |
| 338 */ | 345 */ |
| 339 OpType get optype { | 346 OpType get optype { |
| 340 if (_optype == null) { | 347 if (_optype == null) { |
| 341 _optype = new OpType.forCompletion(target, offset); | 348 _optype = new OpType.forCompletion(target, offset); |
| 342 } | 349 } |
| 343 return _optype; | 350 return _optype; |
| 344 } | 351 } |
| 345 } | 352 } |
| OLD | NEW |