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

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

Issue 1449333002: process sorter analysis request(s) (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/domain_completion_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.dart; 5 library services.completion.dart;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; 9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:analysis_server/src/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
11 import 'package:analysis_server/src/provisional/completion/completion_core.dart' 11 import 'package:analysis_server/src/provisional/completion/completion_core.dart'
12 show CompletionRequest; 12 show AnalysisRequest, CompletionRequest;
13 import 'package:analysis_server/src/provisional/completion/completion_dart.dart' 13 import 'package:analysis_server/src/provisional/completion/completion_dart.dart'
14 as newApi; 14 as newApi;
15 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart'; 15 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart';
16 import 'package:analysis_server/src/services/completion/arglist_contributor.dart '; 16 import 'package:analysis_server/src/services/completion/arglist_contributor.dart ';
17 import 'package:analysis_server/src/services/completion/combinator_contributor.d art'; 17 import 'package:analysis_server/src/services/completion/combinator_contributor.d art';
18 import 'package:analysis_server/src/services/completion/common_usage_computer.da rt'; 18 import 'package:analysis_server/src/services/completion/common_usage_computer.da rt';
19 import 'package:analysis_server/src/services/completion/completion_manager.dart' ; 19 import 'package:analysis_server/src/services/completion/completion_manager.dart' ;
20 import 'package:analysis_server/src/services/completion/contribution_sorter.dart '; 20 import 'package:analysis_server/src/services/completion/contribution_sorter.dart ';
21 import 'package:analysis_server/src/services/completion/dart_completion_cache.da rt'; 21 import 'package:analysis_server/src/services/completion/dart_completion_cache.da rt';
22 import 'package:analysis_server/src/services/completion/imported_reference_contr ibutor.dart'; 22 import 'package:analysis_server/src/services/completion/imported_reference_contr ibutor.dart';
23 import 'package:analysis_server/src/services/completion/keyword_contributor.dart '; 23 import 'package:analysis_server/src/services/completion/keyword_contributor.dart ';
24 import 'package:analysis_server/src/services/completion/local_reference_contribu tor.dart'; 24 import 'package:analysis_server/src/services/completion/local_reference_contribu tor.dart';
25 import 'package:analysis_server/src/services/completion/optype.dart'; 25 import 'package:analysis_server/src/services/completion/optype.dart';
26 import 'package:analysis_server/src/services/completion/prefixed_element_contrib utor.dart'; 26 import 'package:analysis_server/src/services/completion/prefixed_element_contrib utor.dart';
27 import 'package:analysis_server/src/services/completion/uri_contributor.dart'; 27 import 'package:analysis_server/src/services/completion/uri_contributor.dart';
28 import 'package:analysis_server/src/services/search/search_engine.dart'; 28 import 'package:analysis_server/src/services/search/search_engine.dart';
29 import 'package:analyzer/file_system/file_system.dart'; 29 import 'package:analyzer/file_system/file_system.dart';
30 import 'package:analyzer/src/cancelable_future.dart';
31 import 'package:analyzer/src/context/context.dart'
32 show AnalysisFutureHelper, AnalysisContextImpl;
30 import 'package:analyzer/src/generated/ast.dart'; 33 import 'package:analyzer/src/generated/ast.dart';
31 import 'package:analyzer/src/generated/engine.dart'; 34 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl;
32 import 'package:analyzer/src/generated/scanner.dart'; 35 import 'package:analyzer/src/generated/scanner.dart';
33 import 'package:analyzer/src/generated/source.dart'; 36 import 'package:analyzer/src/generated/source.dart';
37 import 'package:analyzer/task/model.dart';
34 38
35 const int DART_RELEVANCE_COMMON_USAGE = 1200; 39 const int DART_RELEVANCE_COMMON_USAGE = 1200;
36 const int DART_RELEVANCE_DEFAULT = 1000; 40 const int DART_RELEVANCE_DEFAULT = 1000;
37 const int DART_RELEVANCE_HIGH = 2000; 41 const int DART_RELEVANCE_HIGH = 2000;
38 const int DART_RELEVANCE_INHERITED_ACCESSOR = 1057; 42 const int DART_RELEVANCE_INHERITED_ACCESSOR = 1057;
39 const int DART_RELEVANCE_INHERITED_FIELD = 1058; 43 const int DART_RELEVANCE_INHERITED_FIELD = 1058;
40 const int DART_RELEVANCE_INHERITED_METHOD = 1057; 44 const int DART_RELEVANCE_INHERITED_METHOD = 1057;
41 const int DART_RELEVANCE_KEYWORD = 1055; 45 const int DART_RELEVANCE_KEYWORD = 1055;
42 const int DART_RELEVANCE_LOCAL_ACCESSOR = 1057; 46 const int DART_RELEVANCE_LOCAL_ACCESSOR = 1057;
43 const int DART_RELEVANCE_LOCAL_FIELD = 1058; 47 const int DART_RELEVANCE_LOCAL_FIELD = 1058;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 178 }
175 } 179 }
176 } 180 }
177 181
178 List<DartCompletionContributor> todo = new List.from(contributors); 182 List<DartCompletionContributor> todo = new List.from(contributors);
179 todo.removeWhere((DartCompletionContributor c) { 183 todo.removeWhere((DartCompletionContributor c) {
180 return performance.logElapseTime('computeFast ${c.runtimeType}', () { 184 return performance.logElapseTime('computeFast ${c.runtimeType}', () {
181 return c.computeFast(request); 185 return c.computeFast(request);
182 }); 186 });
183 }); 187 });
184 // TODO(danrubel) Process the AnalysisRequest returned by the 188 _processAnalysisRequest(request,
185 // contribution sorter. At this point, the target unit has been fully 189 contributionSorter.sort(request, request.suggestions));
186 // resolved, thus no need for additional resolution, but in the future... 190 // TODO (danrubel) if request is obsolete
187 contributionSorter.sort(request, request.suggestions); 191 // (processAnalysisRequest returns false)
188 192 // then send empty results
189 if (todo.isEmpty) { 193 if (todo.isEmpty) {
190 sendResults(request, todo.isEmpty); 194 sendResults(request, todo.isEmpty);
Brian Wilkerson 2015/11/17 15:11:37 If I understand correctly, this will only work if
danrubel 2015/11/17 18:35:44 Correct. Per discussion, I will be adding support
191 } 195 }
192 return todo; 196 return todo;
193 }); 197 });
194 } 198 }
195 199
196 /** 200 /**
197 * If there is remaining work to be done, then wait for the unit to be 201 * If there is remaining work to be done, then wait for the unit to be
198 * resolved and request that each remaining contributor finish their work. 202 * resolved and request that each remaining contributor finish their work.
199 * Return a [Future] that completes when the last notification has been sent. 203 * Return a [Future] that completes when the last notification has been sent.
200 */ 204 */
(...skipping 17 matching lines...) Expand all
218 int count = todo.length; 222 int count = todo.length;
219 todo.forEach((DartCompletionContributor c) { 223 todo.forEach((DartCompletionContributor c) {
220 String name = c.runtimeType.toString(); 224 String name = c.runtimeType.toString();
221 String completeTag = 'computeFull $name complete'; 225 String completeTag = 'computeFull $name complete';
222 performance.logStartTime(completeTag); 226 performance.logStartTime(completeTag);
223 performance.logElapseTime('computeFull $name', () { 227 performance.logElapseTime('computeFull $name', () {
224 c.computeFull(request).then((bool changed) { 228 c.computeFull(request).then((bool changed) {
225 performance.logElapseTime(completeTag); 229 performance.logElapseTime(completeTag);
226 bool last = --count == 0; 230 bool last = --count == 0;
227 if (changed || last) { 231 if (changed || last) {
228 // TODO(danrubel) Process the AnalysisRequest returned by the 232 _processAnalysisRequest(request,
229 // contribution sorter. At this point, the target unit has been 233 contributionSorter.sort(request, request.suggestions));
230 // fully resolved, thus no need for additional resolution, 234 // TODO (danrubel) if request is obsolete
231 // but in the future... 235 // (processAnalysisRequest returns false)
232 contributionSorter.sort(request, request.suggestions); 236 // then send empty results
233 sendResults(request, last); 237 sendResults(request, last);
234 } 238 }
235 }); 239 });
236 }); 240 });
237 }); 241 });
238 }); 242 });
239 }); 243 });
240 } 244 }
241 245
242 @override 246 @override
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 Source libSource = libraries[0]; 284 Source libSource = libraries[0];
281 assert(libSource != null); 285 assert(libSource != null);
282 return context 286 return context
283 .computeResolvedCompilationUnitAsync(source, libSource) 287 .computeResolvedCompilationUnitAsync(source, libSource)
284 .catchError((_) { 288 .catchError((_) {
285 // This source file is not scheduled for analysis, so a resolved 289 // This source file is not scheduled for analysis, so a resolved
286 // compilation unit is never going to get computed. 290 // compilation unit is never going to get computed.
287 return null; 291 return null;
288 }, test: (e) => e is AnalysisNotScheduledError); 292 }, test: (e) => e is AnalysisNotScheduledError);
289 } 293 }
294
295 /**
296 * Process the analysis [analysis] and any subsequent requests.
297 * Return a [Future] that returns `true`
298 * once all analysis requests have been processed
299 * or `false` if the original completion request is obsolete
300 * and processing requests was terminated before finished.
301 */
302 Future<bool> _processAnalysisRequest(
303 CompletionRequest request, AnalysisRequest analysis) {
304 // Return if no additional analysis is necessary
305 if (analysis == null) {
306 return new Future.value(true);
307 }
308
309 // Check to see if the result is already cached
310 var cachedValue = context.getResult(analysis.target, analysis.descriptor);
311 if (cachedValue != null) {
312 return _processAnalysisRequest(
313 request, analysis.callback(request, cachedValue));
314 }
315
316 // TODO (danrubel) determine when completion request is obsolete
317 // and analysis should be terminated before requesting additional analysis
318
319 // Request additional analysis
320 return new AnalysisFutureHelper((context as AnalysisContextImpl),
321 analysis.target, analysis.descriptor).computeAsync().then((value) {
322 return _processAnalysisRequest(
323 request, analysis.callback(request, cachedValue));
324 });
325 }
290 } 326 }
291 327
292 /** 328 /**
293 * The context in which the completion is requested. 329 * The context in which the completion is requested.
294 */ 330 */
295 class DartCompletionRequest extends CompletionRequestImpl { 331 class DartCompletionRequest extends CompletionRequestImpl {
296 /** 332 /**
297 * Cached information from a prior code completion operation. 333 * Cached information from a prior code completion operation.
298 */ 334 */
299 final DartCompletionCache cache; 335 final DartCompletionCache cache;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 531
496 @override 532 @override
497 CompletionTarget get target => request.target; 533 CompletionTarget get target => request.target;
498 534
499 @override 535 @override
500 CompilationUnit get unit => request.unit; 536 CompilationUnit get unit => request.unit;
501 537
502 @override 538 @override
503 String toString() => 'wrapped $request'; 539 String toString() => 'wrapped $request';
504 } 540 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/domain_completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698