@@ -523,7 +523,7 @@ class CompletionMetrics {
523
523
void recordShadowedCompletion (
524
524
String ? completionLocation,
525
525
ExpectedCompletion expectedCompletion,
526
- protocol. CompletionSuggestion closeMatchSuggestion) {
526
+ CompletionSuggestionLite closeMatchSuggestion) {
527
527
shadowedCompletions
528
528
.putIfAbsent (completionLocation ?? 'unknown' , () => [])
529
529
.add (ShadowedCompletion (expectedCompletion, closeMatchSuggestion));
@@ -863,7 +863,7 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
863
863
MetricsSuggestionListener listener,
864
864
ExpectedCompletion expectedCompletion,
865
865
String ? completionLocation,
866
- List <protocol. CompletionSuggestion > suggestions,
866
+ List <CompletionSuggestionLite > suggestions,
867
867
CompletionMetrics metrics,
868
868
int elapsedMS) {
869
869
var place = placementInSuggestionList (suggestions, expectedCompletion);
@@ -925,7 +925,7 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
925
925
926
926
if (options.printMissedCompletionDetails ||
927
927
options.printShadowedCompletionDetails) {
928
- protocol. CompletionSuggestion ? closeMatchSuggestion;
928
+ CompletionSuggestionLite ? closeMatchSuggestion;
929
929
for (var suggestion in suggestions) {
930
930
if (suggestion.completion == expectedCompletion.completion) {
931
931
closeMatchSuggestion = suggestion;
@@ -1376,8 +1376,8 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
1376
1376
@override
1377
1377
void setupForResolution (AnalysisContext context) {}
1378
1378
1379
- int _computeCharsBeforeTop (ExpectedCompletion target,
1380
- List <protocol. CompletionSuggestion > suggestions,
1379
+ int _computeCharsBeforeTop (
1380
+ ExpectedCompletion target, List <CompletionSuggestionLite > suggestions,
1381
1381
{int minRank = 1 }) {
1382
1382
var rank = placementInSuggestionList (suggestions, target).rank;
1383
1383
if (rank <= minRank) {
@@ -1397,15 +1397,13 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
1397
1397
1398
1398
/// Computes completion suggestions for [dartRequest] , and returns the
1399
1399
/// suggestions, sorted by rank and then by completion text.
1400
- Future <List <protocol. CompletionSuggestion >> _computeCompletionSuggestions (
1400
+ Future <List <CompletionSuggestionLite >> _computeCompletionSuggestions (
1401
1401
MetricsSuggestionListener listener,
1402
1402
OperationPerformanceImpl performance,
1403
1403
DartCompletionRequest dartRequest,
1404
1404
NotImportedSuggestions notImportedSuggestions) async {
1405
- List <protocol.CompletionSuggestion > suggestions;
1406
-
1407
1405
var budget = CompletionBudget (Duration (seconds: 30 ));
1408
- var serverSuggestions = await DartCompletionManager (
1406
+ var suggestions = await DartCompletionManager (
1409
1407
budget: budget,
1410
1408
listener: listener,
1411
1409
notImportedSuggestions: notImportedSuggestions,
@@ -1414,19 +1412,16 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
1414
1412
performance,
1415
1413
useFilter: true ,
1416
1414
);
1417
- suggestions = serverSuggestions.map ((serverSuggestion) {
1418
- return serverSuggestion.build ();
1419
- }).toList ();
1420
1415
1421
1416
// Note that some routes sort suggestions before responding differently.
1422
1417
// The Cider and legacy handlers use [fuzzyFilterSort], which does not match
1423
1418
// [completionComparator].
1424
1419
suggestions.sort (completionComparator);
1425
- return suggestions;
1420
+ return suggestions. map ( CompletionSuggestionLite .fromBuilder). toList () ;
1426
1421
}
1427
1422
1428
- List <protocol. CompletionSuggestion > _filterSuggestions (
1429
- String prefix, List <protocol. CompletionSuggestion > suggestions) {
1423
+ List <CompletionSuggestionLite > _filterSuggestions (
1424
+ String prefix, List <CompletionSuggestionLite > suggestions) {
1430
1425
// TODO(brianwilkerson): Replace this with a more realistic filtering
1431
1426
// algorithm.
1432
1427
return suggestions
@@ -1521,7 +1516,7 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
1521
1516
///
1522
1517
/// If [expectedCompletion] is not found, `Place.none()` is returned.
1523
1518
static Place placementInSuggestionList (
1524
- List <protocol. CompletionSuggestion > suggestions,
1519
+ List <CompletionSuggestionLite > suggestions,
1525
1520
ExpectedCompletion expectedCompletion) {
1526
1521
for (var i = 0 ; i < suggestions.length; i++ ) {
1527
1522
if (expectedCompletion.matches (suggestions[i])) {
@@ -1705,6 +1700,78 @@ class CompletionResult {
1705
1700
}
1706
1701
}
1707
1702
1703
+ /// Enough data from [CompletionSuggestionBuilder] to compute metrics.
1704
+ ///
1705
+ /// It excludes expensive parts that are not necessary, such as element
1706
+ /// properties.
1707
+ class CompletionSuggestionLite {
1708
+ final String completion;
1709
+ final protocol.ElementKind ? elementKind;
1710
+ final int relevance;
1711
+ final protocol.CompletionSuggestionKind kind;
1712
+
1713
+ CompletionSuggestionLite ({
1714
+ required this .completion,
1715
+ required this .elementKind,
1716
+ required this .relevance,
1717
+ required this .kind,
1718
+ });
1719
+
1720
+ factory CompletionSuggestionLite .fromBuilder (
1721
+ CompletionSuggestionBuilder builder,
1722
+ ) {
1723
+ return CompletionSuggestionLite (
1724
+ completion: builder.completion,
1725
+ elementKind: builder.elementKind,
1726
+ relevance: builder.relevance,
1727
+ kind: builder.kind,
1728
+ );
1729
+ }
1730
+
1731
+ factory CompletionSuggestionLite .fromJson (Map <String , Object ?> map) {
1732
+ var elementKindStr = map['elementKind' ] as String ? ;
1733
+
1734
+ return CompletionSuggestionLite (
1735
+ completion: map['completion' ] as String ,
1736
+ elementKind: elementKindStr != null
1737
+ ? protocol.ElementKind .fromJson (
1738
+ ResponseDecoder (null ),
1739
+ '' ,
1740
+ elementKindStr,
1741
+ )
1742
+ : null ,
1743
+ relevance: map['relevance' ] as int ,
1744
+ kind: protocol.CompletionSuggestionKind .fromJson (
1745
+ ResponseDecoder (null ),
1746
+ '' ,
1747
+ map['kind' ] as String ,
1748
+ ),
1749
+ );
1750
+ }
1751
+
1752
+ @override
1753
+ int get hashCode => Object .hash (completion, kind);
1754
+
1755
+ @override
1756
+ bool operator == (Object other) {
1757
+ return other is CompletionSuggestionLite &&
1758
+ other.completion == completion &&
1759
+ other.kind == kind &&
1760
+ other.elementKind == elementKind &&
1761
+ other.relevance == relevance;
1762
+ }
1763
+
1764
+ /// Return a map used to represent this suggestion data in a JSON structure.
1765
+ Map <String , Object ?> toJson () {
1766
+ return {
1767
+ 'completion' : completion,
1768
+ if (elementKind case var elementKind? ) 'elementKind' : elementKind.name,
1769
+ 'relevance' : relevance,
1770
+ 'kind' : kind.name,
1771
+ };
1772
+ }
1773
+ }
1774
+
1708
1775
/// The data to be printed on a single line in the table of mrr values per
1709
1776
/// completion location.
1710
1777
class LocationTableLine {
@@ -1738,7 +1805,7 @@ class MetricsSuggestionListener implements SuggestionListener {
1738
1805
0.0
1739
1806
];
1740
1807
1741
- Map <protocol. CompletionSuggestion , List <double >> featureMap = Map .identity ();
1808
+ Map <CompletionSuggestionLite , List <double >> featureMap = Map .identity ();
1742
1809
1743
1810
List <double > cachedFeatures = noFeatures;
1744
1811
@@ -1747,8 +1814,8 @@ class MetricsSuggestionListener implements SuggestionListener {
1747
1814
String ? missingCompletionLocationTable;
1748
1815
1749
1816
@override
1750
- void builtSuggestion (CompletionSuggestionBuilder suggestionBuilder ) {
1751
- var suggestion = suggestionBuilder. build ( );
1817
+ void builtSuggestion (CompletionSuggestionBuilder builder ) {
1818
+ var suggestion = CompletionSuggestionLite . fromBuilder (builder );
1752
1819
featureMap[suggestion] = cachedFeatures;
1753
1820
cachedFeatures = noFeatures;
1754
1821
}
@@ -1826,15 +1893,15 @@ class RelevanceTables {
1826
1893
class ShadowedCompletion {
1827
1894
final ExpectedCompletion expectedCompletion;
1828
1895
1829
- final protocol. CompletionSuggestion closeMatchSuggestion;
1896
+ final CompletionSuggestionLite closeMatchSuggestion;
1830
1897
1831
1898
ShadowedCompletion (this .expectedCompletion, this .closeMatchSuggestion);
1832
1899
}
1833
1900
1834
1901
/// The information being remembered about an individual suggestion.
1835
1902
class SuggestionData {
1836
1903
/// The suggestion that was produced.
1837
- protocol. CompletionSuggestion suggestion;
1904
+ CompletionSuggestionLite suggestion;
1838
1905
1839
1906
/// The values of the features used to compute the suggestion.
1840
1907
List <double > features;
@@ -1844,9 +1911,11 @@ class SuggestionData {
1844
1911
/// Return an instance extracted from the decoded JSON [map] .
1845
1912
factory SuggestionData .fromJson (Map <String , dynamic > map) {
1846
1913
return SuggestionData (
1847
- protocol.CompletionSuggestion .fromJson (ResponseDecoder (null ), '' ,
1848
- map['suggestion' ] as Map <String , dynamic >),
1849
- (map['features' ] as List <dynamic >).cast <double >());
1914
+ CompletionSuggestionLite .fromJson (
1915
+ map['suggestion' ] as Map <String , Object ?>,
1916
+ ),
1917
+ (map['features' ] as List <dynamic >).cast <double >(),
1918
+ );
1850
1919
}
1851
1920
1852
1921
/// Return a map used to represent this suggestion data in a JSON structure.
0 commit comments