Skip to content

Commit c440213

Browse files
srawlinsCommit Queue
authored andcommitted
Tidy up PluginIsolate fields
PluginIsolate.executionPath and .packagesPath were non-nullable strings with a magic `''` value meaning the plugin isolate could not be started. Making it nullable makes it more understandable, and I add documentation. In the "insights" pages, we then don't print weird blank strings. Also I missed renaming `_info` to `_isolate`. Change-Id: Ib8ce52d297cf083239004fffe990b6a9e90c7ddb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447960 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent d769054 commit c440213

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ class PluginIsolate {
2929
/// directory).
3030
final String _path;
3131

32-
/// The path to the 'plugin.dart' file that will be executed in an isolate.
33-
final String executionPath;
32+
/// The path to the 'plugin.dart' file that will be executed in an isolate, or
33+
/// `null` if the isolate could not be started.
34+
final String? executionPath;
3435

3536
/// The path to the '.packages' file used to control the resolution of
36-
/// 'package:' URIs.
37-
final String packagesPath;
37+
/// 'package:' URIs, or `null` if the isolate could not be started.
38+
final String? packagesPath;
3839

3940
/// The object used to manage the receiving and sending of notifications.
4041
final AbstractNotificationManager _notificationManager;
@@ -79,7 +80,7 @@ class PluginIsolate {
7980
/// For example, a plugin cannot be started if there was an error with a
8081
/// previous attempt to start running it or if the plugin is not correctly
8182
/// configured.
82-
bool get _canBeStarted => executionPath.isNotEmpty;
83+
bool get _canBeStarted => executionPath != null;
8384

8485
/// Adds the given [contextRoot] to the set of context roots being analyzed by
8586
/// this plugin.
@@ -181,8 +182,8 @@ class PluginIsolate {
181182
/// Creates and returns the channel used to communicate with the server.
182183
ServerCommunicationChannel _createChannel() {
183184
return ServerIsolateChannel.discovered(
184-
Uri.file(executionPath, windows: Platform.isWindows),
185-
Uri.file(packagesPath, windows: Platform.isWindows),
185+
Uri.file(executionPath!, windows: Platform.isWindows),
186+
Uri.file(packagesPath!, windows: Platform.isWindows),
186187
_instrumentationService,
187188
);
188189
}
@@ -217,7 +218,7 @@ class PluginSession {
217218
static const Duration WAIT_FOR_SHUTDOWN_DURATION = Duration(seconds: 10);
218219

219220
/// The information about the plugin being executed.
220-
final PluginIsolate _info;
221+
final PluginIsolate _isolate;
221222

222223
/// The completer used to signal when the plugin has stopped.
223224
Completer<void> pluginStoppedCompleter = Completer<void>();
@@ -248,7 +249,7 @@ class PluginSession {
248249
/// plugin.
249250
String? _version;
250251

251-
PluginSession(this._info);
252+
PluginSession(this._isolate);
252253

253254
/// The next request ID, encoded as a string.
254255
///
@@ -264,12 +265,12 @@ class PluginSession {
264265
if (notification.event == PLUGIN_NOTIFICATION_ERROR) {
265266
var params = PluginErrorParams.fromNotification(notification);
266267
if (params.isFatal) {
267-
_info.stop();
268+
_isolate.stop();
268269
stop();
269270
}
270271
}
271-
_info._notificationManager.handlePluginNotification(
272-
_info.pluginId,
272+
_isolate._notificationManager.handlePluginNotification(
273+
_isolate.pluginId,
273274
notification,
274275
);
275276
}
@@ -288,7 +289,7 @@ class PluginSession {
288289
if (error case [String message, String stackTraceString]) {
289290
var stackTrace = StackTrace.fromString(stackTraceString);
290291
var exception = PluginException(message);
291-
_info.reportException(
292+
_isolate.reportException(
292293
CaughtException.withMessage(message, exception, stackTrace),
293294
);
294295
} else {
@@ -307,7 +308,7 @@ class PluginSession {
307308
if (requestData != null) {
308309
var responseTime = DateTime.now().millisecondsSinceEpoch;
309310
var duration = responseTime - requestData.requestTime;
310-
PluginManager.recordResponseTime(_info, requestData.method, duration);
311+
PluginManager.recordResponseTime(_isolate, requestData.method, duration);
311312
var completer = requestData.completer;
312313
completer.complete(response);
313314
}
@@ -354,15 +355,15 @@ class PluginSession {
354355
if (error.code == RequestErrorCode.UNKNOWN_REQUEST) {
355356
// The plugin doesn't support this request. It may just be using an
356357
// older version of the `analysis_server_plugin` package.
357-
_info._instrumentationService.logInfo(
358+
_isolate._instrumentationService.logInfo(
358359
"Plugin cannot handle request '${request.method}' with parameters: "
359360
'$parameters.',
360361
);
361362
return;
362363
}
363364
var stackTrace = StackTrace.fromString(error.stackTrace!);
364365
var exception = PluginException(error.message);
365-
_info.reportException(
366+
_isolate.reportException(
366367
CaughtException.withMessage(error.message, exception, stackTrace),
367368
);
368369
}
@@ -382,24 +383,24 @@ class PluginSession {
382383
throw StateError('Missing byte store path');
383384
}
384385
if (!isCompatible) {
385-
_info.reportException(
386+
_isolate.reportException(
386387
CaughtException(
387388
PluginException('Plugin is not compatible.'),
388389
StackTrace.current,
389390
),
390391
);
391392
return false;
392393
}
393-
if (!_info._canBeStarted) {
394-
_info.reportException(
394+
if (!_isolate._canBeStarted) {
395+
_isolate.reportException(
395396
CaughtException(
396397
PluginException('Plugin cannot be started.'),
397398
StackTrace.current,
398399
),
399400
);
400401
return false;
401402
}
402-
channel = _info._createChannel();
403+
channel = _isolate._createChannel();
403404
// TODO(brianwilkerson): Determine if await is necessary, if so, change the
404405
// return type of `channel.listen` to `Future<void>`.
405406
await (channel!.listen(
@@ -412,7 +413,7 @@ class PluginSession {
412413
if (channel == null) {
413414
// If there is an error when starting the isolate, the channel will invoke
414415
// `handleOnDone`, which will cause `channel` to be set to `null`.
415-
_info.reportException(
416+
_isolate.reportException(
416417
CaughtException(
417418
PluginException('Unrecorded error while starting the plugin.'),
418419
StackTrace.current,
@@ -430,7 +431,7 @@ class PluginSession {
430431
_version = result.version;
431432
if (!isCompatible) {
432433
unawaited(sendRequest(PluginShutdownParams()));
433-
_info.reportException(
434+
_isolate.reportException(
434435
CaughtException(
435436
PluginException('Plugin is not compatible.'),
436437
StackTrace.current,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ class PluginManager {
155155
} catch (exception, stackTrace) {
156156
pluginIsolate = PluginIsolate(
157157
path,
158-
'',
159-
'',
158+
null,
159+
null,
160160
_notificationManager,
161161
instrumentationService,
162162
);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ class PluginsPage extends DiagnosticPageWithNav {
4545

4646
_emitTable([
4747
['Bootstrap package path:', id],
48-
['Execution path:', plugin.executionPath.wordBreakOnSlashes],
49-
['Packages file path', plugin.packagesPath.wordBreakOnSlashes],
48+
if (plugin.executionPath case var executionPath?)
49+
['Execution path:', executionPath.wordBreakOnSlashes],
50+
if (plugin.packagesPath case var packagesPath?)
51+
['Packages file path', packagesPath.wordBreakOnSlashes],
5052
]);
5153

5254
if (data.name == null) {

pkg/analyzer/lib/instrumentation/plugin_data.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class PluginData {
77
/// The ID used to uniquely identify the plugin.
88
final String pluginId;
99

10-
/// The name of the plugin.
10+
/// The name of the plugin, or `null` if the plugin is not running.
1111
final String? name;
1212

13-
/// The version of the plugin.
13+
/// The version of the plugin, or `null` if the plugin is not running.
1414
final String? version;
1515

1616
PluginData(this.pluginId, this.name, this.version);

0 commit comments

Comments
 (0)