@@ -11,14 +11,13 @@ import 'dart:io' show stdout;
11
11
import 'dart:math' as math;
12
12
13
13
import 'package:_fe_analyzer_shared/src/base/syntactic_entity.dart' ;
14
- import 'package:analysis_server/src/protocol/protocol_internal.dart' ;
15
14
import 'package:analysis_server/src/protocol_server.dart' as protocol;
15
+ import 'package:analysis_server/src/services/completion/dart/candidate_suggestion.dart' ;
16
16
import 'package:analysis_server/src/services/completion/dart/completion_manager.dart' ;
17
17
import 'package:analysis_server/src/services/completion/dart/feature_computer.dart' ;
18
18
import 'package:analysis_server/src/services/completion/dart/probability_range.dart' ;
19
19
import 'package:analysis_server/src/services/completion/dart/relevance_tables.g.dart' ;
20
20
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart' ;
21
- import 'package:analysis_server/src/services/completion/dart/utilities.dart' ;
22
21
import 'package:analysis_server/src/status/pages.dart' ;
23
22
import 'package:analyzer/dart/analysis/analysis_context.dart' ;
24
23
import 'package:analyzer/dart/analysis/results.dart' ;
@@ -577,7 +576,7 @@ class CompletionMetrics {
577
576
void recordShadowedCompletion (
578
577
String ? completionLocation,
579
578
ExpectedCompletion expectedCompletion,
580
- CompletionSuggestionLite closeMatchSuggestion,
579
+ CandidateSuggestion closeMatchSuggestion,
581
580
) {
582
581
shadowedCompletions
583
582
.putIfAbsent (completionLocation ?? 'unknown' , () => [])
@@ -935,7 +934,7 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
935
934
MetricsSuggestionListener listener,
936
935
ExpectedCompletion expectedCompletion,
937
936
String ? completionLocation,
938
- List <CompletionSuggestionLite > suggestions,
937
+ List <CandidateSuggestion > suggestions,
939
938
CompletionMetrics metrics,
940
939
int elapsedMS,
941
940
) {
@@ -965,7 +964,7 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
965
964
.toList ();
966
965
precedingRelevanceCounts = < int , int > {};
967
966
for (var i = 0 ; i < rank - 1 ; i++ ) {
968
- var relevance = suggestions[i].relevance ;
967
+ var relevance = suggestions[i].relevanceScore ;
969
968
precedingRelevanceCounts[relevance] =
970
969
(precedingRelevanceCounts[relevance] ?? 0 ) + 1 ;
971
970
}
@@ -1008,7 +1007,7 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
1008
1007
1009
1008
if (options.printMissedCompletionDetails ||
1010
1009
options.printShadowedCompletionDetails) {
1011
- CompletionSuggestionLite ? closeMatchSuggestion;
1010
+ CandidateSuggestion ? closeMatchSuggestion;
1012
1011
for (var suggestion in suggestions) {
1013
1012
if (suggestion.completion == expectedCompletion.completion) {
1014
1013
closeMatchSuggestion = suggestion;
@@ -1488,7 +1487,7 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
1488
1487
1489
1488
int _computeCharsBeforeTop (
1490
1489
ExpectedCompletion target,
1491
- List <CompletionSuggestionLite > suggestions, {
1490
+ List <CandidateSuggestion > suggestions, {
1492
1491
int minRank = 1 ,
1493
1492
}) {
1494
1493
var rank = placementInSuggestionList (suggestions, target).rank;
@@ -1509,34 +1508,28 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
1509
1508
1510
1509
/// Computes completion suggestions for [dartRequest] , and returns the
1511
1510
/// suggestions, sorted by rank and then by completion text.
1512
- Future <List <CompletionSuggestionLite >> _computeCompletionSuggestions (
1511
+ Future <List <CandidateSuggestion >> _computeCompletionSuggestions (
1513
1512
MetricsSuggestionListener listener,
1514
1513
OperationPerformanceImpl performance,
1515
1514
DartCompletionRequest dartRequest,
1516
1515
NotImportedSuggestions notImportedSuggestions,
1517
1516
) async {
1518
1517
var budget = CompletionBudget (Duration (seconds: 30 ));
1519
- var suggestions = await DartCompletionManager (
1518
+ var collector = await DartCompletionManager (
1520
1519
budget: budget,
1521
1520
listener: listener,
1522
1521
notImportedSuggestions: notImportedSuggestions,
1523
- ).computeSuggestions (
1524
- dartRequest,
1525
- performance,
1522
+ ).computeFinalizedCandidateSuggestions (
1523
+ request : dartRequest,
1524
+ performance: performance ,
1526
1525
maxSuggestions: - 1 ,
1527
- useFilter: true ,
1528
1526
);
1529
-
1530
- // Note that some routes sort suggestions before responding differently.
1531
- // The Cider and legacy handlers use [fuzzyFilterSort], which does not match
1532
- // [completionComparator].
1533
- suggestions.sort (completionComparator);
1534
- return suggestions.map (CompletionSuggestionLite .fromBuilder).toList ();
1527
+ return collector.suggestions;
1535
1528
}
1536
1529
1537
- List <CompletionSuggestionLite > _filterSuggestions (
1530
+ List <CandidateSuggestion > _filterSuggestions (
1538
1531
String prefix,
1539
- List <CompletionSuggestionLite > suggestions,
1532
+ List <CandidateSuggestion > suggestions,
1540
1533
) {
1541
1534
// TODO(brianwilkerson): Replace this with a more realistic filtering
1542
1535
// algorithm.
@@ -1550,7 +1543,7 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
1550
1543
var suggestion = data.suggestion;
1551
1544
return [
1552
1545
rank.toString (),
1553
- suggestion.relevance .toString (),
1546
+ suggestion.relevanceScore .toString (),
1554
1547
suggestion.completion,
1555
1548
suggestion.kind.toString (),
1556
1549
];
@@ -1635,7 +1628,7 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
1635
1628
///
1636
1629
/// If [expectedCompletion] is not found, `Place.none()` is returned.
1637
1630
static Place placementInSuggestionList (
1638
- List <CompletionSuggestionLite > suggestions,
1631
+ List <CandidateSuggestion > suggestions,
1639
1632
ExpectedCompletion expectedCompletion,
1640
1633
) {
1641
1634
for (var i = 0 ; i < suggestions.length; i++ ) {
@@ -1824,79 +1817,6 @@ class CompletionResult {
1824
1817
}
1825
1818
}
1826
1819
1827
- /// Enough data from [CompletionSuggestionBuilder] to compute metrics.
1828
- ///
1829
- /// It excludes expensive parts that are not necessary, such as element
1830
- /// properties.
1831
- class CompletionSuggestionLite {
1832
- final String completion;
1833
- final protocol.ElementKind ? elementKind;
1834
- final int relevance;
1835
- final protocol.CompletionSuggestionKind kind;
1836
-
1837
- CompletionSuggestionLite ({
1838
- required this .completion,
1839
- required this .elementKind,
1840
- required this .relevance,
1841
- required this .kind,
1842
- });
1843
-
1844
- factory CompletionSuggestionLite .fromBuilder (
1845
- CompletionSuggestionBuilder builder,
1846
- ) {
1847
- return CompletionSuggestionLite (
1848
- completion: builder.completion,
1849
- elementKind: builder.elementKind,
1850
- relevance: builder.relevance,
1851
- kind: builder.kind,
1852
- );
1853
- }
1854
-
1855
- factory CompletionSuggestionLite .fromJson (Map <String , Object ?> map) {
1856
- var elementKindStr = map['elementKind' ] as String ? ;
1857
-
1858
- return CompletionSuggestionLite (
1859
- completion: map['completion' ] as String ,
1860
- elementKind:
1861
- elementKindStr != null
1862
- ? protocol.ElementKind .fromJson (
1863
- ResponseDecoder (null ),
1864
- '' ,
1865
- elementKindStr,
1866
- )
1867
- : null ,
1868
- relevance: map['relevance' ] as int ,
1869
- kind: protocol.CompletionSuggestionKind .fromJson (
1870
- ResponseDecoder (null ),
1871
- '' ,
1872
- map['kind' ] as String ,
1873
- ),
1874
- );
1875
- }
1876
-
1877
- @override
1878
- int get hashCode => Object .hash (completion, kind);
1879
-
1880
- @override
1881
- bool operator == (Object other) {
1882
- return other is CompletionSuggestionLite &&
1883
- other.completion == completion &&
1884
- other.kind == kind &&
1885
- other.elementKind == elementKind &&
1886
- other.relevance == relevance;
1887
- }
1888
-
1889
- /// Return a map used to represent this suggestion data in a JSON structure.
1890
- Map <String , Object ?> toJson () {
1891
- return {
1892
- 'completion' : completion,
1893
- if (elementKind case var elementKind? ) 'elementKind' : elementKind.name,
1894
- 'relevance' : relevance,
1895
- 'kind' : kind.name,
1896
- };
1897
- }
1898
- }
1899
-
1900
1820
/// The data to be printed on a single line in the table of mrr values per
1901
1821
/// completion location.
1902
1822
class LocationTableLine {
@@ -1931,7 +1851,7 @@ class MetricsSuggestionListener implements SuggestionListener {
1931
1851
0.0 ,
1932
1852
];
1933
1853
1934
- Map <CompletionSuggestionLite , List <double >> featureMap = Map .identity ();
1854
+ Map <CandidateSuggestion , List <double >> featureMap = Map .identity ();
1935
1855
1936
1856
List <double > cachedFeatures = noFeatures;
1937
1857
@@ -1940,12 +1860,16 @@ class MetricsSuggestionListener implements SuggestionListener {
1940
1860
String ? missingCompletionLocationTable;
1941
1861
1942
1862
@override
1943
- void builtSuggestion (CompletionSuggestionBuilder builder) {
1944
- var suggestion = CompletionSuggestionLite .fromBuilder (builder);
1945
- featureMap[suggestion] = cachedFeatures;
1863
+ void builtCandidate (CandidateSuggestion candidate) {
1864
+ featureMap[candidate] = cachedFeatures;
1946
1865
cachedFeatures = noFeatures;
1947
1866
}
1948
1867
1868
+ @override
1869
+ void builtSuggestion (CompletionSuggestionBuilder builder) {
1870
+ throw UnsupportedError ('Unexpected use of SuggestionBuilder' );
1871
+ }
1872
+
1949
1873
@override
1950
1874
void computedFeatures ({
1951
1875
double contextType = 0.0 ,
@@ -2020,15 +1944,15 @@ class RelevanceTables {
2020
1944
class ShadowedCompletion {
2021
1945
final ExpectedCompletion expectedCompletion;
2022
1946
2023
- final CompletionSuggestionLite closeMatchSuggestion;
1947
+ final CandidateSuggestion closeMatchSuggestion;
2024
1948
2025
1949
ShadowedCompletion (this .expectedCompletion, this .closeMatchSuggestion);
2026
1950
}
2027
1951
2028
1952
/// The information being remembered about an individual suggestion.
2029
1953
class SuggestionData {
2030
1954
/// The suggestion that was produced.
2031
- CompletionSuggestionLite suggestion;
1955
+ CandidateSuggestion suggestion;
2032
1956
2033
1957
/// The values of the features used to compute the suggestion.
2034
1958
List <double > features;
@@ -2037,17 +1961,17 @@ class SuggestionData {
2037
1961
2038
1962
/// Return an instance extracted from the decoded JSON [map] .
2039
1963
factory SuggestionData .fromJson (Map <String , dynamic > map) {
2040
- return SuggestionData (
2041
- CompletionSuggestionLite .fromJson (
2042
- map['suggestion' ] as Map <String , Object ?>,
2043
- ),
2044
- (map['features' ] as List <dynamic >).cast <double >(),
2045
- );
1964
+ throw UnimplementedError ();
1965
+ // return SuggestionData(
1966
+ // CandidateSuggestion.fromJson(map['suggestion'] as Map<String, Object?>),
1967
+ // (map['features'] as List<dynamic>).cast<double>(),
1968
+ // );
2046
1969
}
2047
1970
2048
1971
/// Return a map used to represent this suggestion data in a JSON structure.
2049
1972
Map <String , dynamic > toJson () {
2050
- return {'suggestion' : suggestion.toJson (), 'features' : features};
1973
+ throw UnimplementedError ();
1974
+ // return {'suggestion': suggestion.toJson(), 'features': features};
2051
1975
}
2052
1976
}
2053
1977
@@ -2094,6 +2018,14 @@ extension on CompletionGroup {
2094
2018
}
2095
2019
}
2096
2020
2021
+ extension on CandidateSuggestion {
2022
+ /// The kind of element being suggested.
2023
+ protocol.CompletionSuggestionKind ? get kind {
2024
+ // TODO(brianwilkerson): Implement this.
2025
+ return null ;
2026
+ }
2027
+ }
2028
+
2097
2029
extension on num {
2098
2030
String asPercentage ([int fractionDigits = 1 ]) =>
2099
2031
'${(this * 100 ).toStringAsFixed (fractionDigits )}%' .padLeft (
0 commit comments