File tree Expand file tree Collapse file tree 2 files changed +38
-7
lines changed
pkg/analysis_server/tool/completion_metrics Expand file tree Collapse file tree 2 files changed +38
-7
lines changed Original file line number Diff line number Diff line change 44
55import 'dart:async' ;
66import 'dart:io' as io;
7- import 'dart:math' ;
87
98import 'package:analysis_server/src/domains/completion/available_suggestions.dart' ;
109import 'package:analysis_server/src/protocol_server.dart' ;
@@ -83,7 +82,7 @@ Future _computeCompletionMetrics(
8382 var fraction =
8483 _placementInSuggestionList (suggestions, expectedCompletion);
8584
86- if (fraction.y != 0 ) {
85+ if (fraction.denominator != 0 ) {
8786 includedCount++ ;
8887 } else {
8988 notIncludedCount++ ;
@@ -130,16 +129,16 @@ Future _computeCompletionMetrics(
130129 completionElementKindCounter.clear ();
131130}
132131
133- Point < int > _placementInSuggestionList (List <CompletionSuggestion > suggestions,
132+ Place _placementInSuggestionList (List <CompletionSuggestion > suggestions,
134133 ExpectedCompletion expectedCompletion) {
135- var i = 1 ;
134+ var placeCounter = 1 ;
136135 for (var completionSuggestion in suggestions) {
137136 if (expectedCompletion.matches (completionSuggestion)) {
138- return Point (i , suggestions.length);
137+ return Place (placeCounter , suggestions.length);
139138 }
140- i ++ ;
139+ placeCounter ++ ;
141140 }
142- return Point ( 0 , 0 );
141+ return Place . none ( );
143142}
144143
145144Future <List <CompletionSuggestion >> computeCompletionSuggestions (
Original file line number Diff line number Diff line change 33// BSD-style license that can be found in the LICENSE file.
44
55import 'package:analysis_server/src/status/pages.dart' ;
6+ import 'package:analyzer/src/generated/utilities_general.dart' ;
67
78/// A simple counter class. A [String] name is passed to name the counter. Each
89/// time something is counted, a non-null, non-empty [String] key is passed to
@@ -54,3 +55,34 @@ class Counter {
5455 print ('' );
5556 }
5657}
58+
59+ /// An immutable class to represent the placement in some list, for example '2nd
60+ /// place out of 5'.
61+ class Place {
62+ /// A 1-indexed place in a list
63+ final int _numerator;
64+
65+ /// The total number of possible places.
66+ final int _denominator;
67+
68+ Place (this ._numerator, this ._denominator) {
69+ assert (_numerator > 0 && _denominator > 0 );
70+ }
71+
72+ Place .none ()
73+ : _numerator = 0 ,
74+ _denominator = 0 ;
75+
76+ int get denominator => _denominator;
77+
78+ @override
79+ int get hashCode => JenkinsSmiHash .hash2 (_numerator, _denominator);
80+
81+ int get numerator => _numerator;
82+
83+ @override
84+ bool operator == (dynamic other) =>
85+ other is Place &&
86+ _numerator == other._numerator &&
87+ _denominator == other._denominator;
88+ }
You can’t perform that action at this time.
0 commit comments