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

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

Issue 1115843003: restructure internal request to implement CompletionRequest API, (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library services.completion.manager; 5 library services.completion.manager;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/completion/completion_core.dart'
10 show CompletionRequest;
11 import 'package:analysis_server/src/analysis_server.dart';
9 import 'package:analysis_server/src/protocol.dart'; 12 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 13 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
11 import 'package:analysis_server/src/services/search/search_engine.dart'; 14 import 'package:analysis_server/src/services/search/search_engine.dart';
15 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 16 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
14 18
15 /** 19 /**
16 * [CompletionCache] contains information about the prior code completion 20 * [CompletionCache] contains information about the prior code completion
17 * for use in the next code completion. 21 * for use in the next code completion.
18 */ 22 */
19 abstract class CompletionCache { 23 abstract class CompletionCache {
20 24
21 /** 25 /**
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 String snippet = ''; 127 String snippet = '';
124 int notificationCount = -1; 128 int notificationCount = -1;
125 int suggestionCountFirst = -1; 129 int suggestionCountFirst = -1;
126 int suggestionCountLast = -1; 130 int suggestionCountLast = -1;
127 Duration _firstNotification; 131 Duration _firstNotification;
128 132
129 CompletionPerformance() { 133 CompletionPerformance() {
130 _stopwatch.start(); 134 _stopwatch.start();
131 } 135 }
132 136
133 void setContentsAndOffset(String contents, int offset) {
134 snippet = _computeSnippet(contents, offset);
135 }
136
137 int get elapsedInMilliseconds => 137 int get elapsedInMilliseconds =>
138 operations.length > 0 ? operations.last.elapsed.inMilliseconds : 0; 138 operations.length > 0 ? operations.last.elapsed.inMilliseconds : 0;
139 139
140 int get firstNotificationInMilliseconds => 140 int get firstNotificationInMilliseconds =>
141 _firstNotification != null ? _firstNotification.inMilliseconds : 0; 141 _firstNotification != null ? _firstNotification.inMilliseconds : 0;
142 142
143 String get startTimeAndMs => '${start.millisecondsSinceEpoch} - $start'; 143 String get startTimeAndMs => '${start.millisecondsSinceEpoch} - $start';
144 144
145 String get suggestionCount { 145 String get suggestionCount {
146 if (notificationCount < 1) return ''; 146 if (notificationCount < 1) return '';
(...skipping 27 matching lines...) Expand all
174 174
175 void logFirstNotificationComplete(String tag) { 175 void logFirstNotificationComplete(String tag) {
176 _firstNotification = _stopwatch.elapsed; 176 _firstNotification = _stopwatch.elapsed;
177 _logDuration(tag, _firstNotification); 177 _logDuration(tag, _firstNotification);
178 } 178 }
179 179
180 void logStartTime(String tag) { 180 void logStartTime(String tag) {
181 _startTimes[tag] = _stopwatch.elapsed; 181 _startTimes[tag] = _stopwatch.elapsed;
182 } 182 }
183 183
184 void setContentsAndOffset(String contents, int offset) {
185 snippet = _computeSnippet(contents, offset);
186 }
187
184 void _logDuration(String tag, Duration elapsed) { 188 void _logDuration(String tag, Duration elapsed) {
185 operations.add(new OperationPerformance(tag, elapsed)); 189 operations.add(new OperationPerformance(tag, elapsed));
186 } 190 }
187 191
188 static String _computeSnippet(String contents, int offset) { 192 static String _computeSnippet(String contents, int offset) {
189 if (contents == null || 193 if (contents == null ||
190 offset == null || 194 offset == null ||
191 offset < 0 || 195 offset < 0 ||
192 contents.length < offset) { 196 contents.length < offset) {
193 return '???'; 197 return '???';
(...skipping 16 matching lines...) Expand all
210 } 214 }
211 String prefix = contents.substring(start, offset); 215 String prefix = contents.substring(start, offset);
212 String suffix = contents.substring(offset, end); 216 String suffix = contents.substring(offset, end);
213 return '$prefix^$suffix'; 217 return '$prefix^$suffix';
214 } 218 }
215 } 219 }
216 220
217 /** 221 /**
218 * Encapsulates information specific to a particular completion request. 222 * Encapsulates information specific to a particular completion request.
219 */ 223 */
220 class CompletionRequest { 224 class CompletionRequestImpl implements CompletionRequest {
225
221 /** 226 /**
222 * The offset within the source at which the completion is requested. 227 * The underlying analysis server for this completion request.
223 */ 228 */
229 final AnalysisServer server;
230
231 @override
232 final AnalysisContext context;
233
234 @override
235 final Source source;
236
237 @override
224 final int offset; 238 final int offset;
225 239
226 /** 240 CompletionRequestImpl(this.server, this.context, this.source, this.offset);
227 * Performance measurements for this particular request.
228 */
229 final CompletionPerformance performance;
230 241
231 CompletionRequest(this.offset, this.performance); 242 @override
243 ResourceProvider get provider => server.resourceProvider;
232 } 244 }
233 245
234 /** 246 /**
235 * Code completion result generated by an [CompletionManager]. 247 * Code completion result generated by an [CompletionManager].
236 */ 248 */
237 class CompletionResult { 249 class CompletionResult {
238 250
239 /** 251 /**
240 * The length of the text to be replaced if the remainder of the identifier 252 * The length of the text to be replaced if the remainder of the identifier
241 * containing the cursor is to be replaced when the suggestion is applied 253 * containing the cursor is to be replaced when the suggestion is applied
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 */ 297 */
286 final String name; 298 final String name;
287 299
288 /** 300 /**
289 * The elapse time or `null` if undefined. 301 * The elapse time or `null` if undefined.
290 */ 302 */
291 final Duration elapsed; 303 final Duration elapsed;
292 304
293 OperationPerformance(this.name, this.elapsed); 305 OperationPerformance(this.name, this.elapsed);
294 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698