@@ -16,77 +16,22 @@ import 'package:analyzer_plugin/protocol/protocol_generated.dart';
1616/// The type of the function used to run a built-in plugin in an isolate.
1717typedef EntryPoint = void Function (SendPort sendPort);
1818
19- /// A communication channel appropriate for built-in plugins.
20- class BuiltInServerIsolateChannel extends ServerIsolateChannel {
21- /// The entry point
22- final EntryPoint entryPoint;
23-
24- @override
25- final String pluginId;
26-
27- /// Initialize a newly created channel to communicate with an isolate running
28- /// the given [entryPoint] .
29- BuiltInServerIsolateChannel (
30- this .entryPoint,
31- this .pluginId,
32- InstrumentationService instrumentationService,
33- SessionLogger sessionLogger,
34- ) : super ._(instrumentationService, sessionLogger);
35-
36- @override
37- Future <Isolate > _spawnIsolate () {
38- return Isolate .spawn (
39- (message) => entryPoint (message as SendPort ),
40- _receivePort? .sendPort,
41- onError: _errorPort? .sendPort,
42- onExit: _exitPort? .sendPort,
43- );
44- }
45- }
46-
47- /// A communication channel appropriate for discovered plugins.
48- class DiscoveredServerIsolateChannel extends ServerIsolateChannel {
49- /// The URI for the Dart file that will be run in the isolate that this
50- /// channel communicates with.
51- final Uri pluginUri;
52-
53- /// The URI for the '.packages' file that will control how 'package:' URIs are
54- /// resolved.
55- final Uri packagesUri;
56-
57- /// Initialize a newly created channel to communicate with an isolate running
58- /// the code at the given [uri] .
59- DiscoveredServerIsolateChannel (
60- this .pluginUri,
61- this .packagesUri,
62- InstrumentationService instrumentationService,
63- SessionLogger sessionLogger,
64- ) : super ._(instrumentationService, sessionLogger);
65-
66- @override
67- String get pluginId => pluginUri.toString ();
68-
69- @override
70- Future <Isolate > _spawnIsolate () {
71- return Isolate .spawnUri (
72- pluginUri,
73- < String > [],
74- _receivePort? .sendPort,
75- onError: _errorPort? .sendPort,
76- onExit: _exitPort? .sendPort,
77- packageConfig: packagesUri,
78- );
79- }
80- }
81-
8219/// A communication channel that allows an analysis server to send [Request] s
8320/// to, and to receive both [Response] s and [Notification] s from, a plugin.
84- abstract class ServerIsolateChannel implements ServerCommunicationChannel {
21+ final class ServerIsolateChannel implements ServerCommunicationChannel {
8522 /// The instrumentation service that is being used by the analysis server.
8623 final InstrumentationService instrumentationService;
8724
25+ /// The URI for the Dart file that will be run in the isolate that this
26+ /// channel communicates with.
27+ final Uri _pluginUri;
28+
29+ /// The URI for the package config file that controls how 'package:' URIs
30+ /// are resolved.
31+ final Uri _packageConfigUri;
32+
8833 /// The session logger that is to be used by this channel.
89- final SessionLogger sessionLogger ;
34+ final SessionLogger _sessionLogger ;
9035
9136 /// The isolate in which the plugin is running, or `null` if the plugin has
9237 /// not yet been started by invoking [listen] .
@@ -105,33 +50,16 @@ abstract class ServerIsolateChannel implements ServerCommunicationChannel {
10550 /// The port used to receive notification when the plugin isolate has exited.
10651 ReceivePort ? _exitPort;
10752
108- /// Return a communication channel appropriate for communicating with a
109- /// built-in plugin.
110- // TODO(brianwilkerson): This isn't currently referenced. We should decide
111- // whether there's any value to supporting built-in plugins and remove this
112- // if we decide there isn't.
113- factory ServerIsolateChannel .builtIn (
114- EntryPoint entryPoint,
115- String pluginId,
116- InstrumentationService instrumentationService,
117- SessionLogger sessionLogger,
118- ) = BuiltInServerIsolateChannel ;
119-
120- /// Return a communication channel appropriate for communicating with a
121- /// discovered plugin.
122- factory ServerIsolateChannel .discovered (
123- Uri pluginUri,
124- Uri packagesUri,
125- InstrumentationService instrumentationService,
126- SessionLogger sessionLogger,
127- ) = DiscoveredServerIsolateChannel ;
128-
129- /// Initialize a newly created channel.
130- ServerIsolateChannel ._(this .instrumentationService, this .sessionLogger);
131-
132- /// Return the id of the plugin running in the isolate, used to identify the
133- /// plugin to the instrumentation service.
134- String get pluginId;
53+ ServerIsolateChannel (
54+ this ._pluginUri,
55+ this ._packageConfigUri,
56+ this .instrumentationService,
57+ this ._sessionLogger,
58+ );
59+
60+ /// The ID of the plugin running in the isolate, used to identify the plugin
61+ /// to the instrumentation service.
62+ String get _pluginId => _pluginUri.toString ();
13563
13664 @override
13765 void close () {
@@ -180,7 +108,7 @@ abstract class ServerIsolateChannel implements ServerCommunicationChannel {
180108 _isolate = await _spawnIsolate ();
181109 } catch (exception, stackTrace) {
182110 instrumentationService.logPluginError (
183- PluginData (pluginId , null , null ),
111+ PluginData (_pluginId , null , null ),
184112 RequestErrorCode .PLUGIN_ERROR .toString (),
185113 exception.toString (),
186114 stackTrace.toString (),
@@ -203,17 +131,17 @@ abstract class ServerIsolateChannel implements ServerCommunicationChannel {
203131 } else if (input is Map <String , Object ?>) {
204132 if (input.containsKey ('id' )) {
205133 var encodedInput = json.encode (input);
206- instrumentationService.logPluginResponse (pluginId , encodedInput);
207- sessionLogger .logMessage (
134+ instrumentationService.logPluginResponse (_pluginId , encodedInput);
135+ _sessionLogger .logMessage (
208136 from: ProcessId .plugin,
209137 to: ProcessId .server,
210138 message: input,
211139 );
212140 onResponse (Response .fromJson (input));
213141 } else if (input.containsKey ('event' )) {
214142 var encodedInput = json.encode (input);
215- instrumentationService.logPluginNotification (pluginId , encodedInput);
216- sessionLogger .logMessage (
143+ instrumentationService.logPluginNotification (_pluginId , encodedInput);
144+ _sessionLogger .logMessage (
217145 from: ProcessId .plugin,
218146 to: ProcessId .server,
219147 message: input,
@@ -232,8 +160,8 @@ abstract class ServerIsolateChannel implements ServerCommunicationChannel {
232160 if (sendPort != null ) {
233161 var jsonData = request.toJson ();
234162 var encodedRequest = json.encode (jsonData);
235- instrumentationService.logPluginRequest (pluginId , encodedRequest);
236- sessionLogger .logMessage (
163+ instrumentationService.logPluginRequest (_pluginId , encodedRequest);
164+ _sessionLogger .logMessage (
237165 from: ProcessId .server,
238166 to: ProcessId .plugin,
239167 message: jsonData,
@@ -242,6 +170,15 @@ abstract class ServerIsolateChannel implements ServerCommunicationChannel {
242170 }
243171 }
244172
245- /// Spawn the isolate in which the plugin is running.
246- Future <Isolate > _spawnIsolate ();
173+ /// Spawns the isolate in which the plugin is running.
174+ Future <Isolate > _spawnIsolate () {
175+ return Isolate .spawnUri (
176+ _pluginUri,
177+ [],
178+ _receivePort? .sendPort,
179+ onError: _errorPort? .sendPort,
180+ onExit: _exitPort? .sendPort,
181+ packageConfig: _packageConfigUri,
182+ );
183+ }
247184}
0 commit comments