Search in sources :

Example 1 with VMConsumer

use of org.dartlang.vm.service.consumer.VMConsumer 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)

Example 2 with VMConsumer

use of org.dartlang.vm.service.consumer.VMConsumer in project flutter-intellij by flutter.

the class RenderThread method performReload.

/**
 * Attempt to perform hot reload.
 *
 * @return true if successful, or false if unsuccessful or timeout.
 */
private boolean performReload() {
    final CountDownLatch reloadLatch = new CountDownLatch(1);
    final AtomicBoolean reloadSuccess = new AtomicBoolean(false);
    myVmService.getVM(new VMConsumer() {

        @Override
        public void received(VM vm) {
            final ElementList<IsolateRef> isolates = vm.getIsolates();
            if (!isolates.isEmpty()) {
                final String isolateId = isolates.get(0).getId();
                myVmService.reloadSources(isolateId, new ReloadReportConsumer() {

                    @Override
                    public void received(ReloadReport report) {
                        reloadSuccess.set(report.getSuccess());
                        reloadLatch.countDown();
                    }

                    @Override
                    public void onError(RPCError error) {
                        reloadLatch.countDown();
                    }
                });
            }
        }

        @Override
        public void onError(RPCError error) {
            reloadLatch.countDown();
        }
    });
    return Uninterruptibles.awaitUninterruptibly(reloadLatch, 2000, TimeUnit.MILLISECONDS) && reloadSuccess.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReloadReportConsumer(org.dartlang.vm.service.consumer.ReloadReportConsumer) VMConsumer(org.dartlang.vm.service.consumer.VMConsumer) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with VMConsumer

use of org.dartlang.vm.service.consumer.VMConsumer in project flutter-intellij by flutter.

the class DartVmServiceDebugProcess method onConnectSucceeded.

private void onConnectSucceeded(VmService vmService) {
    final DartVmServiceListener vmServiceListener = new DartVmServiceListener(this, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
    final DartVmServiceBreakpointHandler breakpointHandler = (DartVmServiceBreakpointHandler) myBreakpointHandlers[0];
    myVmServiceWrapper = new VmServiceWrapper(this, vmService, vmServiceListener, myIsolatesInfo, breakpointHandler);
    final ScriptProvider provider = (isolateId, scriptId) -> myVmServiceWrapper.getScriptSync(isolateId, scriptId);
    mapper.onConnect(provider, myConnector.getRemoteBaseUrl());
    final FlutterLaunchMode launchMode = FlutterLaunchMode.fromEnv(executionEnvironment);
    if (launchMode.supportsDebugConnection()) {
        myVmServiceWrapper.handleDebuggerConnected();
        // TODO(jacobr): the following code is a workaround for issues
        // auto-resuming isolates paused at their creation while running in
        // debug mode.
        // The ideal fix would by to fix VMServiceWrapper so that it checks
        // for already running isolates like we do here or to refactor where we
        // create our VmServiceWrapper so we can listen for isolate creation soon
        // enough that we never miss an isolate creation message.
        vmService.getVM(new VMConsumer() {

            @Override
            public void received(VM vm) {
                final ElementList<IsolateRef> isolates = vm.getIsolates();
                // to handleDebuggerConnected was made and so
                for (IsolateRef isolateRef : isolates) {
                    vmService.getIsolate(isolateRef.getId(), new VmServiceConsumers.GetIsolateConsumerWrapper() {

                        public void received(Isolate isolate) {
                            final Event event = isolate.getPauseEvent();
                            final EventKind eventKind = event.getKind();
                            if (eventKind == EventKind.PauseStart) {
                                ApplicationManager.getApplication().invokeLater(() -> {
                                    // We are assuming it is safe to call handleIsolate multiple times.
                                    myVmServiceWrapper.handleIsolate(isolateRef, true);
                                });
                            } else if (eventKind == EventKind.Resume) {
                                // Currently true if we got here via 'flutter attach'
                                ApplicationManager.getApplication().invokeLater(() -> {
                                    myVmServiceWrapper.attachIsolate(isolateRef, isolate);
                                });
                            }
                        }
                    });
                }
            }

            @Override
            public void onError(RPCError error) {
                FlutterUtils.warn(LOG, error.toString());
            }
        });
    }
    vmService.addVmServiceListener(vmServiceListener);
    myVmConnected = true;
    getSession().rebuildViews();
    onVmConnected(vmService);
}
Also used : JsonObject(com.google.gson.JsonObject) Event(org.dartlang.vm.service.element.Event) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlutterInitializer(io.flutter.FlutterInitializer) THashMap(gnu.trove.THashMap) FlutterLaunchMode(io.flutter.run.FlutterLaunchMode) com.intellij.xdebugger(com.intellij.xdebugger) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) WindowListener(java.awt.event.WindowListener) Disposer(com.intellij.openapi.util.Disposer) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) ExecutionResult(com.intellij.execution.ExecutionResult) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) Logger(com.intellij.openapi.diagnostic.Logger) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) XSuspendContext(com.intellij.xdebugger.frame.XSuspendContext) DartDebuggerEditorsProvider(com.jetbrains.lang.dart.ide.runner.base.DartDebuggerEditorsProvider) ObservatoryConnector(io.flutter.ObservatoryConnector) WindowManager(com.intellij.openapi.wm.WindowManager) FlutterBundle(io.flutter.FlutterBundle) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) WindowEvent(java.awt.event.WindowEvent) StandardCharsets(java.nio.charset.StandardCharsets) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TimeoutUtil(com.intellij.util.TimeoutUtil) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VMConsumer(org.dartlang.vm.service.consumer.VMConsumer) NotNull(org.jetbrains.annotations.NotNull) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) DartVmServiceEvaluator(io.flutter.vmService.frame.DartVmServiceEvaluator) java.util(java.util) DartVmServiceSuspendContext(io.flutter.vmService.frame.DartVmServiceSuspendContext) DartVmServiceStackFrame(io.flutter.vmService.frame.DartVmServiceStackFrame) CompletableFuture(java.util.concurrent.CompletableFuture) org.dartlang.vm.service.element(org.dartlang.vm.service.element) XDebuggerEditorsProvider(com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider) DartPopFrameAction(com.jetbrains.lang.dart.ide.runner.actions.DartPopFrameAction) GetObjectConsumer(org.dartlang.vm.service.consumer.GetObjectConsumer) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) ProjectUtil(com.intellij.ide.impl.ProjectUtil) Project(com.intellij.openapi.project.Project) FlutterUtils(io.flutter.FlutterUtils) Logging(org.dartlang.vm.service.logging.Logging) VmService(org.dartlang.vm.service.VmService) IOException(java.io.IOException) XBreakpointHandler(com.intellij.xdebugger.breakpoints.XBreakpointHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) java.awt(java.awt) Pair(com.intellij.openapi.util.Pair) BitUtil(com.intellij.util.BitUtil) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) javax.swing(javax.swing) FlutterLaunchMode(io.flutter.run.FlutterLaunchMode) VMConsumer(org.dartlang.vm.service.consumer.VMConsumer) Event(org.dartlang.vm.service.element.Event) WindowEvent(java.awt.event.WindowEvent)

Aggregations

VMConsumer (org.dartlang.vm.service.consumer.VMConsumer)3 ExecutionResult (com.intellij.execution.ExecutionResult)2 ObservatoryConnector (io.flutter.ObservatoryConnector)2 JsonObject (com.google.gson.JsonObject)1 OpenFileHyperlinkInfo (com.intellij.execution.filters.OpenFileHyperlinkInfo)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 RunContentBuilder (com.intellij.execution.runners.RunContentBuilder)1 ConsoleViewContentType (com.intellij.execution.ui.ConsoleViewContentType)1 ExecutionConsole (com.intellij.execution.ui.ExecutionConsole)1 ProjectUtil (com.intellij.ide.impl.ProjectUtil)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Project (com.intellij.openapi.project.Project)1 Disposer (com.intellij.openapi.util.Disposer)1 Pair (com.intellij.openapi.util.Pair)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 WindowManager (com.intellij.openapi.wm.WindowManager)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1