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

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

Issue 1152013002: Add support for specifying files needing analysis (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
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
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/analysis/index/index_core.dart'; 7 import 'package:analysis_server/analysis/index/index_core.dart';
8 import 'package:analysis_server/completion/completion_core.dart'; 8 import 'package:analysis_server/completion/completion_core.dart';
9 import 'package:analysis_server/edit/assist/assist_core.dart'; 9 import 'package:analysis_server/edit/assist/assist_core.dart';
10 import 'package:analysis_server/edit/fix/fix_core.dart'; 10 import 'package:analysis_server/edit/fix/fix_core.dart';
11 import 'package:analysis_server/plugin/analyzed_files.dart';
11 import 'package:analysis_server/plugin/assist.dart'; 12 import 'package:analysis_server/plugin/assist.dart';
12 //import 'package:analysis_server/plugin/completion.dart';
13 import 'package:analysis_server/plugin/fix.dart'; 13 import 'package:analysis_server/plugin/fix.dart';
14 import 'package:analysis_server/src/analysis_server.dart'; 14 import 'package:analysis_server/src/analysis_server.dart';
15 import 'package:analysis_server/src/domain_analysis.dart'; 15 import 'package:analysis_server/src/domain_analysis.dart';
16 import 'package:analysis_server/src/domain_completion.dart'; 16 import 'package:analysis_server/src/domain_completion.dart';
17 import 'package:analysis_server/src/domain_execution.dart'; 17 import 'package:analysis_server/src/domain_execution.dart';
18 import 'package:analysis_server/src/domain_server.dart'; 18 import 'package:analysis_server/src/domain_server.dart';
19 import 'package:analysis_server/src/edit/edit_domain.dart'; 19 import 'package:analysis_server/src/edit/edit_domain.dart';
20 import 'package:analysis_server/src/protocol.dart'; 20 import 'package:analysis_server/src/protocol.dart';
21 import 'package:analysis_server/src/search/search_domain.dart'; 21 import 'package:analysis_server/src/search/search_domain.dart';
22 import 'package:analysis_server/src/services/correction/assist_internal.dart'; 22 import 'package:analysis_server/src/services/correction/assist_internal.dart';
23 import 'package:analysis_server/src/services/correction/fix_internal.dart'; 23 import 'package:analysis_server/src/services/correction/fix_internal.dart';
24 import 'package:analyzer/file_system/file_system.dart';
25 import 'package:analyzer/src/generated/engine.dart';
24 import 'package:plugin/plugin.dart'; 26 import 'package:plugin/plugin.dart';
25 27
26 /** 28 /**
27 * A function that will create a request handler that can be used by the given 29 * A function that will create a request handler that can be used by the given
28 * [server]. 30 * [server].
29 */ 31 */
30 typedef RequestHandler RequestHandlerFactory(AnalysisServer server); 32 typedef RequestHandler RequestHandlerFactory(AnalysisServer server);
31 33
32 /** 34 /**
33 * A plugin that defines the extension points and extensions that are inherently 35 * A plugin that defines the extension points and extensions that are inherently
34 * defined by the analysis server. 36 * defined by the analysis server.
35 */ 37 */
36 class ServerPlugin implements Plugin { 38 class ServerPlugin implements Plugin {
37 /** 39 /**
38 * The simple identifier of the extension point that allows plugins to 40 * The simple identifier of the extension point that allows plugins to
39 * register new assist contributors with the server. 41 * register functions that can cause files to be analyzed.
42 */
43 static const String ANALYZE_FILE_EXTENSION_POINT = 'analyzeFile';
44
45 /**
46 * The simple identifier of the extension point that allows plugins to
47 * register assist contributors.
40 */ 48 */
41 static const String ASSIST_CONTRIBUTOR_EXTENSION_POINT = 'assistContributor'; 49 static const String ASSIST_CONTRIBUTOR_EXTENSION_POINT = 'assistContributor';
42 50
43 /** 51 /**
44 * The simple identifier of the extension point that allows plugins to 52 * The simple identifier of the extension point that allows plugins to
45 * register new completion contributors with the server. 53 * register completion contributors.
46 */ 54 */
47 static const String COMPLETION_CONTRIBUTOR_EXTENSION_POINT = 55 static const String COMPLETION_CONTRIBUTOR_EXTENSION_POINT =
48 'completionContributor'; 56 'completionContributor';
49 57
50 /** 58 /**
51 * The simple identifier of the extension point that allows plugins to 59 * The simple identifier of the extension point that allows plugins to
52 * register new domains with the server. 60 * register domains.
53 */ 61 */
54 static const String DOMAIN_EXTENSION_POINT = 'domain'; 62 static const String DOMAIN_EXTENSION_POINT = 'domain';
55 63
56 /** 64 /**
57 * The simple identifier of the extension point that allows plugins to 65 * The simple identifier of the extension point that allows plugins to
58 * register new fix contributors with the server. 66 * register fix contributors.
59 */ 67 */
60 static const String FIX_CONTRIBUTOR_EXTENSION_POINT = 'fixContributor'; 68 static const String FIX_CONTRIBUTOR_EXTENSION_POINT = 'fixContributor';
61 69
62 /** 70 /**
63 * The simple identifier of the extension point that allows plugins to 71 * The simple identifier of the extension point that allows plugins to
64 * register new index contributors with the server. 72 * register index contributors.
65 */ 73 */
66 static const String INDEX_CONTRIBUTOR_EXTENSION_POINT = 'indexContributor'; 74 static const String INDEX_CONTRIBUTOR_EXTENSION_POINT = 'indexContributor';
67 75
68 /** 76 /**
69 * The unique identifier of this plugin. 77 * The unique identifier of this plugin.
70 */ 78 */
71 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; 79 static const String UNIQUE_IDENTIFIER = 'analysis_server.core';
72 80
73 /** 81 /**
74 * The extension point that allows plugins to register new assist contributors 82 * The extension point that allows plugins to register functions that can
75 * with the server. 83 * cause files to be analyzed.
84 */
85 ExtensionPoint analyzeFileExtensionPoint;
86
87 /**
88 * The extension point that allows plugins to register assist contributors.
76 */ 89 */
77 ExtensionPoint assistContributorExtensionPoint; 90 ExtensionPoint assistContributorExtensionPoint;
78 91
79 /** 92 /**
80 * The extension point that allows plugins to register new completion 93 * The extension point that allows plugins to register completion
81 * contributors with the server. 94 * contributors.
82 */ 95 */
83 ExtensionPoint completionContributorExtensionPoint; 96 ExtensionPoint completionContributorExtensionPoint;
84 97
85 /** 98 /**
86 * The extension point that allows plugins to register new domains with the 99 * The extension point that allows plugins to register domains with the
87 * server. 100 * server.
88 */ 101 */
89 ExtensionPoint domainExtensionPoint; 102 ExtensionPoint domainExtensionPoint;
90 103
91 /** 104 /**
92 * The extension point that allows plugins to register new fix contributors 105 * The extension point that allows plugins to register fix contributors with
93 * with the server. 106 * the server.
94 */ 107 */
95 ExtensionPoint fixContributorExtensionPoint; 108 ExtensionPoint fixContributorExtensionPoint;
96 109
97 /** 110 /**
98 * The extension point that allows plugins to register new index contributors 111 * The extension point that allows plugins to register index contributors.
99 * with the server.
100 */ 112 */
101 ExtensionPoint indexContributorExtensionPoint; 113 ExtensionPoint indexContributorExtensionPoint;
102 114
103 /** 115 /**
104 * Initialize a newly created plugin. 116 * Initialize a newly created plugin.
105 */ 117 */
106 ServerPlugin(); 118 ServerPlugin();
107 119
108 /** 120 /**
121 * Return a list containing all of the functions that can cause files to be
122 * analyzed.
123 */
124 List<ShouldAnalyzeFile> get analyzeFileFunctions =>
125 analyzeFileExtensionPoint.extensions;
126
127 /**
109 * Return a list containing all of the assist contributors that were 128 * Return a list containing all of the assist contributors that were
110 * contributed. 129 * contributed.
111 */ 130 */
112 List<AssistContributor> get assistContributors => 131 List<AssistContributor> get assistContributors =>
113 assistContributorExtensionPoint.extensions; 132 assistContributorExtensionPoint.extensions;
114 133
115 /** 134 /**
116 * Return a list containing all of the completion contributors that were 135 * Return a list containing all of the completion contributors that were
117 * contributed. 136 * contributed.
118 */ 137 */
(...skipping 24 matching lines...) Expand all
143 if (domainExtensionPoint == null) { 162 if (domainExtensionPoint == null) {
144 return <RequestHandler>[]; 163 return <RequestHandler>[];
145 } 164 }
146 return domainExtensionPoint.extensions 165 return domainExtensionPoint.extensions
147 .map((RequestHandlerFactory factory) => factory(server)) 166 .map((RequestHandlerFactory factory) => factory(server))
148 .toList(); 167 .toList();
149 } 168 }
150 169
151 @override 170 @override
152 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { 171 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) {
172 analyzeFileExtensionPoint = registerExtensionPoint(
173 ANALYZE_FILE_EXTENSION_POINT, _validateAnalyzeFileExtension);
153 assistContributorExtensionPoint = registerExtensionPoint( 174 assistContributorExtensionPoint = registerExtensionPoint(
154 ASSIST_CONTRIBUTOR_EXTENSION_POINT, 175 ASSIST_CONTRIBUTOR_EXTENSION_POINT,
155 _validateAssistContributorExtension); 176 _validateAssistContributorExtension);
156 completionContributorExtensionPoint = registerExtensionPoint( 177 completionContributorExtensionPoint = registerExtensionPoint(
157 COMPLETION_CONTRIBUTOR_EXTENSION_POINT, 178 COMPLETION_CONTRIBUTOR_EXTENSION_POINT,
158 _validateCompletionContributorExtension); 179 _validateCompletionContributorExtension);
159 domainExtensionPoint = registerExtensionPoint( 180 domainExtensionPoint = registerExtensionPoint(
160 DOMAIN_EXTENSION_POINT, _validateDomainExtension); 181 DOMAIN_EXTENSION_POINT, _validateDomainExtension);
161 fixContributorExtensionPoint = registerExtensionPoint( 182 fixContributorExtensionPoint = registerExtensionPoint(
162 FIX_CONTRIBUTOR_EXTENSION_POINT, _validateFixContributorExtension); 183 FIX_CONTRIBUTOR_EXTENSION_POINT, _validateFixContributorExtension);
163 indexContributorExtensionPoint = registerExtensionPoint( 184 indexContributorExtensionPoint = registerExtensionPoint(
164 INDEX_CONTRIBUTOR_EXTENSION_POINT, _validateIndexContributorExtension); 185 INDEX_CONTRIBUTOR_EXTENSION_POINT, _validateIndexContributorExtension);
165 } 186 }
166 187
167 @override 188 @override
168 void registerExtensions(RegisterExtension registerExtension) { 189 void registerExtensions(RegisterExtension registerExtension) {
169 // 190 //
191 // Register analyze file functions.
192 //
193 registerExtension(ANALYZE_FILE_EXTENSION_POINT_ID,
194 (File file) => AnalysisEngine.isDartFileName(file.path) ||
195 AnalysisEngine.isHtmlFileName(file.path));
196 //
170 // Register assist contributors. 197 // Register assist contributors.
171 // 198 //
172 registerExtension( 199 registerExtension(
173 ASSIST_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultAssistContributor()); 200 ASSIST_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultAssistContributor());
174 // 201 //
175 // Register completion contributors. 202 // Register completion contributors.
176 // 203 //
177 // TODO(brianwilkerson) Register the completion contributors. 204 // TODO(brianwilkerson) Register the completion contributors.
178 // registerExtension(COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID, ???); 205 // registerExtension(COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID, ???);
179 // 206 //
180 // Register domains. 207 // Register domains.
181 // 208 //
182 String domainId = Plugin.join(UNIQUE_IDENTIFIER, DOMAIN_EXTENSION_POINT); 209 String domainId = Plugin.join(UNIQUE_IDENTIFIER, DOMAIN_EXTENSION_POINT);
183 registerExtension( 210 registerExtension(
184 domainId, (AnalysisServer server) => new ServerDomainHandler(server)); 211 domainId, (AnalysisServer server) => new ServerDomainHandler(server));
185 registerExtension( 212 registerExtension(
186 domainId, (AnalysisServer server) => new AnalysisDomainHandler(server)); 213 domainId, (AnalysisServer server) => new AnalysisDomainHandler(server));
187 registerExtension(domainId, 214 registerExtension(
188 (AnalysisServer server) => new EditDomainHandler(server, this)); 215 domainId, (AnalysisServer server) => new EditDomainHandler(server));
189 registerExtension( 216 registerExtension(
190 domainId, (AnalysisServer server) => new SearchDomainHandler(server)); 217 domainId, (AnalysisServer server) => new SearchDomainHandler(server));
191 registerExtension(domainId, 218 registerExtension(domainId,
192 (AnalysisServer server) => new CompletionDomainHandler(server)); 219 (AnalysisServer server) => new CompletionDomainHandler(server));
193 registerExtension(domainId, 220 registerExtension(domainId,
194 (AnalysisServer server) => new ExecutionDomainHandler(server)); 221 (AnalysisServer server) => new ExecutionDomainHandler(server));
195 // 222 //
196 // Register fix contributors. 223 // Register fix contributors.
197 // 224 //
198 registerExtension( 225 registerExtension(
199 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor()); 226 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor());
200 // 227 //
201 // Register index contributors. 228 // Register index contributors.
202 // 229 //
203 // TODO(brianwilkerson) Register the index contributors. 230 // TODO(brianwilkerson) Register the index contributors.
204 // registerExtension(INDEX_CONTRIBUTOR_EXTENSION_POINT, ???); 231 // registerExtension(INDEX_CONTRIBUTOR_EXTENSION_POINT, ???);
205 } 232 }
206 233
207 /** 234 /**
208 * Validate the given extension by throwing an [ExtensionError] if it is not a 235 * Validate the given extension by throwing an [ExtensionError] if it is not a
209 * valid assist contributor. 236 * valid assist contributor.
210 */ 237 */
238 void _validateAnalyzeFileExtension(Object extension) {
239 if (extension is! ShouldAnalyzeFile) {
240 String id = analyzeFileExtensionPoint.uniqueIdentifier;
241 throw new ExtensionError(
242 'Extensions to $id must be an ShouldAnalyzeFile function');
243 }
244 }
245
246 /**
247 * Validate the given extension by throwing an [ExtensionError] if it is not a
248 * valid assist contributor.
249 */
211 void _validateAssistContributorExtension(Object extension) { 250 void _validateAssistContributorExtension(Object extension) {
212 if (extension is! AssistContributor) { 251 if (extension is! AssistContributor) {
213 String id = assistContributorExtensionPoint.uniqueIdentifier; 252 String id = assistContributorExtensionPoint.uniqueIdentifier;
214 throw new ExtensionError( 253 throw new ExtensionError(
215 'Extensions to $id must be an AssistContributor'); 254 'Extensions to $id must be an AssistContributor');
216 } 255 }
217 } 256 }
218 257
219 /** 258 /**
220 * Validate the given extension by throwing an [ExtensionError] if it is not a 259 * Validate the given extension by throwing an [ExtensionError] if it is not a
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 * Validate the given extension by throwing an [ExtensionError] if it is not a 294 * Validate the given extension by throwing an [ExtensionError] if it is not a
256 * valid index contributor. 295 * valid index contributor.
257 */ 296 */
258 void _validateIndexContributorExtension(Object extension) { 297 void _validateIndexContributorExtension(Object extension) {
259 if (extension is! IndexContributor) { 298 if (extension is! IndexContributor) {
260 String id = indexContributorExtensionPoint.uniqueIdentifier; 299 String id = indexContributorExtensionPoint.uniqueIdentifier;
261 throw new ExtensionError('Extensions to $id must be an IndexContributor'); 300 throw new ExtensionError('Extensions to $id must be an IndexContributor');
262 } 301 }
263 } 302 }
264 } 303 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/edit/edit_domain.dart ('k') | pkg/analysis_server/lib/src/socket_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698