| 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.computer.dart.toplevel; | 5 library services.completion.computer.dart.toplevel; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/protocol_server.dart' | 10 import 'package:analysis_server/src/protocol_server.dart' |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 class ImportedComputer extends DartCompletionComputer { | 23 class ImportedComputer extends DartCompletionComputer { |
| 24 bool shouldWaitForLowPrioritySuggestions; | 24 bool shouldWaitForLowPrioritySuggestions; |
| 25 bool suggestionsComputed; | 25 bool suggestionsComputed; |
| 26 _ImportedSuggestionBuilder builder; | 26 _ImportedSuggestionBuilder builder; |
| 27 | 27 |
| 28 ImportedComputer({this.shouldWaitForLowPrioritySuggestions: false}); | 28 ImportedComputer({this.shouldWaitForLowPrioritySuggestions: false}); |
| 29 | 29 |
| 30 @override | 30 @override |
| 31 bool computeFast(DartCompletionRequest request) { | 31 bool computeFast(DartCompletionRequest request) { |
| 32 OpType optype = request.optype; | 32 OpType optype = request.optype; |
| 33 if (optype.includeTopLevelSuggestions || | 33 if (optype.includeReturnValueSuggestions || |
| 34 optype.includeTypeNameSuggestions || |
| 35 optype.includeVoidReturnSuggestions || |
| 34 optype.includeConstructorSuggestions) { | 36 optype.includeConstructorSuggestions) { |
| 35 builder = new _ImportedSuggestionBuilder(request, | 37 builder = new _ImportedSuggestionBuilder(request, optype); |
| 36 typesOnly: optype.includeOnlyTypeNameSuggestions, | |
| 37 excludeVoidReturn: !optype.includeVoidReturnSuggestions, | |
| 38 constructorsOnly: optype.includeConstructorSuggestions); | |
| 39 builder.shouldWaitForLowPrioritySuggestions = | 38 builder.shouldWaitForLowPrioritySuggestions = |
| 40 shouldWaitForLowPrioritySuggestions; | 39 shouldWaitForLowPrioritySuggestions; |
| 41 // If target is an argument in an argument list | 40 // If target is an argument in an argument list |
| 42 // then suggestions may need to be adjusted | 41 // then suggestions may need to be adjusted |
| 43 suggestionsComputed = builder.computeFast(request.node); | 42 suggestionsComputed = builder.computeFast(request.node); |
| 44 return suggestionsComputed && request.target.argIndex == null; | 43 return suggestionsComputed && request.target.argIndex == null; |
| 45 } | 44 } |
| 46 return true; | 45 return true; |
| 47 } | 46 } |
| 48 | 47 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 72 } | 71 } |
| 73 | 72 |
| 74 /** | 73 /** |
| 75 * [_ImportedSuggestionBuilder] traverses the imports and builds suggestions | 74 * [_ImportedSuggestionBuilder] traverses the imports and builds suggestions |
| 76 * based upon imported elements. | 75 * based upon imported elements. |
| 77 */ | 76 */ |
| 78 class _ImportedSuggestionBuilder extends ElementSuggestionBuilder | 77 class _ImportedSuggestionBuilder extends ElementSuggestionBuilder |
| 79 implements SuggestionBuilder { | 78 implements SuggestionBuilder { |
| 80 bool shouldWaitForLowPrioritySuggestions; | 79 bool shouldWaitForLowPrioritySuggestions; |
| 81 final DartCompletionRequest request; | 80 final DartCompletionRequest request; |
| 82 final bool typesOnly; | 81 final OpType optype; |
| 83 final bool excludeVoidReturn; | |
| 84 final bool constructorsOnly; | |
| 85 DartCompletionCache cache; | 82 DartCompletionCache cache; |
| 86 | 83 |
| 87 _ImportedSuggestionBuilder(this.request, {this.typesOnly: false, | 84 _ImportedSuggestionBuilder(this.request, this.optype) { |
| 88 this.excludeVoidReturn: false, this.constructorsOnly: false}) { | |
| 89 cache = request.cache; | 85 cache = request.cache; |
| 90 } | 86 } |
| 91 | 87 |
| 92 @override | 88 @override |
| 93 CompletionSuggestionKind get kind => CompletionSuggestionKind.INVOCATION; | 89 CompletionSuggestionKind get kind => CompletionSuggestionKind.INVOCATION; |
| 94 | 90 |
| 95 /** | 91 /** |
| 96 * If the needed information is cached, then add suggestions and return `true` | 92 * If the needed information is cached, then add suggestions and return `true` |
| 97 * else return `false` indicating that additional work is necessary. | 93 * else return `false` indicating that additional work is necessary. |
| 98 */ | 94 */ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 _addFilteredSuggestions(filterText, cache.libraryPrefixSuggestions); | 138 _addFilteredSuggestions(filterText, cache.libraryPrefixSuggestions); |
| 143 } | 139 } |
| 144 | 140 |
| 145 /** | 141 /** |
| 146 * Add imported element suggestions. | 142 * Add imported element suggestions. |
| 147 */ | 143 */ |
| 148 void _addElementSuggestions(List<Element> elements, | 144 void _addElementSuggestions(List<Element> elements, |
| 149 {int relevance: DART_RELEVANCE_DEFAULT}) { | 145 {int relevance: DART_RELEVANCE_DEFAULT}) { |
| 150 elements.forEach((Element elem) { | 146 elements.forEach((Element elem) { |
| 151 if (elem is! ClassElement) { | 147 if (elem is! ClassElement) { |
| 152 if (typesOnly) { | 148 if (optype.includeOnlyTypeNameSuggestions) { |
| 153 return; | 149 return; |
| 154 } | 150 } |
| 155 if (elem is ExecutableElement) { | 151 if (elem is ExecutableElement) { |
| 156 DartType returnType = elem.returnType; | 152 DartType returnType = elem.returnType; |
| 157 if (returnType != null && returnType.isVoid) { | 153 if (returnType != null && returnType.isVoid) { |
| 158 if (excludeVoidReturn) { | 154 if (!optype.includeVoidReturnSuggestions) { |
| 159 return; | 155 return; |
| 160 } | 156 } |
| 161 } | 157 } |
| 162 } | 158 } |
| 163 } | 159 } |
| 164 addSuggestion(elem, relevance: relevance); | 160 addSuggestion(elem, relevance: relevance); |
| 165 }); | 161 }); |
| 166 } | 162 } |
| 167 | 163 |
| 168 /** | 164 /** |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 }); | 217 }); |
| 222 } | 218 } |
| 223 } | 219 } |
| 224 } | 220 } |
| 225 } | 221 } |
| 226 | 222 |
| 227 /** | 223 /** |
| 228 * Add suggested based upon imported elements. | 224 * Add suggested based upon imported elements. |
| 229 */ | 225 */ |
| 230 void _addSuggestions(AstNode node) { | 226 void _addSuggestions(AstNode node) { |
| 231 if (constructorsOnly) { | 227 if (optype.includeConstructorSuggestions) { |
| 232 _addConstructorSuggestions(); | 228 _addConstructorSuggestions(); |
| 233 } else { | 229 } |
| 230 if (optype.includeReturnValueSuggestions || |
| 231 optype.includeTypeNameSuggestions || |
| 232 optype.includeVoidReturnSuggestions) { |
| 234 _addInheritedSuggestions(node); | 233 _addInheritedSuggestions(node); |
| 235 _addTopLevelSuggestions(); | 234 _addTopLevelSuggestions(); |
| 236 } | 235 } |
| 237 } | 236 } |
| 238 | 237 |
| 239 /** | 238 /** |
| 240 * Add top level suggestions from the cache. | 239 * Add top level suggestions from the cache. |
| 241 * To reduce the number of suggestions sent to the client, | 240 * To reduce the number of suggestions sent to the client, |
| 242 * filter the suggestions based upon the first character typed. | 241 * filter the suggestions based upon the first character typed. |
| 243 * If no characters are available to use for filtering, | 242 * If no characters are available to use for filtering, |
| 244 * then exclude all low priority suggestions. | 243 * then exclude all low priority suggestions. |
| 245 */ | 244 */ |
| 246 void _addTopLevelSuggestions() { | 245 void _addTopLevelSuggestions() { |
| 247 String filterText = request.filterText; | 246 String filterText = request.filterText; |
| 248 if (filterText.length > 1) { | 247 if (filterText.length > 1) { |
| 249 filterText = filterText.substring(0, 1); | 248 filterText = filterText.substring(0, 1); |
| 250 } | 249 } |
| 251 DartCompletionCache cache = request.cache; | 250 DartCompletionCache cache = request.cache; |
| 252 _addFilteredSuggestions(filterText, cache.importedTypeSuggestions); | 251 if (optype.includeTypeNameSuggestions) { |
| 253 _addFilteredSuggestions(filterText, cache.libraryPrefixSuggestions); | 252 _addFilteredSuggestions(filterText, cache.importedTypeSuggestions); |
| 254 if (!typesOnly) { | 253 _addFilteredSuggestions(filterText, cache.libraryPrefixSuggestions); |
| 254 } |
| 255 if (optype.includeReturnValueSuggestions) { |
| 255 _addFilteredSuggestions(filterText, cache.otherImportedSuggestions); | 256 _addFilteredSuggestions(filterText, cache.otherImportedSuggestions); |
| 256 if (!excludeVoidReturn) { | 257 } |
| 257 _addFilteredSuggestions( | 258 if (optype.includeVoidReturnSuggestions) { |
| 258 filterText, cache.importedVoidReturnSuggestions); | 259 _addFilteredSuggestions(filterText, cache.importedVoidReturnSuggestions); |
| 259 } | |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 } | 262 } |
| OLD | NEW |