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

Side by Side Diff: pkg/analysis_server/lib/src/plugin/server_plugin.dart

Issue 1095143002: Initial version of completion plugin API (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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) 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 analysis_server.src.plugin.server_plugin; 5 library analysis_server.src.plugin.server_plugin;
6 6
7 import 'package:analysis_server/completion/completion_core.dart';
7 import 'package:analysis_server/edit/assist/assist_core.dart'; 8 import 'package:analysis_server/edit/assist/assist_core.dart';
8 import 'package:analysis_server/edit/fix/fix_core.dart'; 9 import 'package:analysis_server/edit/fix/fix_core.dart';
9 import 'package:analysis_server/plugin/assist.dart'; 10 import 'package:analysis_server/plugin/assist.dart';
11 //import 'package:analysis_server/plugin/completion.dart';
10 import 'package:analysis_server/plugin/fix.dart'; 12 import 'package:analysis_server/plugin/fix.dart';
11 import 'package:analysis_server/src/analysis_server.dart'; 13 import 'package:analysis_server/src/analysis_server.dart';
12 import 'package:analysis_server/src/domain_analysis.dart'; 14 import 'package:analysis_server/src/domain_analysis.dart';
13 import 'package:analysis_server/src/domain_completion.dart'; 15 import 'package:analysis_server/src/domain_completion.dart';
14 import 'package:analysis_server/src/domain_execution.dart'; 16 import 'package:analysis_server/src/domain_execution.dart';
15 import 'package:analysis_server/src/domain_server.dart'; 17 import 'package:analysis_server/src/domain_server.dart';
16 import 'package:analysis_server/src/edit/edit_domain.dart'; 18 import 'package:analysis_server/src/edit/edit_domain.dart';
17 import 'package:analysis_server/src/protocol.dart'; 19 import 'package:analysis_server/src/protocol.dart';
18 import 'package:analysis_server/src/search/search_domain.dart'; 20 import 'package:analysis_server/src/search/search_domain.dart';
19 import 'package:analysis_server/src/services/correction/assist_internal.dart'; 21 import 'package:analysis_server/src/services/correction/assist_internal.dart';
(...skipping 12 matching lines...) Expand all
32 */ 34 */
33 class ServerPlugin implements Plugin { 35 class ServerPlugin implements Plugin {
34 /** 36 /**
35 * The simple identifier of the extension point that allows plugins to 37 * The simple identifier of the extension point that allows plugins to
36 * register new assist contributors with the server. 38 * register new assist contributors with the server.
37 */ 39 */
38 static const String ASSIST_CONTRIBUTOR_EXTENSION_POINT = 'assistContributor'; 40 static const String ASSIST_CONTRIBUTOR_EXTENSION_POINT = 'assistContributor';
39 41
40 /** 42 /**
41 * The simple identifier of the extension point that allows plugins to 43 * The simple identifier of the extension point that allows plugins to
44 * register new completion contributors with the server.
45 */
46 static const String COMPLETION_CONTRIBUTOR_EXTENSION_POINT =
47 'completionContributor';
48
49 /**
50 * The simple identifier of the extension point that allows plugins to
42 * register new domains with the server. 51 * register new domains with the server.
43 */ 52 */
44 static const String DOMAIN_EXTENSION_POINT = 'domain'; 53 static const String DOMAIN_EXTENSION_POINT = 'domain';
45 54
46 /** 55 /**
47 * The simple identifier of the extension point that allows plugins to 56 * The simple identifier of the extension point that allows plugins to
48 * register new fix contributors with the server. 57 * register new fix contributors with the server.
49 */ 58 */
50 static const String FIX_CONTRIBUTOR_EXTENSION_POINT = 'fixContributor'; 59 static const String FIX_CONTRIBUTOR_EXTENSION_POINT = 'fixContributor';
51 60
52 /** 61 /**
53 * The unique identifier of this plugin. 62 * The unique identifier of this plugin.
54 */ 63 */
55 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; 64 static const String UNIQUE_IDENTIFIER = 'analysis_server.core';
56 65
57 /** 66 /**
58 * The extension point that allows plugins to register new assist contributors 67 * The extension point that allows plugins to register new assist contributors
59 * with the server. 68 * with the server.
60 */ 69 */
61 ExtensionPoint assistContributorExtensionPoint; 70 ExtensionPoint assistContributorExtensionPoint;
62 71
63 /** 72 /**
73 * The extension point that allows plugins to register new completion
74 * contributors with the server.
75 */
76 ExtensionPoint completionContributorExtensionPoint;
77
78 /**
64 * The extension point that allows plugins to register new domains with the 79 * The extension point that allows plugins to register new domains with the
65 * server. 80 * server.
66 */ 81 */
67 ExtensionPoint domainExtensionPoint; 82 ExtensionPoint domainExtensionPoint;
68 83
69 /** 84 /**
70 * The extension point that allows plugins to register new fix contributors 85 * The extension point that allows plugins to register new fix contributors
71 * with the server. 86 * with the server.
72 */ 87 */
73 ExtensionPoint fixContributorExtensionPoint; 88 ExtensionPoint fixContributorExtensionPoint;
74 89
75 /** 90 /**
76 * Initialize a newly created plugin. 91 * Initialize a newly created plugin.
77 */ 92 */
78 ServerPlugin(); 93 ServerPlugin();
79 94
95 /**
96 * Return a list containing all of the assist contributors that were
97 * contributed.
98 */
99 List<AssistContributor> get assistContributors =>
100 assistContributorExtensionPoint.extensions;
101
102 /**
103 * Return a list containing all of the completion contributors that were
104 * contributed.
105 */
106 List<CompletionContributor> get completionContributors =>
107 completionContributorExtensionPoint.extensions;
108
109 /**
110 * Return a list containing all of the fix contributors that were contributed.
111 */
112 List<FixContributor> get fixContributors =>
113 fixContributorExtensionPoint.extensions;
114
80 @override 115 @override
81 String get uniqueIdentifier => UNIQUE_IDENTIFIER; 116 String get uniqueIdentifier => UNIQUE_IDENTIFIER;
82 117
83 /** 118 /**
84 * Return a list containing all of the fix contributors that were contributed.
85 */
86 List<AssistContributor> assistContributors() {
87 return assistContributorExtensionPoint.extensions;
88 }
89
90 /**
91 * Use the given [server] to create all of the domains ([RequestHandler]'s) 119 * Use the given [server] to create all of the domains ([RequestHandler]'s)
92 * that have been registered and return the newly created domains. 120 * that have been registered and return the newly created domains.
93 */ 121 */
94 List<RequestHandler> createDomains(AnalysisServer server) { 122 List<RequestHandler> createDomains(AnalysisServer server) {
95 if (domainExtensionPoint == null) { 123 if (domainExtensionPoint == null) {
96 return <RequestHandler>[]; 124 return <RequestHandler>[];
97 } 125 }
98 return domainExtensionPoint.extensions 126 return domainExtensionPoint.extensions
99 .map((RequestHandlerFactory factory) => factory(server)) 127 .map((RequestHandlerFactory factory) => factory(server))
100 .toList(); 128 .toList();
101 } 129 }
102 130
103 /**
104 * Return a list containing all of the fix contributors that were contributed.
105 */
106 List<FixContributor> fixContributors() {
107 return fixContributorExtensionPoint.extensions;
108 }
109
110 @override 131 @override
111 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { 132 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) {
112 assistContributorExtensionPoint = registerExtensionPoint( 133 assistContributorExtensionPoint = registerExtensionPoint(
113 ASSIST_CONTRIBUTOR_EXTENSION_POINT, 134 ASSIST_CONTRIBUTOR_EXTENSION_POINT,
114 _validateAssistContributorExtension); 135 _validateAssistContributorExtension);
136 completionContributorExtensionPoint = registerExtensionPoint(
137 COMPLETION_CONTRIBUTOR_EXTENSION_POINT,
138 _validateCompletionContributorExtension);
115 domainExtensionPoint = registerExtensionPoint( 139 domainExtensionPoint = registerExtensionPoint(
116 DOMAIN_EXTENSION_POINT, _validateDomainExtension); 140 DOMAIN_EXTENSION_POINT, _validateDomainExtension);
117 fixContributorExtensionPoint = registerExtensionPoint( 141 fixContributorExtensionPoint = registerExtensionPoint(
118 FIX_CONTRIBUTOR_EXTENSION_POINT, _validateFixContributorExtension); 142 FIX_CONTRIBUTOR_EXTENSION_POINT, _validateFixContributorExtension);
119 } 143 }
120 144
121 @override 145 @override
122 void registerExtensions(RegisterExtension registerExtension) { 146 void registerExtensions(RegisterExtension registerExtension) {
123 // 147 //
124 // Register assist contributors. 148 // Register assist contributors.
125 // 149 //
126 registerExtension( 150 registerExtension(
127 ASSIST_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultAssistContributor()); 151 ASSIST_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultAssistContributor());
128 // 152 //
153 // Register completion contributors.
154 //
155 // TODO(brianwilkerson) Register the completion contributors.
156 // registerExtension(
157 // COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID, ???);
158 //
129 // Register domains. 159 // Register domains.
130 // 160 //
131 String domainId = Plugin.join(UNIQUE_IDENTIFIER, DOMAIN_EXTENSION_POINT); 161 String domainId = Plugin.join(UNIQUE_IDENTIFIER, DOMAIN_EXTENSION_POINT);
132 registerExtension( 162 registerExtension(
133 domainId, (AnalysisServer server) => new ServerDomainHandler(server)); 163 domainId, (AnalysisServer server) => new ServerDomainHandler(server));
134 registerExtension( 164 registerExtension(
135 domainId, (AnalysisServer server) => new AnalysisDomainHandler(server)); 165 domainId, (AnalysisServer server) => new AnalysisDomainHandler(server));
136 registerExtension(domainId, 166 registerExtension(domainId,
137 (AnalysisServer server) => new EditDomainHandler(server, this)); 167 (AnalysisServer server) => new EditDomainHandler(server, this));
138 registerExtension( 168 registerExtension(
139 domainId, (AnalysisServer server) => new SearchDomainHandler(server)); 169 domainId, (AnalysisServer server) => new SearchDomainHandler(server));
140 registerExtension(domainId, 170 registerExtension(domainId,
141 (AnalysisServer server) => new CompletionDomainHandler(server)); 171 (AnalysisServer server) => new CompletionDomainHandler(server));
142 registerExtension(domainId, 172 registerExtension(domainId,
143 (AnalysisServer server) => new ExecutionDomainHandler(server)); 173 (AnalysisServer server) => new ExecutionDomainHandler(server));
144 // 174 //
145 // Register fix contributors. 175 // Register fix contributors.
146 // 176 //
147 registerExtension( 177 registerExtension(
148 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor()); 178 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor());
149 } 179 }
150 180
151 /** 181 /**
152 * Validate the given extension by throwing an [ExtensionError] if it is not a 182 * Validate the given extension by throwing an [ExtensionError] if it is not a
153 * valid fix contributor. 183 * valid assist contributor.
154 */ 184 */
155 void _validateAssistContributorExtension(Object extension) { 185 void _validateAssistContributorExtension(Object extension) {
156 if (extension is! AssistContributor) { 186 if (extension is! AssistContributor) {
157 String id = assistContributorExtensionPoint.uniqueIdentifier; 187 String id = assistContributorExtensionPoint.uniqueIdentifier;
158 throw new ExtensionError( 188 throw new ExtensionError(
159 'Extensions to $id must be an AssistContributor'); 189 'Extensions to $id must be an AssistContributor');
160 } 190 }
161 } 191 }
162 192
163 /** 193 /**
164 * Validate the given extension by throwing an [ExtensionError] if it is not a 194 * Validate the given extension by throwing an [ExtensionError] if it is not a
195 * valid completion contributor.
196 */
197 void _validateCompletionContributorExtension(Object extension) {
198 if (extension is! CompletionContributor) {
199 String id = completionContributorExtensionPoint.uniqueIdentifier;
200 throw new ExtensionError(
201 'Extensions to $id must be an CompletionContributor');
202 }
203 }
204
205 /**
206 * Validate the given extension by throwing an [ExtensionError] if it is not a
165 * valid domain. 207 * valid domain.
166 */ 208 */
167 void _validateDomainExtension(Object extension) { 209 void _validateDomainExtension(Object extension) {
168 if (extension is! RequestHandlerFactory) { 210 if (extension is! RequestHandlerFactory) {
169 String id = domainExtensionPoint.uniqueIdentifier; 211 String id = domainExtensionPoint.uniqueIdentifier;
170 throw new ExtensionError( 212 throw new ExtensionError(
171 'Extensions to $id must be a RequestHandlerFactory'); 213 'Extensions to $id must be a RequestHandlerFactory');
172 } 214 }
173 } 215 }
174 216
175 /** 217 /**
176 * Validate the given extension by throwing an [ExtensionError] if it is not a 218 * Validate the given extension by throwing an [ExtensionError] if it is not a
177 * valid fix contributor. 219 * valid fix contributor.
178 */ 220 */
179 void _validateFixContributorExtension(Object extension) { 221 void _validateFixContributorExtension(Object extension) {
180 if (extension is! FixContributor) { 222 if (extension is! FixContributor) {
181 String id = fixContributorExtensionPoint.uniqueIdentifier; 223 String id = fixContributorExtensionPoint.uniqueIdentifier;
182 throw new ExtensionError('Extensions to $id must be a FixContributor'); 224 throw new ExtensionError('Extensions to $id must be a FixContributor');
183 } 225 }
184 } 226 }
185 } 227 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/completion/completion_dart.dart ('k') | pkg/analysis_server/lib/src/services/correction/assist.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698