Skip to content

Commit 1da50ff

Browse files
srawlinsCommit Queue
authored andcommitted
DAS: Collapse the ServerIsolateChannel class hierarchy
We stopped referencing BuiltInServerIsolateChannel a while ago, so the only concrete subclass of ServerIsolateChannel was DiscoveredServerIsolateChannel. This change removes the former class and collapses the latter class into the parent class. We also make `pluginUri` and `sessionLogger` private. Also, `packagesUri` was referencing the old `.packages` files, which are replaced with package config files, so we rename that field to `_packageConfigUri`. Change-Id: I93e2f4f10e14d832d85ea63382188019716b5de0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465985 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 8473a6e commit 1da50ff

File tree

4 files changed

+47
-110
lines changed

4 files changed

+47
-110
lines changed

pkg/analysis_server/lib/src/plugin/plugin_isolate.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class PluginIsolate {
3434
/// `null` if the isolate could not be started.
3535
final String? executionPath;
3636

37-
/// The path to the '.packages' file used to control the resolution of
37+
/// The path to the package config file used to control the resolution of
3838
/// 'package:' URIs, or `null` if the isolate could not be started.
39-
final String? packagesPath;
39+
final String? packageConfigPath;
4040

4141
/// The object used to manage the receiving and sending of notifications.
4242
final AbstractNotificationManager _notificationManager;
@@ -62,7 +62,7 @@ class PluginIsolate {
6262
PluginIsolate(
6363
this._path,
6464
this.executionPath,
65-
this.packagesPath,
65+
this.packageConfigPath,
6666
this._notificationManager,
6767
this._instrumentationService,
6868
this.sessionLogger, {
@@ -208,9 +208,9 @@ class PluginIsolate {
208208

209209
/// Creates and returns the channel used to communicate with the server.
210210
ServerCommunicationChannel _createChannel() {
211-
return ServerIsolateChannel.discovered(
211+
return ServerIsolateChannel(
212212
Uri.file(executionPath!, windows: Platform.isWindows),
213-
Uri.file(packagesPath!, windows: Platform.isWindows),
213+
Uri.file(packageConfigPath!, windows: Platform.isWindows),
214214
_instrumentationService,
215215
sessionLogger,
216216
);

pkg/analysis_server/lib/src/plugin/server_isolate_channel.dart

Lines changed: 38 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
1717
typedef 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
}

pkg/analysis_server/lib/src/status/pages/legacy_plugins_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class LegacyPluginsPage extends DiagnosticPageWithNav {
5151
['Bootstrap package path', id],
5252
if (plugin.executionPath case var executionPath?)
5353
['Execution path:', executionPath.wordBreakOnSlashes],
54-
if (plugin.packagesPath case var packagesPath?)
55-
['Packages file path', packagesPath.wordBreakOnSlashes],
54+
if (plugin.packageConfigPath case var packageConfigPath?)
55+
['Package config path', packageConfigPath.wordBreakOnSlashes],
5656
]);
5757

5858
if (data.name == null) {

pkg/analysis_server/lib/src/status/pages/plugins_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class PluginsPage extends DiagnosticPageWithNav {
4343
['Bootstrap package path:', id],
4444
if (isolate.executionPath case var executionPath?)
4545
['Execution path:', executionPath.wordBreakOnSlashes],
46-
if (isolate.packagesPath case var packagesPath?)
47-
['Packages file path', packagesPath.wordBreakOnSlashes],
46+
if (isolate.packageConfigPath case var packageConfigPath?)
47+
['Package config path', packageConfigPath.wordBreakOnSlashes],
4848
]);
4949

5050
if (data.name == null) {

0 commit comments

Comments
 (0)