Search in sources :

Example 1 with ElementList

use of org.dartlang.vm.service.element.ElementList in project flutter-intellij by flutter.

the class FlutterTestRunner method run.

protected RunContentDescriptor run(@NotNull TestLaunchState launcher, @NotNull ExecutionEnvironment env) throws ExecutionException {
    final ExecutionResult executionResult = launcher.execute(env.getExecutor(), this);
    final ObservatoryConnector connector = new Connector(executionResult.getProcessHandler());
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        // Poll, waiting for "flutter run" to give us a websocket.
        // This is adapted from DartVmServiceDebugProcess::scheduleConnect.
        String url = connector.getWebSocketUrl();
        while (url == null) {
            if (launcher.isTerminated()) {
                return;
            }
            TimeoutUtil.sleep(100);
            url = connector.getWebSocketUrl();
        }
        if (launcher.isTerminated()) {
            return;
        }
        final VmService vmService;
        try {
            vmService = VmService.connect(url);
        } catch (IOException | RuntimeException e) {
            if (!launcher.isTerminated()) {
                launcher.notifyTextAvailable("Failed to connect to the VM service at: " + url + "\n" + e.toString() + "\n", ProcessOutputTypes.STDERR);
            }
            return;
        }
        // Listen for debug 'PauseStart' events for isolates after the initial connect and resume those isolates.
        vmService.streamListen(VmService.DEBUG_STREAM_ID, VmServiceConsumers.EMPTY_SUCCESS_CONSUMER);
        vmService.addVmServiceListener(new VmServiceListenerAdapter() {

            @Override
            public void received(String streamId, Event event) {
                if (EventKind.PauseStart.equals(event.getKind())) {
                    resumePausedAtStartIsolate(launcher, vmService, event.getIsolate());
                }
            }
        });
        // Resume any isolates paused at the initial connect.
        vmService.getVM(new VMConsumer() {

            @Override
            public void received(VM response) {
                final ElementList<IsolateRef> isolates = response.getIsolates();
                for (IsolateRef isolateRef : isolates) {
                    resumePausedAtStartIsolate(launcher, vmService, isolateRef);
                }
            }

            @Override
            public void onError(RPCError error) {
                if (!launcher.isTerminated()) {
                    launcher.notifyTextAvailable("Error connecting to VM: " + error.getCode() + " " + error.getMessage() + "\n", ProcessOutputTypes.STDERR);
                }
            }
        });
    });
    return new RunContentBuilder(executionResult, env).showRunContent(env.getContentToReuse());
}
Also used : ObservatoryConnector(io.flutter.ObservatoryConnector) IsolateRef(org.dartlang.vm.service.element.IsolateRef) VmService(org.dartlang.vm.service.VmService) VMConsumer(org.dartlang.vm.service.consumer.VMConsumer) ExecutionResult(com.intellij.execution.ExecutionResult) RPCError(org.dartlang.vm.service.element.RPCError) ObservatoryConnector(io.flutter.ObservatoryConnector) IOException(java.io.IOException) ElementList(org.dartlang.vm.service.element.ElementList) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter) VM(org.dartlang.vm.service.element.VM) Event(org.dartlang.vm.service.element.Event) RunContentBuilder(com.intellij.execution.runners.RunContentBuilder)

Aggregations

ExecutionResult (com.intellij.execution.ExecutionResult)1 RunContentBuilder (com.intellij.execution.runners.RunContentBuilder)1 ObservatoryConnector (io.flutter.ObservatoryConnector)1 VmServiceListenerAdapter (io.flutter.utils.VmServiceListenerAdapter)1 IOException (java.io.IOException)1 VmService (org.dartlang.vm.service.VmService)1 VMConsumer (org.dartlang.vm.service.consumer.VMConsumer)1 ElementList (org.dartlang.vm.service.element.ElementList)1 Event (org.dartlang.vm.service.element.Event)1 IsolateRef (org.dartlang.vm.service.element.IsolateRef)1 RPCError (org.dartlang.vm.service.element.RPCError)1 VM (org.dartlang.vm.service.element.VM)1