| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 /** | 73 /** |
| 74 * [_ImportedSuggestionBuilder] traverses the imports and builds suggestions | 74 * [_ImportedSuggestionBuilder] traverses the imports and builds suggestions |
| 75 * based upon imported elements. | 75 * based upon imported elements. |
| 76 */ | 76 */ |
| 77 class _ImportedSuggestionBuilder extends ElementSuggestionBuilder | 77 class _ImportedSuggestionBuilder extends ElementSuggestionBuilder |
| 78 implements SuggestionBuilder { | 78 implements SuggestionBuilder { |
| 79 bool shouldWaitForLowPrioritySuggestions; | 79 bool shouldWaitForLowPrioritySuggestions; |
| 80 final DartCompletionRequest request; | 80 final DartCompletionRequest request; |
| 81 final OpType optype; | 81 final OpType optype; |
| 82 DartCompletionCache cache; | 82 DartCompletionCache cache; |
| 83 HashSet<String> completions; |
| 83 | 84 |
| 84 _ImportedSuggestionBuilder(this.request, this.optype) { | 85 _ImportedSuggestionBuilder(this.request, this.optype) { |
| 85 cache = request.cache; | 86 cache = request.cache; |
| 87 completions = new HashSet<String>(); |
| 88 for (CompletionSuggestion suggestion in request.suggestions) { |
| 89 completions.add(suggestion.completion); |
| 90 } |
| 86 } | 91 } |
| 87 | 92 |
| 88 @override | 93 @override |
| 89 CompletionSuggestionKind get kind => CompletionSuggestionKind.INVOCATION; | 94 CompletionSuggestionKind get kind => CompletionSuggestionKind.INVOCATION; |
| 90 | 95 |
| 91 /** | 96 /** |
| 92 * If the needed information is cached, then add suggestions and return `true` | 97 * If the needed information is cached, then add suggestions and return `true` |
| 93 * else return `false` indicating that additional work is necessary. | 98 * else return `false` indicating that additional work is necessary. |
| 94 */ | 99 */ |
| 95 bool computeFast(AstNode node) { | 100 bool computeFast(AstNode node) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 168 |
| 164 /** | 169 /** |
| 165 * Add suggestions which start with the given text. | 170 * Add suggestions which start with the given text. |
| 166 */ | 171 */ |
| 167 _addFilteredSuggestions( | 172 _addFilteredSuggestions( |
| 168 String filterText, List<CompletionSuggestion> unfiltered) { | 173 String filterText, List<CompletionSuggestion> unfiltered) { |
| 169 //TODO (danrubel) Revisit this filtering once paged API has been added | 174 //TODO (danrubel) Revisit this filtering once paged API has been added |
| 170 unfiltered.forEach((CompletionSuggestion suggestion) { | 175 unfiltered.forEach((CompletionSuggestion suggestion) { |
| 171 if (filterText.length > 0) { | 176 if (filterText.length > 0) { |
| 172 if (suggestion.completion.startsWith(filterText)) { | 177 if (suggestion.completion.startsWith(filterText)) { |
| 173 request.suggestions.add(suggestion); | 178 _addSuggestion(suggestion); |
| 174 } | 179 } |
| 175 } else { | 180 } else { |
| 176 if (suggestion.relevance != DART_RELEVANCE_LOW) { | 181 if (suggestion.relevance != DART_RELEVANCE_LOW) { |
| 177 request.suggestions.add(suggestion); | 182 _addSuggestion(suggestion); |
| 178 } | 183 } |
| 179 } | 184 } |
| 180 }); | 185 }); |
| 181 } | 186 } |
| 182 | 187 |
| 183 /** | 188 /** |
| 184 * Add suggestions for any inherited imported members. | 189 * Add suggestions for any inherited imported members. |
| 185 */ | 190 */ |
| 186 void _addInheritedSuggestions(AstNode node) { | 191 void _addInheritedSuggestions(AstNode node) { |
| 187 var classDecl = node.getAncestor((p) => p is ClassDeclaration); | 192 var classDecl = node.getAncestor((p) => p is ClassDeclaration); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 214 _addElementSuggestions(type.element.methods, | 219 _addElementSuggestions(type.element.methods, |
| 215 relevance: DART_RELEVANCE_INHERITED_METHOD); | 220 relevance: DART_RELEVANCE_INHERITED_METHOD); |
| 216 } | 221 } |
| 217 }); | 222 }); |
| 218 } | 223 } |
| 219 } | 224 } |
| 220 } | 225 } |
| 221 } | 226 } |
| 222 | 227 |
| 223 /** | 228 /** |
| 229 * Add suggestion if an identically named suggestion |
| 230 * has not already been added. |
| 231 */ |
| 232 void _addSuggestion(CompletionSuggestion suggestion) { |
| 233 if (completions.add(suggestion.completion)) { |
| 234 request.suggestions.add(suggestion); |
| 235 } |
| 236 } |
| 237 |
| 238 /** |
| 224 * Add suggested based upon imported elements. | 239 * Add suggested based upon imported elements. |
| 225 */ | 240 */ |
| 226 void _addSuggestions(AstNode node) { | 241 void _addSuggestions(AstNode node) { |
| 227 if (optype.includeConstructorSuggestions) { | 242 if (optype.includeConstructorSuggestions) { |
| 228 _addConstructorSuggestions(); | 243 _addConstructorSuggestions(); |
| 229 } | 244 } |
| 230 if (optype.includeReturnValueSuggestions || | 245 if (optype.includeReturnValueSuggestions || |
| 231 optype.includeTypeNameSuggestions || | 246 optype.includeTypeNameSuggestions || |
| 232 optype.includeVoidReturnSuggestions) { | 247 optype.includeVoidReturnSuggestions) { |
| 233 _addInheritedSuggestions(node); | 248 _addInheritedSuggestions(node); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 253 _addFilteredSuggestions(filterText, cache.libraryPrefixSuggestions); | 268 _addFilteredSuggestions(filterText, cache.libraryPrefixSuggestions); |
| 254 } | 269 } |
| 255 if (optype.includeReturnValueSuggestions) { | 270 if (optype.includeReturnValueSuggestions) { |
| 256 _addFilteredSuggestions(filterText, cache.otherImportedSuggestions); | 271 _addFilteredSuggestions(filterText, cache.otherImportedSuggestions); |
| 257 } | 272 } |
| 258 if (optype.includeVoidReturnSuggestions) { | 273 if (optype.includeVoidReturnSuggestions) { |
| 259 _addFilteredSuggestions(filterText, cache.importedVoidReturnSuggestions); | 274 _addFilteredSuggestions(filterText, cache.importedVoidReturnSuggestions); |
| 260 } | 275 } |
| 261 } | 276 } |
| 262 } | 277 } |
| OLD | NEW |