Search in sources :

Example 1 with VmService

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

the class FlutterConsoleLogManager method processLoggingEvent.

@VisibleForTesting
public void processLoggingEvent(@NotNull Event event) {
    final LogRecord logRecord = event.getLogRecord();
    if (logRecord == null)
        return;
    final VmService service = app.getVmService();
    if (service == null) {
        return;
    }
    final IsolateRef isolateRef = event.getIsolate();
    final InstanceRef message = logRecord.getMessage();
    @NotNull final InstanceRef loggerName = logRecord.getLoggerName();
    final String name = loggerName.getValueAsString().isEmpty() ? "log" : loggerName.getValueAsString();
    final String prefix = "[" + name + "] ";
    final String messageStr = getFullStringValue(service, isolateRef.getId(), message);
    console.print(prefix, SUBTLE_CONTENT_TYPE);
    console.print(messageStr + "\n", NORMAL_CONTENT_TYPE);
    @NotNull final InstanceRef error = logRecord.getError();
    @NotNull final InstanceRef stackTrace = logRecord.getStackTrace();
    if (!error.isNull()) {
        final String padding = StringUtil.repeat(" ", prefix.length());
        if (error.getKind() == InstanceKind.String) {
            String string = getFullStringValue(service, isolateRef.getId(), error);
            // Handle json in the error payload.
            boolean isJson = false;
            try {
                final JsonElement json = JsonUtils.parseString(string);
                isJson = true;
                string = new GsonBuilder().setPrettyPrinting().create().toJson(json);
                string = string.replaceAll("\n", "\n" + padding);
            } catch (JsonSyntaxException ignored) {
            }
            console.print(padding + string + "\n", isJson ? ConsoleViewContentType.NORMAL_OUTPUT : ERROR_CONTENT_TYPE);
        } else {
            final CountDownLatch latch = new CountDownLatch(1);
            service.invoke(isolateRef.getId(), error.getId(), "toString", Collections.emptyList(), true, new VmServiceConsumers.InvokeConsumerWrapper() {

                @Override
                public void received(InstanceRef response) {
                    console.print(padding + stringValueFromStringRef(response) + "\n", ERROR_CONTENT_TYPE);
                    latch.countDown();
                }

                @Override
                public void noGoodResult() {
                    console.print(padding + error.getClassRef().getName() + " " + error.getId() + "\n", ERROR_CONTENT_TYPE);
                    latch.countDown();
                }
            });
            try {
                latch.await();
            } catch (InterruptedException ignored) {
            }
        }
    }
    if (!stackTrace.isNull()) {
        final String padding = StringUtil.repeat(" ", prefix.length());
        final String out = stackTrace.getValueAsString() == null ? "" : stackTrace.getValueAsString().trim();
        console.print(padding + out.replaceAll("\n", "\n" + padding) + "\n", ERROR_CONTENT_TYPE);
    }
}
Also used : VmServiceConsumers(io.flutter.vmService.VmServiceConsumers) GsonBuilder(com.google.gson.GsonBuilder) VmService(org.dartlang.vm.service.VmService) CountDownLatch(java.util.concurrent.CountDownLatch) NotNull(org.jetbrains.annotations.NotNull) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with VmService

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

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

the class DartVmServiceDebugProcess method connect.

private void connect(@NotNull final String url) throws IOException {
    final VmService vmService = VmService.connect(url);
    final DartVmServiceListener vmServiceListener = new DartVmServiceListener(this, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
    vmService.addVmServiceListener(vmServiceListener);
    myVmServiceWrapper = new VmServiceWrapper(this, vmService, vmServiceListener, myIsolatesInfo, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
    myVmServiceWrapper.handleDebuggerConnected();
    myVmConnected = true;
}
Also used : VmService(org.dartlang.vm.service.VmService)

Example 4 with VmService

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

the class DartVmServiceDebugProcess method connect.

private void connect(@NotNull final String url) throws IOException {
    final VmService vmService = VmService.connect(url);
    final DartVmServiceListener vmServiceListener = new DartVmServiceListener(this, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
    vmService.addVmServiceListener(vmServiceListener);
    myVmServiceWrapper = new VmServiceWrapper(this, vmService, vmServiceListener, myIsolatesInfo, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
    myVmServiceWrapper.handleDebuggerConnected();
    myVmConnected = true;
}
Also used : VmService(org.dartlang.vm.service.VmService)

Example 5 with VmService

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

the class DartVmServiceDebugProcessZ method onConnectSucceeded.

private void onConnectSucceeded(VmService vmService, VmOpenSourceLocationListener vmOpenSourceLocationListener) {
    final DartVmServiceListener vmServiceListener = new DartVmServiceListener(this, (DartVmServiceBreakpointHandler) myBreakpointHandlers[0]);
    final DartVmServiceBreakpointHandler breakpointHandler = (DartVmServiceBreakpointHandler) myBreakpointHandlers[0];
    myVmOpenSourceLocationListener = vmOpenSourceLocationListener;
    myVmServiceWrapper = new VmServiceWrapper(this, vmService, vmServiceListener, myIsolatesInfo, breakpointHandler);
    final ScriptProvider provider = (isolateId, scriptId) -> myVmServiceWrapper.getScriptSync(isolateId, scriptId);
    mapper.onConnect(provider, myConnector.getRemoteBaseUrl());
    // We disable the remote debug flag so that handleDebuggerConnected() does not echo the stdout and
    // stderr streams (this would duplicate what we get over daemon logging).
    remoteDebug = false;
    final FlutterLaunchMode launchMode = FlutterLaunchMode.getMode(executionEnvironment);
    if (launchMode.supportsDebugConnection()) {
        myVmServiceWrapper.handleDebuggerConnected();
    }
    // We re-enable the remote debug flag so that the service wrapper will call our guessRemoteProjectRoot()
    // method with the list of loaded libraries for the isolate.
    remoteDebug = true;
    vmService.addVmServiceListener(vmServiceListener);
    myVmOpenSourceLocationListener.addListener(this::onOpenSourceLocationRequest);
    myVmConnected = true;
    getSession().rebuildViews();
    onVmConnected(vmService);
}
Also used : java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ObservatoryConnector(com.jetbrains.lang.dart.ide.runner.ObservatoryConnector) DartVmServiceSuspendContext(com.jetbrains.lang.dart.ide.runner.server.vmService.frame.DartVmServiceSuspendContext) THashSet(gnu.trove.THashSet) FlutterLaunchMode(io.flutter.run.FlutterLaunchMode) org.dartlang.vm.service.element(org.dartlang.vm.service.element) XDebuggerEditorsProvider(com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider) GetObjectConsumer(org.dartlang.vm.service.consumer.GetObjectConsumer) XDebuggerBundle(com.intellij.xdebugger.XDebuggerBundle) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) WindowListener(java.awt.event.WindowListener) ProjectUtil(com.intellij.ide.impl.ProjectUtil) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) ExecutionResult(com.intellij.execution.ExecutionResult) Logging(org.dartlang.vm.service.logging.Logging) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) Logger(com.intellij.openapi.diagnostic.Logger) XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugSessionListener(com.intellij.xdebugger.XDebugSessionListener) XSuspendContext(com.intellij.xdebugger.frame.XSuspendContext) DartDebuggerEditorsProvider(com.jetbrains.lang.dart.ide.runner.base.DartDebuggerEditorsProvider) Frame(java.awt.Frame) WindowManager(com.intellij.openapi.wm.WindowManager) VmService(org.dartlang.vm.service.VmService) IOException(java.io.IOException) XBreakpointHandler(com.intellij.xdebugger.breakpoints.XBreakpointHandler) FlutterBundle(io.flutter.FlutterBundle) SystemInfo(com.intellij.openapi.util.SystemInfo) WindowEvent(java.awt.event.WindowEvent) StandardCharsets(java.nio.charset.StandardCharsets) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) XSourcePosition(com.intellij.xdebugger.XSourcePosition) TimeoutUtil(com.intellij.util.TimeoutUtil) DartVmServiceStackFrame(com.jetbrains.lang.dart.ide.runner.server.vmService.frame.DartVmServiceStackFrame) BitUtil(com.intellij.util.BitUtil) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) FlutterLaunchMode(io.flutter.run.FlutterLaunchMode)

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