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

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

Issue 1470373002: create new Dart specific completion contributor extension point (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.manager; 5 library services.completion.dart.manager;
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/provisional/completion/completion_core.dart' 11 import 'package:analysis_server/src/provisional/completion/completion_core.dart'
11 show CompletionContributor, CompletionRequest; 12 show CompletionContributor, CompletionRequest;
12 import 'package:analysis_server/src/provisional/completion/completion_dart.dart' ; 13 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart';
13 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart'; 14 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart';
14 import 'package:analysis_server/src/services/completion/completion_core.dart'; 15 import 'package:analysis_server/src/services/completion/completion_core.dart';
15 import 'package:analysis_server/src/services/completion/dart/keyword_contributor .dart'; 16 import 'package:analysis_server/src/services/completion/dart/keyword_contributor .dart';
16 import 'package:analyzer/file_system/file_system.dart'; 17 import 'package:analyzer/file_system/file_system.dart';
17 import 'package:analyzer/src/context/context.dart' 18 import 'package:analyzer/src/context/context.dart'
18 show AnalysisFutureHelper, AnalysisContextImpl; 19 show AnalysisFutureHelper, AnalysisContextImpl;
19 import 'package:analyzer/src/generated/ast.dart'; 20 import 'package:analyzer/src/generated/ast.dart';
20 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl; 21 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl;
21 import 'package:analyzer/src/generated/source.dart'; 22 import 'package:analyzer/src/generated/source.dart';
22 import 'package:analyzer/src/task/dart.dart'; 23 import 'package:analyzer/src/task/dart.dart';
23 import 'package:analyzer/task/dart.dart'; 24 import 'package:analyzer/task/dart.dart';
24 25
25 /** 26 /**
27 * A factory for constructing the default set of [DartCompletionContributor]s.
28 * Do not call this function directly...
29 * use ServerPlugin.dartCompletionContributorFactories
30 */
31 List<DartCompletionContributor> defaultDartCompletionContributorFactory() =>
32 [new KeywordContributor(),];
33
34 /**
26 * [DartCompletionManager] determines if a completion request is Dart specific 35 * [DartCompletionManager] determines if a completion request is Dart specific
27 * and forwards those requests to all [DartCompletionContributor]s. 36 * and forwards those requests to all [DartCompletionContributor]s.
28 */ 37 */
29 class DartCompletionManager implements CompletionContributor { 38 class DartCompletionManager implements CompletionContributor {
30 // TODO(danrubel) initialize using plugin API
31 List<DartCompletionContributor> contributors = <DartCompletionContributor>[
32 new KeywordContributor(),
33 ];
34
35 @override 39 @override
36 Future<List<CompletionSuggestion>> computeSuggestions( 40 Future<List<CompletionSuggestion>> computeSuggestions(
37 CompletionRequest request) { 41 CompletionRequest request) {
38 if (AnalysisEngine.isDartFileName(request.source.shortName)) { 42 if (AnalysisEngine.isDartFileName(request.source.shortName)) {
39 return _computeDartSuggestions( 43 return _computeDartSuggestions(
40 new DartCompletionRequestImpl.forRequest(request)); 44 new DartCompletionRequestImpl.forRequest(request));
41 } 45 }
42 return new Future.value(); 46 return new Future.value();
43 } 47 }
44 48
45 /** 49 /**
46 * Return a [Future] that completes with a list of suggestions 50 * Return a [Future] that completes with a list of suggestions
47 * for the given completion [request]. 51 * for the given completion [request].
48 */ 52 */
49 Future<List<CompletionSuggestion>> _computeDartSuggestions( 53 Future<List<CompletionSuggestion>> _computeDartSuggestions(
50 DartCompletionRequest request) async { 54 DartCompletionRequest request) async {
55 // Build the Dart specific completion contributors
56 List<DartCompletionContributor> contributors =
57 <DartCompletionContributor>[];
58 for (DartCompletionContributorFactory contributorFactory
59 in request.serverPlugin.dartCompletionContributorFactories) {
60 contributors.addAll(contributorFactory());
61 }
62
63 // Request Dart specific completions from each contributor
51 List<CompletionSuggestion> suggestions = <CompletionSuggestion>[]; 64 List<CompletionSuggestion> suggestions = <CompletionSuggestion>[];
52 for (DartCompletionContributor contributor in contributors) { 65 for (DartCompletionContributor contributor in contributors) {
53 suggestions.addAll(await contributor.computeSuggestions(request)); 66 suggestions.addAll(await contributor.computeSuggestions(request));
54 } 67 }
55 return suggestions; 68 return suggestions;
56 } 69 }
57 } 70 }
58 71
59 /** 72 /**
60 * The information about a requested list of completions within a Dart file. 73 * The information about a requested list of completions within a Dart file.
61 */ 74 */
62 class DartCompletionRequestImpl extends CompletionRequestImpl 75 class DartCompletionRequestImpl extends CompletionRequestImpl
63 implements DartCompletionRequest { 76 implements DartCompletionRequest {
64 /** 77 /**
65 * The cached completion target or `null` if not computed yet. 78 * The cached completion target or `null` if not computed yet.
66 */ 79 */
67 CompletionTarget _target; 80 CompletionTarget _target;
68 81
69 /** 82 /**
70 * `true` if [resolveDeclarationsInScope] has partially resolved the unit 83 * `true` if [resolveDeclarationsInScope] has partially resolved the unit
71 * referenced by [target], else `false`. 84 * referenced by [target], else `false`.
72 */ 85 */
73 bool _haveResolveDeclarationsInScope = false; 86 bool _haveResolveDeclarationsInScope = false;
74 87
75 /** 88 /**
76 * Initialize a newly created completion request based on the given request. 89 * Initialize a newly created completion request based on the given request.
77 */ 90 */
78 factory DartCompletionRequestImpl.forRequest(CompletionRequest request) { 91 factory DartCompletionRequestImpl.forRequest(CompletionRequest request) {
79 return new DartCompletionRequestImpl._(request.context, 92 return new DartCompletionRequestImpl._(request.server, request.context,
80 request.resourceProvider, request.source, request.offset); 93 request.resourceProvider, request.source, request.offset);
81 } 94 }
82 95
83 DartCompletionRequestImpl._(AnalysisContext context, 96 DartCompletionRequestImpl._(AnalysisServer server, AnalysisContext context,
84 ResourceProvider resourceProvider, Source source, int offset) 97 ResourceProvider resourceProvider, Source source, int offset)
85 : super(context, resourceProvider, source, offset); 98 : super(server, context, resourceProvider, source, offset);
86 99
87 @override 100 @override
88 Future<CompilationUnit> resolveDeclarationsInScope() async { 101 Future<CompilationUnit> resolveDeclarationsInScope() async {
89 CompilationUnit unit = target.unit; 102 CompilationUnit unit = target.unit;
90 if (_haveResolveDeclarationsInScope) { 103 if (_haveResolveDeclarationsInScope) {
91 return unit; 104 return unit;
92 } 105 }
93 106
94 // Determine the library source 107 // Determine the library source
95 Source librarySource; 108 Source librarySource;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 140
128 @override 141 @override
129 CompletionTarget get target { 142 CompletionTarget get target {
130 if (_target == null) { 143 if (_target == null) {
131 CompilationUnit unit = context.computeResult(source, PARSED_UNIT); 144 CompilationUnit unit = context.computeResult(source, PARSED_UNIT);
132 _target = new CompletionTarget.forOffset(unit, offset); 145 _target = new CompletionTarget.forOffset(unit, offset);
133 } 146 }
134 return _target; 147 return _target;
135 } 148 }
136 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698