Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: pkg/analysis_server/lib/src/services/completion/imported_computer.dart

Issue 795633004: filter imported element suggestions to reduce number of results sent to client (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge and fix test Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/completion/imported_computer.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/imported_computer.dart b/pkg/analysis_server/lib/src/services/completion/imported_computer.dart
index a74910ca2dbf4bb410c5d00fbc5b33c0224474b3..5b0d947e20b52a561e591de59c4d438abd18dbd0 100644
--- a/pkg/analysis_server/lib/src/services/completion/imported_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/imported_computer.dart
@@ -320,15 +320,41 @@ class _ImportedSuggestionBuilder implements SuggestionBuilder {
}
}
+ /**
+ * Add top level suggestions from the cache.
+ * To reduce the number of suggestions sent to the client,
+ * filter the suggestions based upon the first character typed.
+ * If no characters are available to use for filtering,
+ * then exclude all low priority suggestions.
+ */
void _addTopLevelSuggestions() {
+ String filterText = request.filterText;
+ if (filterText.length > 1) {
+ filterText = filterText.substring(0, 1);
+ }
+
+ //TODO (danrubel) Revisit this filtering once paged API has been added
+ addFilteredSuggestions(List<CompletionSuggestion> unfiltered) {
+ unfiltered.forEach((CompletionSuggestion suggestion) {
+ if (filterText.length > 0) {
+ if (suggestion.completion.startsWith(filterText)) {
+ request.suggestions.add(suggestion);
+ }
+ } else {
+ if (suggestion.relevance != CompletionRelevance.LOW) {
+ request.suggestions.add(suggestion);
+ }
+ }
+ });
+ }
+
DartCompletionCache cache = request.cache;
- request.suggestions
- ..addAll(cache.importedTypeSuggestions)
- ..addAll(cache.libraryPrefixSuggestions);
+ addFilteredSuggestions(cache.importedTypeSuggestions);
+ addFilteredSuggestions(cache.libraryPrefixSuggestions);
if (!typesOnly) {
- request.suggestions.addAll(cache.otherImportedSuggestions);
+ addFilteredSuggestions(cache.otherImportedSuggestions);
if (!excludeVoidReturn) {
- request.suggestions.addAll(cache.importedVoidReturnSuggestions);
+ addFilteredSuggestions(cache.importedVoidReturnSuggestions);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698