public void addBreakpoint(
      @NotNull final String isolateId,
      @Nullable final XSourcePosition position,
      @NotNull final VmServiceConsumers.BreakpointConsumerWrapper consumer) {
    if (position == null || position.getFile().getFileType() != DartFileType.INSTANCE) {
      consumer.sourcePositionNotApplicable();
      return;
    }

    addRequest(
        () -> {
          final int line = position.getLine() + 1;
          for (String uri : myDebugProcess.getUrisForFile(position.getFile())) {
            myVmService.addBreakpointWithScriptUri(isolateId, uri, line, consumer);
          }
        });
  }
 private void setInitialBreakpointsAndResume(@NotNull final IsolateRef isolateRef) {
   if (myDebugProcess.isRemoteDebug()) {
     if (myDebugProcess.myRemoteProjectRootUri == null) {
       // need to detect remote project root path before setting breakpoints
       getIsolate(
           isolateRef.getId(),
           new VmServiceConsumers.GetIsolateConsumerWrapper() {
             @Override
             public void received(final Isolate isolate) {
               myDebugProcess.guessRemoteProjectRoot(isolate.getLibraries());
               doSetInitialBreakpointsAndResume(isolateRef);
             }
           });
     } else {
       doSetInitialBreakpointsAndResume(isolateRef);
     }
   } else {
     doSetInitialBreakpointsAndResume(isolateRef);
   }
 }
  public void handleDebuggerConnected() {
    streamListen(
        VmService.DEBUG_STREAM_ID,
        new VmServiceConsumers.SuccessConsumerWrapper() {
          @Override
          public void received(final Success success) {
            myVmServiceReceiverThreadId = Thread.currentThread().getId();
            streamListen(
                VmService.ISOLATE_STREAM_ID,
                new VmServiceConsumers.SuccessConsumerWrapper() {
                  @Override
                  public void received(final Success success) {
                    getVm(
                        new VmServiceConsumers.VmConsumerWrapper() {
                          @Override
                          public void received(final VM vm) {
                            if (vm.getIsolates().size() == 0) {
                              Logging.getLogger()
                                  .logError(
                                      "No isolates found after VM start: "
                                          + vm.getIsolates().size());
                            }

                            for (final IsolateRef isolateRef : vm.getIsolates()) {
                              getIsolate(
                                  isolateRef.getId(),
                                  new VmServiceConsumers.GetIsolateConsumerWrapper() {
                                    @Override
                                    public void received(final Isolate isolate) {
                                      final Event event = isolate.getPauseEvent();
                                      final EventKind eventKind = event.getKind();

                                      // if event is not PauseStart it means that PauseStart event
                                      // will follow later and will be handled by listener
                                      handleIsolate(isolateRef, eventKind == EventKind.PauseStart);

                                      // Handle the case of isolates paused when we connect (this
                                      // can come up in remote debugging).
                                      if (eventKind == EventKind.PauseBreakpoint
                                          || eventKind == EventKind.PauseException
                                          || eventKind == EventKind.PauseInterrupted) {
                                        myDebugProcess.isolateSuspended(isolateRef);

                                        ApplicationManager.getApplication()
                                            .executeOnPooledThread(
                                                () -> {
                                                  final ElementList<Breakpoint> breakpoints =
                                                      eventKind == EventKind.PauseBreakpoint
                                                          ? event.getPauseBreakpoints()
                                                          : null;
                                                  final InstanceRef exception =
                                                      eventKind == EventKind.PauseException
                                                          ? event.getException()
                                                          : null;
                                                  myVmServiceListener.onIsolatePaused(
                                                      isolateRef,
                                                      breakpoints,
                                                      exception,
                                                      event.getTopFrame(),
                                                      event.getAtAsyncSuspension());
                                                });
                                      }
                                    }
                                  });
                            }
                          }
                        });
                  }
                });
          }
        });

    if (myDebugProcess.isRemoteDebug()) {
      streamListen(VmService.STDOUT_STREAM_ID, VmServiceConsumers.EMPTY_SUCCESS_CONSUMER);
      streamListen(VmService.STDERR_STREAM_ID, VmServiceConsumers.EMPTY_SUCCESS_CONSUMER);
    }
  }