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

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

Issue 1539693002: move DartCompletionSorter to dart specific contributor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 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/dart/completion_manager.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
index 5ff957f1c4cc74d4d7d72127662f444dcc3d33c5..2289a925a565f4a76a7af80fb835dbf6ae1f1a2f 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
@@ -26,12 +26,20 @@ import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/task/dart.dart';
import 'package:analyzer/task/dart.dart';
import 'package:analyzer/src/generated/scanner.dart';
+import 'package:analysis_server/src/services/completion/dart/contribution_sorter.dart';
+import 'package:analysis_server/src/services/completion/dart/common_usage_sorter.dart';
/**
* [DartCompletionManager] determines if a completion request is Dart specific
* and forwards those requests to all [DartCompletionContributor]s.
*/
class DartCompletionManager implements CompletionContributor {
+ /**
+ * The [contributionSorter] is a long-lived object that isn't allowed
+ * to maintain state between calls to [DartContributionSorter#sort(...)].
+ */
+ static DartContributionSorter contributionSorter = new CommonUsageSorter();
+
@override
Future<List<CompletionSuggestion>> computeSuggestions(
CompletionRequest request) async {
@@ -57,8 +65,10 @@ class DartCompletionManager implements CompletionContributor {
<String, CompletionSuggestion>{};
for (DartCompletionContributor contributor
in dartCompletionPlugin.contributors) {
- for (CompletionSuggestion newSuggestion
- in await contributor.computeSuggestions(dartRequest)) {
+ List<CompletionSuggestion> contributorSuggestions =
+ await contributor.computeSuggestions(dartRequest);
+
+ for (CompletionSuggestion newSuggestion in contributorSuggestions) {
var oldSuggestion = suggestionMap.putIfAbsent(
newSuggestion.completion, () => newSuggestion);
if (newSuggestion != oldSuggestion &&
@@ -67,7 +77,11 @@ class DartCompletionManager implements CompletionContributor {
}
}
}
- return suggestionMap.values.toList();
+
+ // Adjust suggestion relevance before returning
+ List<CompletionSuggestion> suggestions = suggestionMap.values.toList();
+ await contributionSorter.sort(dartRequest, suggestions);
+ return suggestions;
}
}

Powered by Google App Engine
This is Rietveld 408576698