Search in sources :

Example 1 with ObservatoryConnector

use of io.flutter.ObservatoryConnector 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 ObservatoryConnector

use of io.flutter.ObservatoryConnector in project flutter-intellij by flutter.

the class FlutterTestRunner method runInDebugger.

protected RunContentDescriptor runInDebugger(@NotNull TestLaunchState launcher, @NotNull ExecutionEnvironment env) throws ExecutionException {
    // Start process and create console.
    final ExecutionResult executionResult = launcher.execute(env.getExecutor(), this);
    final ObservatoryConnector connector = new Connector(executionResult.getProcessHandler());
    // Set up source file mapping.
    final DartUrlResolver resolver = DartUrlResolver.getInstance(env.getProject(), launcher.getTestFileOrDir());
    final FlutterPositionMapper.Analyzer analyzer = FlutterPositionMapper.Analyzer.create(env.getProject(), launcher.getTestFileOrDir());
    final FlutterPositionMapper mapper = new FlutterPositionMapper(env.getProject(), launcher.getPubRoot().getRoot(), resolver, analyzer);
    // Create the debug session.
    final XDebuggerManager manager = XDebuggerManager.getInstance(env.getProject());
    final XDebugSession session = manager.startSession(env, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            return new TestDebugProcess(env, session, executionResult, resolver, connector, mapper);
        }
    });
    return session.getRunContentDescriptor();
}
Also used : ObservatoryConnector(io.flutter.ObservatoryConnector) XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) ExecutionResult(com.intellij.execution.ExecutionResult) ObservatoryConnector(io.flutter.ObservatoryConnector) NotNull(org.jetbrains.annotations.NotNull) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) FlutterPositionMapper(io.flutter.run.FlutterPositionMapper)

Aggregations

ExecutionResult (com.intellij.execution.ExecutionResult)2 ObservatoryConnector (io.flutter.ObservatoryConnector)2 RunContentBuilder (com.intellij.execution.runners.RunContentBuilder)1 XDebugProcess (com.intellij.xdebugger.XDebugProcess)1 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)1 XDebugSession (com.intellij.xdebugger.XDebugSession)1 XDebuggerManager (com.intellij.xdebugger.XDebuggerManager)1 DartUrlResolver (com.jetbrains.lang.dart.util.DartUrlResolver)1 FlutterPositionMapper (io.flutter.run.FlutterPositionMapper)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 NotNull (org.jetbrains.annotations.NotNull)1