OLD | NEW |
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/plugin/analysis/analysis_domain.dart'; | 7 import 'package:analysis_server/plugin/analysis/analysis_domain.dart'; |
8 import 'package:analysis_server/plugin/analysis/analyzed_files.dart'; | 8 import 'package:analysis_server/plugin/analysis/analyzed_files.dart'; |
9 import 'package:analysis_server/plugin/analysis/navigation/navigation.dart'; | 9 import 'package:analysis_server/plugin/analysis/navigation/navigation.dart'; |
10 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart'
; | 10 import 'package:analysis_server/plugin/analysis/navigation/navigation_core.dart'
; |
(...skipping 13 matching lines...) Expand all Loading... |
24 import 'package:analysis_server/src/domain_experimental.dart'; | 24 import 'package:analysis_server/src/domain_experimental.dart'; |
25 import 'package:analysis_server/src/domain_server.dart'; | 25 import 'package:analysis_server/src/domain_server.dart'; |
26 import 'package:analysis_server/src/domains/analysis/navigation_dart.dart'; | 26 import 'package:analysis_server/src/domains/analysis/navigation_dart.dart'; |
27 import 'package:analysis_server/src/domains/analysis/occurrences_dart.dart'; | 27 import 'package:analysis_server/src/domains/analysis/occurrences_dart.dart'; |
28 import 'package:analysis_server/src/edit/edit_domain.dart'; | 28 import 'package:analysis_server/src/edit/edit_domain.dart'; |
29 import 'package:analysis_server/src/provisional/completion/completion_core.dart'
; | 29 import 'package:analysis_server/src/provisional/completion/completion_core.dart'
; |
30 import 'package:analysis_server/src/search/search_domain.dart'; | 30 import 'package:analysis_server/src/search/search_domain.dart'; |
31 import 'package:analysis_server/src/services/correction/assist_internal.dart'; | 31 import 'package:analysis_server/src/services/correction/assist_internal.dart'; |
32 import 'package:analysis_server/src/services/correction/fix_internal.dart'; | 32 import 'package:analysis_server/src/services/correction/fix_internal.dart'; |
33 import 'package:analysis_server/src/services/index/index_contributor.dart'; | 33 import 'package:analysis_server/src/services/index/index_contributor.dart'; |
34 import 'package:analyzer/file_system/file_system.dart'; | |
35 import 'package:analyzer/src/generated/engine.dart'; | 34 import 'package:analyzer/src/generated/engine.dart'; |
36 import 'package:plugin/plugin.dart'; | 35 import 'package:plugin/plugin.dart'; |
37 | 36 |
38 /** | 37 /** |
39 * A function that will create a request handler that can be used by the given | 38 * A function that will create a request handler that can be used by the given |
40 * [server]. | 39 * [server]. |
41 */ | 40 */ |
42 typedef RequestHandler RequestHandlerFactory(AnalysisServer server); | 41 typedef RequestHandler RequestHandlerFactory(AnalysisServer server); |
43 | 42 |
44 /** | 43 /** |
45 * A plugin that defines the extension points and extensions that are inherently | 44 * A plugin that defines the extension points and extensions that are inherently |
46 * defined by the analysis server. | 45 * defined by the analysis server. |
47 */ | 46 */ |
48 class ServerPlugin implements Plugin { | 47 class ServerPlugin implements Plugin { |
49 /** | 48 /** |
50 * The simple identifier of the extension point that allows plugins to | 49 * The simple identifier of the extension point that allows plugins to |
51 * register functions that can cause files to be analyzed. | 50 * register file patterns that will cause files to be analyzed. |
52 */ | 51 */ |
53 static const String ANALYZE_FILE_EXTENSION_POINT = 'analyzeFile'; | 52 static const String ANALYZED_FILE_PATTERNS_EXTENSION_POINT = |
| 53 'analyzedFilePatterns'; |
54 | 54 |
55 /** | 55 /** |
56 * The simple identifier of the extension point that allows plugins to | 56 * The simple identifier of the extension point that allows plugins to |
57 * register assist contributors. | 57 * register assist contributors. |
58 */ | 58 */ |
59 static const String ASSIST_CONTRIBUTOR_EXTENSION_POINT = 'assistContributor'; | 59 static const String ASSIST_CONTRIBUTOR_EXTENSION_POINT = 'assistContributor'; |
60 | 60 |
61 /** | 61 /** |
62 * The simple identifier of the extension point that allows plugins to | 62 * The simple identifier of the extension point that allows plugins to |
63 * register completion contributors. | 63 * register completion contributors. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 * register analysis result listeners. | 102 * register analysis result listeners. |
103 */ | 103 */ |
104 static const String SET_ANALISYS_DOMAIN_EXTENSION_POINT = 'setAnalysisDomain'; | 104 static const String SET_ANALISYS_DOMAIN_EXTENSION_POINT = 'setAnalysisDomain'; |
105 | 105 |
106 /** | 106 /** |
107 * The unique identifier of this plugin. | 107 * The unique identifier of this plugin. |
108 */ | 108 */ |
109 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; | 109 static const String UNIQUE_IDENTIFIER = 'analysis_server.core'; |
110 | 110 |
111 /** | 111 /** |
112 * The extension point that allows plugins to register functions that can | 112 * The extension point that allows plugins to register file patterns that will |
113 * cause files to be analyzed. | 113 * cause files to be analyzed. |
114 */ | 114 */ |
115 ExtensionPoint analyzeFileExtensionPoint; | 115 ExtensionPoint analyzedFilePatternsExtensionPoint; |
116 | 116 |
117 /** | 117 /** |
118 * The extension point that allows plugins to register assist contributors. | 118 * The extension point that allows plugins to register assist contributors. |
119 */ | 119 */ |
120 ExtensionPoint assistContributorExtensionPoint; | 120 ExtensionPoint assistContributorExtensionPoint; |
121 | 121 |
122 /** | 122 /** |
123 * The extension point that allows plugins to register completion | 123 * The extension point that allows plugins to register completion |
124 * contributors. | 124 * contributors. |
125 */ | 125 */ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 * domain. | 159 * domain. |
160 */ | 160 */ |
161 ExtensionPoint setAnalysisDomainExtensionPoint; | 161 ExtensionPoint setAnalysisDomainExtensionPoint; |
162 | 162 |
163 /** | 163 /** |
164 * Initialize a newly created plugin. | 164 * Initialize a newly created plugin. |
165 */ | 165 */ |
166 ServerPlugin(); | 166 ServerPlugin(); |
167 | 167 |
168 /** | 168 /** |
169 * Return a list containing all of the functions that can cause files to be | 169 * Return a list containing all of the file patterns that can cause files to |
170 * analyzed. | 170 * be analyzed. |
171 */ | 171 */ |
172 List<ShouldAnalyzeFile> get analyzeFileFunctions => | 172 List<String> get analyzedFilePatterns { |
173 analyzeFileExtensionPoint.extensions; | 173 List<String> patterns = <String>[]; |
| 174 for (List<String> extension |
| 175 in analyzedFilePatternsExtensionPoint.extensions) { |
| 176 patterns.addAll(extension); |
| 177 } |
| 178 return patterns; |
| 179 } |
174 | 180 |
175 /** | 181 /** |
176 * Return a list containing all of the assist contributors that were | 182 * Return a list containing all of the assist contributors that were |
177 * contributed. | 183 * contributed. |
178 */ | 184 */ |
179 List<AssistContributor> get assistContributors => | 185 List<AssistContributor> get assistContributors => |
180 assistContributorExtensionPoint.extensions; | 186 assistContributorExtensionPoint.extensions; |
181 | 187 |
182 /** | 188 /** |
183 * Return a list containing all of the completion contributors that were | 189 * Return a list containing all of the completion contributors that were |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 return domainExtensionPoint.extensions | 240 return domainExtensionPoint.extensions |
235 .map((RequestHandlerFactory factory) => factory(server)) | 241 .map((RequestHandlerFactory factory) => factory(server)) |
236 .toList(); | 242 .toList(); |
237 } | 243 } |
238 | 244 |
239 @override | 245 @override |
240 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { | 246 void registerExtensionPoints(RegisterExtensionPoint registerExtensionPoint) { |
241 setAnalysisDomainExtensionPoint = registerExtensionPoint( | 247 setAnalysisDomainExtensionPoint = registerExtensionPoint( |
242 SET_ANALISYS_DOMAIN_EXTENSION_POINT, | 248 SET_ANALISYS_DOMAIN_EXTENSION_POINT, |
243 _validateSetAnalysisDomainFunction); | 249 _validateSetAnalysisDomainFunction); |
244 analyzeFileExtensionPoint = registerExtensionPoint( | 250 analyzedFilePatternsExtensionPoint = registerExtensionPoint( |
245 ANALYZE_FILE_EXTENSION_POINT, _validateAnalyzeFileExtension); | 251 ANALYZED_FILE_PATTERNS_EXTENSION_POINT, |
| 252 _validateAnalyzedFilePatternsExtension); |
246 assistContributorExtensionPoint = registerExtensionPoint( | 253 assistContributorExtensionPoint = registerExtensionPoint( |
247 ASSIST_CONTRIBUTOR_EXTENSION_POINT, | 254 ASSIST_CONTRIBUTOR_EXTENSION_POINT, |
248 _validateAssistContributorExtension); | 255 _validateAssistContributorExtension); |
249 completionContributorExtensionPoint = registerExtensionPoint( | 256 completionContributorExtensionPoint = registerExtensionPoint( |
250 COMPLETION_CONTRIBUTOR_EXTENSION_POINT, | 257 COMPLETION_CONTRIBUTOR_EXTENSION_POINT, |
251 _validateCompletionContributorExtension); | 258 _validateCompletionContributorExtension); |
252 domainExtensionPoint = registerExtensionPoint( | 259 domainExtensionPoint = registerExtensionPoint( |
253 DOMAIN_EXTENSION_POINT, _validateDomainExtension); | 260 DOMAIN_EXTENSION_POINT, _validateDomainExtension); |
254 fixContributorExtensionPoint = registerExtensionPoint( | 261 fixContributorExtensionPoint = registerExtensionPoint( |
255 FIX_CONTRIBUTOR_EXTENSION_POINT, _validateFixContributorExtension); | 262 FIX_CONTRIBUTOR_EXTENSION_POINT, _validateFixContributorExtension); |
256 indexContributorExtensionPoint = registerExtensionPoint( | 263 indexContributorExtensionPoint = registerExtensionPoint( |
257 INDEX_CONTRIBUTOR_EXTENSION_POINT, _validateIndexContributorExtension); | 264 INDEX_CONTRIBUTOR_EXTENSION_POINT, _validateIndexContributorExtension); |
258 navigationContributorExtensionPoint = registerExtensionPoint( | 265 navigationContributorExtensionPoint = registerExtensionPoint( |
259 NAVIGATION_CONTRIBUTOR_EXTENSION_POINT, | 266 NAVIGATION_CONTRIBUTOR_EXTENSION_POINT, |
260 _validateNavigationContributorExtension); | 267 _validateNavigationContributorExtension); |
261 occurrencesContributorExtensionPoint = registerExtensionPoint( | 268 occurrencesContributorExtensionPoint = registerExtensionPoint( |
262 OCCURRENCES_CONTRIBUTOR_EXTENSION_POINT, | 269 OCCURRENCES_CONTRIBUTOR_EXTENSION_POINT, |
263 _validateOccurrencesContributorExtension); | 270 _validateOccurrencesContributorExtension); |
264 } | 271 } |
265 | 272 |
266 @override | 273 @override |
267 void registerExtensions(RegisterExtension registerExtension) { | 274 void registerExtensions(RegisterExtension registerExtension) { |
268 // | 275 // |
269 // Register analyze file functions. | 276 // Register analyzed file patterns. |
270 // | 277 // |
271 registerExtension( | 278 List<String> patterns = <String>[ |
272 ANALYZE_FILE_EXTENSION_POINT_ID, | 279 '/**/*.${AnalysisEngine.SUFFIX_DART}', |
273 (File file) => AnalysisEngine.isDartFileName(file.path) || | 280 '/**/*.${AnalysisEngine.SUFFIX_HTML}', |
274 AnalysisEngine.isHtmlFileName(file.path) || | 281 '/**/*.${AnalysisEngine.SUFFIX_HTM}', |
275 AnalysisEngine.isAnalysisOptionsFileName(file.path)); | 282 '/**/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}' |
| 283 ]; |
| 284 registerExtension(ANALYZED_FILE_PATTERNS_EXTENSION_POINT_ID, patterns); |
276 // | 285 // |
277 // Register assist contributors. | 286 // Register assist contributors. |
278 // | 287 // |
279 registerExtension( | 288 registerExtension( |
280 ASSIST_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultAssistContributor()); | 289 ASSIST_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultAssistContributor()); |
281 // | 290 // |
282 // Register completion contributors. | 291 // Register completion contributors. |
283 // | 292 // |
284 // TODO(brianwilkerson) Register the completion contributors. | 293 // TODO(brianwilkerson) Register the completion contributors. |
285 // registerExtension(COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID, ???); | 294 // registerExtension(COMPLETION_CONTRIBUTOR_EXTENSION_POINT_ID, ???); |
(...skipping 25 matching lines...) Expand all Loading... |
311 // | 320 // |
312 // Register fix contributors. | 321 // Register fix contributors. |
313 // | 322 // |
314 registerExtension( | 323 registerExtension( |
315 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor()); | 324 FIX_CONTRIBUTOR_EXTENSION_POINT_ID, new DefaultFixContributor()); |
316 // | 325 // |
317 // Register index contributors. | 326 // Register index contributors. |
318 // | 327 // |
319 registerExtension( | 328 registerExtension( |
320 INDEX_CONTRIBUTOR_EXTENSION_POINT_ID, new DartIndexContributor()); | 329 INDEX_CONTRIBUTOR_EXTENSION_POINT_ID, new DartIndexContributor()); |
| 330 } |
321 | 331 |
| 332 /** |
| 333 * Return `true` if the list being used as an [extension] contains any |
| 334 * elements that are not strings. |
| 335 */ |
| 336 bool _containsNonString(List extension) { |
| 337 for (Object element in extension) { |
| 338 if (element is! String) { |
| 339 return true; |
| 340 } |
| 341 } |
| 342 return false; |
322 } | 343 } |
323 | 344 |
324 /** | 345 /** |
325 * Validate the given extension by throwing an [ExtensionError] if it is not a | 346 * Validate the given extension by throwing an [ExtensionError] if it is not a |
326 * valid assist contributor. | 347 * valid list of analyzed file patterns. |
327 */ | 348 */ |
328 void _validateAnalyzeFileExtension(Object extension) { | 349 void _validateAnalyzedFilePatternsExtension(Object extension) { |
329 if (extension is! ShouldAnalyzeFile) { | 350 if (extension is! List || _containsNonString(extension)) { |
330 String id = analyzeFileExtensionPoint.uniqueIdentifier; | 351 String id = analyzedFilePatternsExtensionPoint.uniqueIdentifier; |
331 throw new ExtensionError( | 352 throw new ExtensionError('Extensions to $id must be a List of Strings'); |
332 'Extensions to $id must be a ShouldAnalyzeFile function'); | |
333 } | 353 } |
334 } | 354 } |
335 | 355 |
336 /** | 356 /** |
337 * Validate the given extension by throwing an [ExtensionError] if it is not a | 357 * Validate the given extension by throwing an [ExtensionError] if it is not a |
338 * valid assist contributor. | 358 * valid assist contributor. |
339 */ | 359 */ |
340 void _validateAssistContributorExtension(Object extension) { | 360 void _validateAssistContributorExtension(Object extension) { |
341 if (extension is! AssistContributor) { | 361 if (extension is! AssistContributor) { |
342 String id = assistContributorExtensionPoint.uniqueIdentifier; | 362 String id = assistContributorExtensionPoint.uniqueIdentifier; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 * valid analysis domain receiver. | 440 * valid analysis domain receiver. |
421 */ | 441 */ |
422 void _validateSetAnalysisDomainFunction(Object extension) { | 442 void _validateSetAnalysisDomainFunction(Object extension) { |
423 if (extension is! SetAnalysisDomain) { | 443 if (extension is! SetAnalysisDomain) { |
424 String id = setAnalysisDomainExtensionPoint.uniqueIdentifier; | 444 String id = setAnalysisDomainExtensionPoint.uniqueIdentifier; |
425 throw new ExtensionError( | 445 throw new ExtensionError( |
426 'Extensions to $id must be a SetAnalysisDomain function'); | 446 'Extensions to $id must be a SetAnalysisDomain function'); |
427 } | 447 } |
428 } | 448 } |
429 } | 449 } |
OLD | NEW |