| Index: pkg/analyzer_plugin/lib/src/channel/isolate_channel.dart
|
| diff --git a/pkg/analyzer_plugin/lib/src/channel/isolate_channel.dart b/pkg/analyzer_plugin/lib/src/channel/isolate_channel.dart
|
| index c3048d4201d639a4d1565cfd3bc1b8c02848f851..8ddc42a52de949f565494df0a7292dee6c493175 100644
|
| --- a/pkg/analyzer_plugin/lib/src/channel/isolate_channel.dart
|
| +++ b/pkg/analyzer_plugin/lib/src/channel/isolate_channel.dart
|
| @@ -3,8 +3,10 @@
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| import 'dart:async';
|
| +import 'dart:convert';
|
| import 'dart:isolate';
|
|
|
| +import 'package:analyzer/instrumentation/instrumentation.dart';
|
| import 'package:analyzer_plugin/channel/channel.dart';
|
| import 'package:analyzer_plugin/protocol/protocol.dart';
|
|
|
| @@ -50,6 +52,7 @@ class PluginIsolateChannel implements PluginCommunicationChannel {
|
| {Function onError, void onDone()}) {
|
| void onData(data) {
|
| Map<String, Object> requestMap = data;
|
| +// print('[plugin] Received request: ${JSON.encode(requestMap)}');
|
| Request request = new Request.fromJson(requestMap);
|
| if (request != null) {
|
| onRequest(request);
|
| @@ -65,12 +68,16 @@ class PluginIsolateChannel implements PluginCommunicationChannel {
|
|
|
| @override
|
| void sendNotification(Notification notification) {
|
| - _sendPort.send(notification.toJson());
|
| + Map<String, Object> json = notification.toJson();
|
| +// print('[plugin] Send notification: ${JSON.encode(json)}');
|
| + _sendPort.send(json);
|
| }
|
|
|
| @override
|
| void sendResponse(Response response) {
|
| - _sendPort.send(response.toJson());
|
| + Map<String, Object> json = response.toJson();
|
| +// print('[plugin] Send response: ${JSON.encode(json)}');
|
| + _sendPort.send(json);
|
| }
|
| }
|
|
|
| @@ -80,10 +87,21 @@ class PluginIsolateChannel implements PluginCommunicationChannel {
|
| */
|
| class ServerIsolateChannel implements ServerCommunicationChannel {
|
| /**
|
| - * The URI for the plugin that will be run in the isolate that this channel
|
| + * The URI for the Dart file that will be run in the isolate that this channel
|
| * communicates with.
|
| */
|
| - final Uri uri;
|
| + final Uri pluginUri;
|
| +
|
| + /**
|
| + * The URI for the '.packages' file that will control how 'package:' URIs are
|
| + * resolved.
|
| + */
|
| + final Uri packagesUri;
|
| +
|
| + /**
|
| + * The instrumentation service that is being used by the analysis server.
|
| + */
|
| + final InstrumentationService instrumentationService;
|
|
|
| /**
|
| * The isolate in which the plugin is running, or `null` if the plugin has
|
| @@ -97,17 +115,28 @@ class ServerIsolateChannel implements ServerCommunicationChannel {
|
| */
|
| SendPort _sendPort;
|
|
|
| + ReceivePort receivePort;
|
| +
|
| + ReceivePort errorPort;
|
| +
|
| + ReceivePort exitPort;
|
| +
|
| /**
|
| * Initialize a newly created channel to communicate with an isolate running
|
| * the code at the given [uri].
|
| */
|
| - ServerIsolateChannel(this.uri);
|
| -
|
| + ServerIsolateChannel(
|
| + this.pluginUri, this.packagesUri, this.instrumentationService);
|
| @override
|
| void close() {
|
| - // TODO(brianwilkerson) Is there anything useful to do here?
|
| + receivePort?.close();
|
| + errorPort?.close();
|
| + exitPort?.close();
|
| _isolate = null;
|
| - _sendPort = null;
|
| +// _sendPort = null;
|
| +// receivePort = null;
|
| +// errorPort = null;
|
| +// exitPort = null;
|
| }
|
|
|
| @override
|
| @@ -117,39 +146,53 @@ class ServerIsolateChannel implements ServerCommunicationChannel {
|
| if (_isolate != null) {
|
| throw new StateError('Cannot listen to the same channel more than once.');
|
| }
|
| - ReceivePort receivePort = new ReceivePort();
|
| - ReceivePort errorPort;
|
| + receivePort = new ReceivePort();
|
| if (onError != null) {
|
| errorPort = new ReceivePort();
|
| errorPort.listen((error) {
|
| onError(error);
|
| });
|
| }
|
| - ReceivePort exitPort;
|
| if (onDone != null) {
|
| exitPort = new ReceivePort();
|
| exitPort.listen((_) {
|
| onDone();
|
| });
|
| }
|
| - _isolate = await Isolate.spawnUri(uri, <String>[], receivePort.sendPort,
|
| - automaticPackageResolution: true,
|
| + _isolate = await Isolate.spawnUri(
|
| + pluginUri, <String>[], receivePort.sendPort,
|
| onError: errorPort?.sendPort,
|
| - onExit: exitPort?.sendPort);
|
| - _sendPort = await receivePort.first as SendPort;
|
| + onExit: exitPort?.sendPort,
|
| + packageConfig: packagesUri);
|
| + Completer<Null> channelReady = new Completer<Null>();
|
| receivePort.listen((dynamic input) {
|
| - if (input is Map) {
|
| + if (input is SendPort) {
|
| +// print('[server] Received send port');
|
| + _sendPort = input;
|
| + channelReady.complete(null);
|
| + } else if (input is Map) {
|
| if (input.containsKey('id') != null) {
|
| + String encodedInput = JSON.encode(input);
|
| +// print('[server] Received response: $encodedInput');
|
| + instrumentationService.logPluginResponse(pluginUri, encodedInput);
|
| onResponse(new Response.fromJson(input));
|
| } else if (input.containsKey('event')) {
|
| + String encodedInput = JSON.encode(input);
|
| +// print('[server] Received notification: $encodedInput');
|
| + instrumentationService.logPluginNotification(pluginUri, encodedInput);
|
| onNotification(new Notification.fromJson(input));
|
| }
|
| }
|
| });
|
| + return channelReady.future;
|
| }
|
|
|
| @override
|
| void sendRequest(Request request) {
|
| - _sendPort.send(request.toJson());
|
| + Map<String, Object> json = request.toJson();
|
| + String encodedRequest = JSON.encode(json);
|
| +// print('[server] Send request: $encodedRequest');
|
| + instrumentationService.logPluginRequest(pluginUri, encodedRequest);
|
| + _sendPort.send(json);
|
| }
|
| }
|
|
|