| 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' hide Element, | 10 import 'package:analysis_server/src/protocol_server.dart' hide Element, |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 if (visited.add(type.name)) { | 313 if (visited.add(type.name)) { |
| 314 _addElementSuggestions(type.accessors); | 314 _addElementSuggestions(type.accessors); |
| 315 _addElementSuggestions(type.methods); | 315 _addElementSuggestions(type.methods); |
| 316 } | 316 } |
| 317 }); | 317 }); |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 | 322 |
| 323 /** |
| 324 * Add top level suggestions from the cache. |
| 325 * To reduce the number of suggestions sent to the client, |
| 326 * filter the suggestions based upon the first character typed. |
| 327 * If no characters are available to use for filtering, |
| 328 * then exclude all low priority suggestions. |
| 329 */ |
| 323 void _addTopLevelSuggestions() { | 330 void _addTopLevelSuggestions() { |
| 331 String filterText = request.filterText; |
| 332 if (filterText.length > 1) { |
| 333 filterText = filterText.substring(0, 1); |
| 334 } |
| 335 |
| 336 //TODO (danrubel) Revisit this filtering once paged API has been added |
| 337 addFilteredSuggestions(List<CompletionSuggestion> unfiltered) { |
| 338 unfiltered.forEach((CompletionSuggestion suggestion) { |
| 339 if (filterText.length > 0) { |
| 340 if (suggestion.completion.startsWith(filterText)) { |
| 341 request.suggestions.add(suggestion); |
| 342 } |
| 343 } else { |
| 344 if (suggestion.relevance != CompletionRelevance.LOW) { |
| 345 request.suggestions.add(suggestion); |
| 346 } |
| 347 } |
| 348 }); |
| 349 } |
| 350 |
| 324 DartCompletionCache cache = request.cache; | 351 DartCompletionCache cache = request.cache; |
| 325 request.suggestions | 352 addFilteredSuggestions(cache.importedTypeSuggestions); |
| 326 ..addAll(cache.importedTypeSuggestions) | 353 addFilteredSuggestions(cache.libraryPrefixSuggestions); |
| 327 ..addAll(cache.libraryPrefixSuggestions); | |
| 328 if (!typesOnly) { | 354 if (!typesOnly) { |
| 329 request.suggestions.addAll(cache.otherImportedSuggestions); | 355 addFilteredSuggestions(cache.otherImportedSuggestions); |
| 330 if (!excludeVoidReturn) { | 356 if (!excludeVoidReturn) { |
| 331 request.suggestions.addAll(cache.importedVoidReturnSuggestions); | 357 addFilteredSuggestions(cache.importedVoidReturnSuggestions); |
| 332 } | 358 } |
| 333 } | 359 } |
| 334 } | 360 } |
| 335 } | 361 } |
| OLD | NEW |