Fix a couple of bugs in the metrics tool
Change-Id: Ib8c17f9e9963996118473c5c32d3d6fb51ce632e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196343
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/tool/code_completion/completion_metrics.dart b/pkg/analysis_server/tool/code_completion/completion_metrics.dart
index 31237c3..4a685e3 100644
--- a/pkg/analysis_server/tool/code_completion/completion_metrics.dart
+++ b/pkg/analysis_server/tool/code_completion/completion_metrics.dart
@@ -654,15 +654,17 @@
var rank = place.rank;
var suggestion = suggestions[rank - 1];
- var actualSuggestion =
- SuggestionData(suggestion, listener.featureMap[suggestion]!);
+ var features = listener.featureMap[suggestion] ??
+ MetricsSuggestionListener.noFeatures;
+ var actualSuggestion = SuggestionData(suggestion, features);
List<SuggestionData>? topSuggestions;
Map<int, int>? precedingRelevanceCounts;
if (options.printWorstResults) {
+ var features = listener.featureMap[suggestion] ??
+ MetricsSuggestionListener.noFeatures;
topSuggestions = suggestions
.sublist(0, math.min(10, suggestions.length))
- .map((suggestion) =>
- SuggestionData(suggestion, listener.featureMap[suggestion]!))
+ .map((suggestion) => SuggestionData(suggestion, features))
.toList();
precedingRelevanceCounts = <int, int>{};
for (var i = 0; i < rank - 1; i++) {
@@ -1687,9 +1689,9 @@
}
class MetricsSuggestionListener implements SuggestionListener {
- Map<protocol.CompletionSuggestion, List<double>> featureMap = {};
-
- List<double> cachedFeatures = const [
+ /// The feature values to use when there are no features for a suggestion.
+ static const List<double> noFeatures = [
+ 0.0,
0.0,
0.0,
0.0,
@@ -1701,6 +1703,10 @@
0.0
];
+ Map<protocol.CompletionSuggestion, List<double>> featureMap = {};
+
+ List<double> cachedFeatures = noFeatures;
+
String? missingCompletionLocation;
String? missingCompletionLocationTable;
@@ -1708,7 +1714,7 @@
@override
void builtSuggestion(protocol.CompletionSuggestion suggestion) {
featureMap[suggestion] = cachedFeatures;
- cachedFeatures = const [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
+ cachedFeatures = noFeatures;
}
@override