Search in sources :

Example 6 with VmService

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

the class DartVmServiceDebugProcessZ method scheduleConnectNew.

public void scheduleConnectNew() {
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        // Poll, waiting for "flutter run" to give us a websocket.
        // Don't use a timeout - the user can cancel manually the operation.
        String url = myConnector.getWebSocketUrl();
        while (url == null) {
            if (getSession().isStopped())
                return;
            TimeoutUtil.sleep(100);
            url = myConnector.getWebSocketUrl();
        }
        if (getSession().isStopped()) {
            return;
        }
        // "Flutter run" has given us a websocket; we can assume it's ready immediately,
        // because "flutter run" has already connected to it.
        final VmService vmService;
        final VmOpenSourceLocationListener vmOpenSourceLocationListener;
        try {
            vmService = VmService.connect(url);
            vmOpenSourceLocationListener = VmOpenSourceLocationListener.connect(url);
        } catch (IOException e) {
            onConnectFailed("Failed to connect to the VM observatory service at: " + url + "\n" + e.toString() + "\n" + formatStackTraces(e));
            return;
        }
        onConnectSucceeded(vmService, vmOpenSourceLocationListener);
    });
}
Also used : VmService(org.dartlang.vm.service.VmService) IOException(java.io.IOException)

Example 7 with VmService

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

the class VmServiceWidgetPerfProvider method setupConnection.

private void setupConnection(@NotNull VmService vmService) {
    if (isDisposed || connected) {
        return;
    }
    final VMServiceManager vmServiceManager = app.getVMServiceManager();
    assert vmServiceManager != null;
    connected = true;
    isolateRefStreamSubscription = vmServiceManager.getCurrentFlutterIsolate((isolateRef) -> requestRepaint(When.soon), false);
    vmService.addVmServiceListener(new VmServiceListenerAdapter() {

        @Override
        public void received(String streamId, Event event) {
            onVmServiceReceived(streamId, event);
        }

        @Override
        public void connectionClosed() {
        }
    });
    inspectorService = InspectorService.create(app, app.getFlutterDebugProcess(), app.getVmService());
    inspectorService.whenCompleteAsync((service, throwable) -> Disposer.register(this, service));
    requestRepaint(When.soon);
}
Also used : JsonObject(com.google.gson.JsonObject) DiagnosticsNode(io.flutter.inspector.DiagnosticsNode) IsolateRef(org.dartlang.vm.service.element.IsolateRef) Event(org.dartlang.vm.service.element.Event) StringUtil(com.intellij.openapi.util.text.StringUtil) VmService(org.dartlang.vm.service.VmService) InspectorService(io.flutter.inspector.InspectorService) VMServiceManager(io.flutter.vmService.VMServiceManager) CompletableFuture(java.util.concurrent.CompletableFuture) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StreamSubscription(io.flutter.utils.StreamSubscription) Disposer(com.intellij.openapi.util.Disposer) VmServiceListener(org.dartlang.vm.service.VmServiceListener) NotNull(org.jetbrains.annotations.NotNull) FlutterApp(io.flutter.run.daemon.FlutterApp) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter) VMServiceManager(io.flutter.vmService.VMServiceManager) Event(org.dartlang.vm.service.element.Event) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter)

Example 8 with VmService

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

the class DartVmServiceDebugProcess method scheduleConnect.

public void scheduleConnect() {
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        // Poll, waiting for "flutter run" to give us a websocket.
        // Don't use a timeout - the user can cancel manually the operation.
        String url = myConnector.getWebSocketUrl();
        while (url == null) {
            if (getSession().isStopped())
                return;
            TimeoutUtil.sleep(100);
            url = myConnector.getWebSocketUrl();
        }
        if (getSession().isStopped()) {
            return;
        }
        // "flutter run" has given us a websocket; we can assume it's ready immediately, because
        // "flutter run" has already connected to it.
        final VmService vmService;
        try {
            vmService = VmService.connect(url);
        } catch (IOException | RuntimeException e) {
            onConnectFailed("Failed to connect to the VM observatory service at: " + url + "\n" + e.toString() + "\n" + formatStackTraces(e));
            return;
        }
        onConnectSucceeded(vmService);
    });
}
Also used : VmService(org.dartlang.vm.service.VmService) IOException(java.io.IOException)

Example 9 with VmService

use of org.dartlang.vm.service.VmService 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

VmService (org.dartlang.vm.service.VmService)9 IOException (java.io.IOException)5 NotNull (org.jetbrains.annotations.NotNull)4 ExecutionResult (com.intellij.execution.ExecutionResult)3 Disposer (com.intellij.openapi.util.Disposer)3 Event (org.dartlang.vm.service.element.Event)3 JsonObject (com.google.gson.JsonObject)2 OpenFileHyperlinkInfo (com.intellij.execution.filters.OpenFileHyperlinkInfo)2 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 ConsoleViewContentType (com.intellij.execution.ui.ConsoleViewContentType)2 ProjectUtil (com.intellij.ide.impl.ProjectUtil)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 WindowManager (com.intellij.openapi.wm.WindowManager)2 BitUtil (com.intellij.util.BitUtil)2 TimeoutUtil (com.intellij.util.TimeoutUtil)2 XBreakpointHandler (com.intellij.xdebugger.breakpoints.XBreakpointHandler)2 XDebuggerEditorsProvider (com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider)2