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

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

Issue 1467023002: step toward new completion API (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address comments and merge 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
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 AnalysisRequest, CompletionRequest; 12 show AnalysisRequest, CompletionRequest;
13 import 'package:analysis_server/src/provisional/completion/completion_dart.dart'
14 as newApi;
15 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart'; 13 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart';
16 import 'package:analysis_server/src/services/completion/arglist_contributor.dart '; 14 import 'package:analysis_server/src/services/completion/arglist_contributor.dart ';
17 import 'package:analysis_server/src/services/completion/combinator_contributor.d art'; 15 import 'package:analysis_server/src/services/completion/combinator_contributor.d art';
18 import 'package:analysis_server/src/services/completion/common_usage_computer.da rt'; 16 import 'package:analysis_server/src/services/completion/common_usage_computer.da rt';
19 import 'package:analysis_server/src/services/completion/completion_manager.dart' ; 17 import 'package:analysis_server/src/services/completion/completion_manager.dart' ;
20 import 'package:analysis_server/src/services/completion/contribution_sorter.dart '; 18 import 'package:analysis_server/src/services/completion/contribution_sorter.dart ';
21 import 'package:analysis_server/src/services/completion/dart_completion_cache.da rt'; 19 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'; 20 import 'package:analysis_server/src/services/completion/imported_reference_contr ibutor.dart';
23 import 'package:analysis_server/src/services/completion/keyword_contributor.dart '; 21 import 'package:analysis_server/src/services/completion/keyword_contributor.dart ';
24 import 'package:analysis_server/src/services/completion/local_reference_contribu tor.dart'; 22 import 'package:analysis_server/src/services/completion/local_reference_contribu tor.dart';
25 import 'package:analysis_server/src/services/completion/optype.dart'; 23 import 'package:analysis_server/src/services/completion/optype.dart';
26 import 'package:analysis_server/src/services/completion/prefixed_element_contrib utor.dart'; 24 import 'package:analysis_server/src/services/completion/prefixed_element_contrib utor.dart';
27 import 'package:analysis_server/src/services/completion/uri_contributor.dart'; 25 import 'package:analysis_server/src/services/completion/uri_contributor.dart';
28 import 'package:analysis_server/src/services/search/search_engine.dart'; 26 import 'package:analysis_server/src/services/search/search_engine.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' 27 import 'package:analyzer/src/context/context.dart'
32 show AnalysisFutureHelper, AnalysisContextImpl; 28 show AnalysisFutureHelper, AnalysisContextImpl;
33 import 'package:analyzer/src/generated/ast.dart'; 29 import 'package:analyzer/src/generated/ast.dart';
34 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl; 30 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl;
35 import 'package:analyzer/src/generated/scanner.dart'; 31 import 'package:analyzer/src/generated/scanner.dart';
36 import 'package:analyzer/src/generated/source.dart'; 32 import 'package:analyzer/src/generated/source.dart';
37 import 'package:analyzer/task/model.dart';
38 33
39 const int DART_RELEVANCE_COMMON_USAGE = 1200; 34 const int DART_RELEVANCE_COMMON_USAGE = 1200;
40 const int DART_RELEVANCE_DEFAULT = 1000; 35 const int DART_RELEVANCE_DEFAULT = 1000;
41 const int DART_RELEVANCE_HIGH = 2000; 36 const int DART_RELEVANCE_HIGH = 2000;
42 const int DART_RELEVANCE_INHERITED_ACCESSOR = 1057; 37 const int DART_RELEVANCE_INHERITED_ACCESSOR = 1057;
43 const int DART_RELEVANCE_INHERITED_FIELD = 1058; 38 const int DART_RELEVANCE_INHERITED_FIELD = 1058;
44 const int DART_RELEVANCE_INHERITED_METHOD = 1057; 39 const int DART_RELEVANCE_INHERITED_METHOD = 1057;
45 const int DART_RELEVANCE_KEYWORD = 1055; 40 const int DART_RELEVANCE_KEYWORD = 1055;
46 const int DART_RELEVANCE_LOCAL_ACCESSOR = 1057; 41 const int DART_RELEVANCE_LOCAL_ACCESSOR = 1057;
47 const int DART_RELEVANCE_LOCAL_FIELD = 1058; 42 const int DART_RELEVANCE_LOCAL_FIELD = 1058;
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 parameterNames: suggestion.parameterNames, 447 parameterNames: suggestion.parameterNames,
453 parameterTypes: suggestion.parameterTypes, 448 parameterTypes: suggestion.parameterTypes,
454 requiredParameterCount: suggestion.requiredParameterCount, 449 requiredParameterCount: suggestion.requiredParameterCount,
455 hasNamedParameters: suggestion.hasNamedParameters, 450 hasNamedParameters: suggestion.hasNamedParameters,
456 returnType: suggestion.returnType, 451 returnType: suggestion.returnType,
457 element: suggestion.element); 452 element: suggestion.element);
458 } 453 }
459 } 454 }
460 } 455 }
461 } 456 }
462
463 /**
464 * A wrapper around a new dart completion contributor that makes it usable where
465 * an old dart completion contributor is expected.
466 */
467 class NewCompletionWrapper implements DartCompletionContributor {
468 /**
469 * The new-style contributor that is being wrapped.
470 */
471 final newApi.DartCompletionContributor contributor;
472
473 /**
474 * Initialize a newly created wrapper for the given [contributor].
475 */
476 NewCompletionWrapper(this.contributor);
477
478 @override
479 bool computeFast(DartCompletionRequest request) {
480 List<CompletionSuggestion> suggestions =
481 contributor.computeSuggestions(new OldRequestWrapper(request));
482 if (suggestions == null) {
483 return false;
484 }
485 for (CompletionSuggestion suggestion in suggestions) {
486 request.addSuggestion(suggestion);
487 }
488 return true;
489 }
490
491 @override
492 Future<bool> computeFull(DartCompletionRequest request) async {
493 List<CompletionSuggestion> suggestions =
494 contributor.computeSuggestions(new OldRequestWrapper(request));
495 if (suggestions != null) {
496 for (CompletionSuggestion suggestion in suggestions) {
497 request.addSuggestion(suggestion);
498 }
499 return true;
500 }
501 return false;
502 }
503
504 @override
505 String toString() => 'wrapped $contributor';
506 }
507
508 /**
509 * A wrapper around an old dart completion request that makes it usable where a
510 * new dart completion request is expected.
511 */
512 class OldRequestWrapper implements newApi.DartCompletionRequest {
513 final DartCompletionRequest request;
514
515 OldRequestWrapper(this.request);
516
517 @override
518 AnalysisContext get context => request.context;
519
520 @override
521 bool get isResolved => request.unit.element != null;
522
523 @override
524 int get offset => request.offset;
525
526 @override
527 ResourceProvider get resourceProvider => request.resourceProvider;
528
529 @override
530 Source get source => request.source;
531
532 @override
533 CompletionTarget get target => request.target;
534
535 @override
536 CompilationUnit get unit => request.unit;
537
538 @override
539 String toString() => 'wrapped $request';
540 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698