OLD | NEW |
---|---|
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:analyzer/file_system/file_system.dart'; | 5 import 'package:analyzer/file_system/file_system.dart'; |
6 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 6 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
7 import 'package:analyzer/src/dart/analysis/driver.dart' | 7 import 'package:analyzer/src/dart/analysis/driver.dart' |
8 show AnalysisDriverScheduler, PerformanceLog; | 8 show AnalysisDriverScheduler, PerformanceLog; |
9 import 'package:analyzer/src/dart/analysis/file_byte_store.dart'; | |
9 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 10 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
10 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
11 import 'package:analyzer_plugin/channel/channel.dart'; | 12 import 'package:analyzer_plugin/channel/channel.dart'; |
12 import 'package:analyzer_plugin/protocol/generated_protocol.dart'; | 13 import 'package:analyzer_plugin/protocol/generated_protocol.dart'; |
13 import 'package:analyzer_plugin/protocol/protocol.dart'; | 14 import 'package:analyzer_plugin/protocol/protocol.dart'; |
14 import 'package:analyzer_plugin/protocol/protocol_constants.dart'; | 15 import 'package:analyzer_plugin/protocol/protocol_constants.dart'; |
15 import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'; | 16 import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'; |
16 import 'package:analyzer_plugin/src/utilities/null_string_sink.dart'; | 17 import 'package:analyzer_plugin/src/utilities/null_string_sink.dart'; |
17 import 'package:analyzer_plugin/utilities/subscription_manager.dart'; | 18 import 'package:analyzer_plugin/utilities/subscription_manager.dart'; |
19 import 'package:pub_semver/pub_semver.dart'; | |
18 | 20 |
19 /** | 21 /** |
20 * The abstract superclass of any class implementing a plugin for the analysis | 22 * The abstract superclass of any class implementing a plugin for the analysis |
21 * server. | 23 * server. |
22 * | 24 * |
23 * Clients may not implement or mix-in this class, but are expected to extend | 25 * Clients may not implement or mix-in this class, but are expected to extend |
24 * it. | 26 * it. |
25 */ | 27 */ |
26 abstract class ServerPlugin { | 28 abstract class ServerPlugin { |
27 /** | 29 /** |
30 * A gigabyte. | |
31 */ | |
32 static const int G = 1024 * 1024 * 1024; | |
33 | |
34 /** | |
35 * A megabyte. | |
36 */ | |
37 static const int M = 1024 * 1024; | |
38 | |
39 /** | |
28 * The communication channel being used to communicate with the analysis | 40 * The communication channel being used to communicate with the analysis |
29 * server. | 41 * server. |
30 */ | 42 */ |
31 PluginCommunicationChannel _channel; | 43 PluginCommunicationChannel _channel; |
32 | 44 |
33 /** | 45 /** |
34 * The resource provider used to access the file system. | 46 * The resource provider used to access the file system. |
35 */ | 47 */ |
36 final ResourceProvider resourceProvider; | 48 final ResourceProvider resourceProvider; |
37 | 49 |
38 /** | 50 /** |
39 * The object used to manage analysis subscriptions. | 51 * The object used to manage analysis subscriptions. |
40 */ | 52 */ |
41 final SubscriptionManager subscriptionManager = new SubscriptionManager(); | 53 final SubscriptionManager subscriptionManager = new SubscriptionManager(); |
42 | 54 |
43 /** | 55 /** |
44 * The scheduler used by any analysis drivers that are created. | 56 * The scheduler used by any analysis drivers that are created. |
45 */ | 57 */ |
46 AnalysisDriverScheduler analysisDriverScheduler; | 58 AnalysisDriverScheduler analysisDriverScheduler; |
47 | 59 |
48 /** | 60 /** |
49 * The performance log used by any analysis drivers that are created. | 61 * The performance log used by any analysis drivers that are created. |
50 */ | 62 */ |
51 final PerformanceLog performanceLog = | 63 final PerformanceLog performanceLog = |
52 new PerformanceLog(new NullStringSink()); | 64 new PerformanceLog(new NullStringSink()); |
53 | 65 |
54 /** | 66 /** |
55 * The byte store used by any analysis drivers that are created. | 67 * The byte store used by any analysis drivers that are created, or `null` if |
68 * the cache location isn't known because the 'plugin.version' request has not | |
69 * yet been received. | |
56 */ | 70 */ |
57 final ByteStore byteStore = new MemoryByteStore(); | 71 ByteStore _byteStore; |
58 | 72 |
59 /** | 73 /** |
60 * The file content overlay used by any analysis drivers that are created. | 74 * The file content overlay used by any analysis drivers that are created. |
61 */ | 75 */ |
62 final FileContentOverlay fileContentOverlay = new FileContentOverlay(); | 76 final FileContentOverlay fileContentOverlay = new FileContentOverlay(); |
63 | 77 |
64 /** | 78 /** |
65 * Initialize a newly created analysis server plugin. If a resource [provider] | 79 * Initialize a newly created analysis server plugin. If a resource [provider] |
66 * is given, then it will be used to access the file system. Otherwise a | 80 * is given, then it will be used to access the file system. Otherwise a |
67 * resource provider that accesses the physical file system will be used. | 81 * resource provider that accesses the physical file system will be used. |
68 */ | 82 */ |
69 ServerPlugin(this.resourceProvider) { | 83 ServerPlugin(this.resourceProvider) { |
70 analysisDriverScheduler = new AnalysisDriverScheduler(performanceLog); | 84 analysisDriverScheduler = new AnalysisDriverScheduler(performanceLog); |
71 } | 85 } |
72 | 86 |
73 /** | 87 /** |
74 * Return the communication channel being used to communicate with the | 88 * Return the communication channel being used to communicate with the |
75 * analysis server, or `null` if the plugin has not been started. | 89 * analysis server, or `null` if the plugin has not been started. |
76 */ | 90 */ |
77 PluginCommunicationChannel get channel => _channel; | 91 PluginCommunicationChannel get channel => _channel; |
78 | 92 |
79 /** | 93 /** |
94 * Return the user visible information about how to contact the plugin authors | |
95 * with any problems that are found, or `null` if there is no contact info. | |
96 */ | |
97 String get contactInfo => null; | |
98 | |
99 /** | |
100 * Return a list of glob patterns selecting the files that this plugin is | |
101 * interested in analyzing. | |
102 */ | |
103 List<String> get fileGlobsToAnalyze; | |
104 | |
105 /** | |
106 * Return the user visible name of this plugin. | |
107 */ | |
108 String get name; | |
109 | |
110 /** | |
111 * Return the version number of this plugin, encoded as a string. | |
112 */ | |
113 String get version; | |
114 | |
115 /** | |
80 * Handle the fact that the file with the given [path] has been modified. | 116 * Handle the fact that the file with the given [path] has been modified. |
81 */ | 117 */ |
82 void contentChanged(String path) { | 118 void contentChanged(String path) { |
83 // Ignore changes to files. | 119 // Ignore changes to files. |
84 } | 120 } |
85 | 121 |
86 /** | 122 /** |
87 * Handle an 'analysis.handleWatchEvents' request. | 123 * Handle an 'analysis.handleWatchEvents' request. |
88 */ | 124 */ |
89 AnalysisHandleWatchEventsResult handleAnalysisHandleWatchEvents( | 125 AnalysisHandleWatchEventsResult handleAnalysisHandleWatchEvents( |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 * perform any required clean-up, but cannot prevent the plugin from shutting | 256 * perform any required clean-up, but cannot prevent the plugin from shutting |
221 * down. | 257 * down. |
222 */ | 258 */ |
223 PluginShutdownResult handlePluginShutdown(Map<String, Object> parameters) => | 259 PluginShutdownResult handlePluginShutdown(Map<String, Object> parameters) => |
224 new PluginShutdownResult(); | 260 new PluginShutdownResult(); |
225 | 261 |
226 /** | 262 /** |
227 * Handle a 'plugin.versionCheck' request. | 263 * Handle a 'plugin.versionCheck' request. |
228 */ | 264 */ |
229 PluginVersionCheckResult handlePluginVersionCheck( | 265 PluginVersionCheckResult handlePluginVersionCheck( |
230 Map<String, Object> parameters); | 266 Map<String, Object> parameters) { |
267 String byteStorePath = validateParameter(parameters, | |
268 PLUGIN_REQUEST_VERSION_CHECK_BYTESTOREPATH, 'plugin.versionCheck'); | |
269 String versionString = validateParameter(parameters, | |
270 PLUGIN_REQUEST_VERSION_CHECK_VERSION, 'plugin.versionCheck'); | |
271 Version serverVersion = new Version.parse(versionString); | |
272 _byteStore = | |
273 new MemoryCachingByteStore(new FileByteStore(byteStorePath, G), 64 * M); | |
scheglov
2017/02/04 02:01:15
We might want to avoid using FileByteStore in plug
Brian Wilkerson
2017/02/04 18:06:56
Ah, I didn't realize it did that much. Could we pu
| |
274 return new PluginVersionCheckResult( | |
275 isCompatibleWith(serverVersion), name, version, fileGlobsToAnalyze, | |
276 contactInfo: contactInfo); | |
277 } | |
278 | |
279 /** | |
280 * Return `true` if this plugin is compatible with an analysis server that is | |
281 * using the given version of the plugin API. | |
282 */ | |
283 bool isCompatibleWith(Version serverVersion) => | |
284 serverVersion <= new Version.parse(version); | |
231 | 285 |
232 /** | 286 /** |
233 * The method that is called when the analysis server closes the communication | 287 * The method that is called when the analysis server closes the communication |
234 * channel. This method will not be invoked under normal conditions because | 288 * channel. This method will not be invoked under normal conditions because |
235 * the server will send a shutdown request and the plugin will stop listening | 289 * the server will send a shutdown request and the plugin will stop listening |
236 * to the channel before the server closes the channel. | 290 * to the channel before the server closes the channel. |
237 */ | 291 */ |
238 void onDone() {} | 292 void onDone() {} |
239 | 293 |
240 /** | 294 /** |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 response = new Response(id, | 401 response = new Response(id, |
348 error: new RequestError( | 402 error: new RequestError( |
349 RequestErrorCode.PLUGIN_ERROR, exception.toString(), | 403 RequestErrorCode.PLUGIN_ERROR, exception.toString(), |
350 stackTrace: stackTrace.toString())); | 404 stackTrace: stackTrace.toString())); |
351 } | 405 } |
352 if (response != null) { | 406 if (response != null) { |
353 _channel.sendResponse(response); | 407 _channel.sendResponse(response); |
354 } | 408 } |
355 } | 409 } |
356 } | 410 } |
OLD | NEW |