vscode#DebugSession TypeScript Examples

The following examples show how to use vscode#DebugSession. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: config-provider.ts    From plugin-vscode with Apache License 2.0 5 votes vote down vote up
createDebugAdapterDescriptor(session: DebugSession, executable: DebugAdapterExecutable | undefined): Thenable<DebugAdapterDescriptor> {
        const port = session.configuration.debugServer;
        const cwd = this.getCurrentWorkingDir();
        let args: string[] = [];
        const cmd = this.getScriptPath(args);

        if (ballerinaExtInstance.is12x) {
            const SHOW_VSCODE_IDE_DOCS = "https://ballerina.io/1.2/learn/setting-up-visual-studio-code/run-and-debug/";
            const showDetails: string = 'Learn More';
            window.showWarningMessage("Ballerina Debugging is an experimental feature. Click \"Learn more\" for known limitations and workarounds.",
                showDetails).then((selection) => {
                    if (showDetails === selection) {
                        commands.executeCommand('vscode.open', Uri.parse(SHOW_VSCODE_IDE_DOCS));
                    }
                });
        }
        args.push(port.toString());

        let opt: ExecutableOptions = { cwd: cwd };
        opt.env = Object.assign({}, process.env);

        const serverProcess = child_process.spawn(cmd, args, opt);

        log(`Starting debug adapter: '${this.ballerinaExtInstance.getBallerinaCmd()} start-debugger-adapter ${port.toString()}`);

        return new Promise<void>((resolve) => {
            serverProcess.stdout.on('data', (data) => {
                if (data.toString().includes('Debug server started')) {
                    resolve();
                }
                log(`${data}`);
            });

            serverProcess.stderr.on('data', (data) => {
                debugLog(`${data}`);
            });
        }).then(() => {
            sendTelemetryEvent(ballerinaExtInstance, TM_EVENT_START_DEBUG_SESSION, CMP_DEBUGGER);
            return new DebugAdapterServer(port);
        }).catch((error) => {
            sendTelemetryException(ballerinaExtInstance, error, CMP_DEBUGGER);
            return Promise.reject(error);
        });
    }
Example #2
Source File: debugger.ts    From karma-test-explorer with MIT License 5 votes vote down vote up
public startDebugSession(
    workspaceFolder: WorkspaceFolder,
    debuggerNameOrConfig: string | DebugConfiguration,
    sessionStartTimeout: number
  ): Execution<DebugSession> {
    const deferredDebugSessionExecution: DeferredExecution<DebugSession> = new DeferredExecution();
    const debugSessionExecution = deferredDebugSessionExecution.execution();
    const debuggerNamespaceTag = this.options?.debuggerNamespace ? ` - ${this.options?.debuggerNamespace}` : '';

    const actualDebuggerNameOrConfig =
      typeof debuggerNameOrConfig === 'string'
        ? debuggerNameOrConfig
        : { ...debuggerNameOrConfig, name: `${debuggerNameOrConfig.name}${debuggerNamespaceTag}` };

    const debuggerConfigName =
      typeof actualDebuggerNameOrConfig === 'string' ? actualDebuggerNameOrConfig : actualDebuggerNameOrConfig.name;

    try {
      const activeDebugSession = debug.activeDebugSession;

      if (activeDebugSession && activeDebugSession.name === debuggerConfigName) {
        this.logger.info(() => `Debug session '${activeDebugSession.name}' is alredy active`);
        deferredDebugSessionExecution.start(activeDebugSession);
        this.activeDebugSession = activeDebugSession;
      } else {
        const debugStartSubscription: Disposable = debug.onDidStartDebugSession(session => {
          if (session.name === debuggerConfigName) {
            this.logger.info(() => `Debug session '${session.name}' has started`);
            deferredDebugSessionExecution.start(session);
            this.activeDebugSession = session;
          }
        });

        debugSessionExecution.started().finally(() => debugStartSubscription.dispose());

        debug.startDebugging(workspaceFolder, actualDebuggerNameOrConfig).then(
          isSessionStarted => {
            if (!isSessionStarted) {
              deferredDebugSessionExecution.fail(`Debug session '${debuggerConfigName}' failed to start`);
            }
          },
          reason =>
            deferredDebugSessionExecution.fail(
              `Debug session '${debuggerConfigName}' failed to start: ${reason.message ?? reason}`
            )
        );

        deferredDebugSessionExecution.failIfNotStarted(
          sessionStartTimeout,
          `Timeout after waiting ${sessionStartTimeout} ms for debug session '${debuggerConfigName}' to start`
        );
      }

      debugSessionExecution.started().then(debugSession => {
        const debugStopSubscription = debug.onDidTerminateDebugSession(session => {
          if (session === debugSession) {
            this.logger.info(() => `Debug session '${session.name}' has ended`);
            deferredDebugSessionExecution.end();
            this.activeDebugSession = undefined;
            debugStopSubscription.dispose();
          }
        });
      });
    } catch (error) {
      deferredDebugSessionExecution.fail(`Debug session '${debuggerConfigName}' failed to start: ${error}`);
    }

    return debugSessionExecution;
  }
Example #3
Source File: debugger.ts    From karma-test-explorer with MIT License 5 votes vote down vote up
private activeDebugSession?: DebugSession;
Example #4
Source File: karma-test-explorer.ts    From karma-test-explorer with MIT License 5 votes vote down vote up
public async debugTests(testIds: string[]): Promise<void> {
    if (!this.verifyNoTestProcessCurrentlyRunning('New test debug request ignored')) {
      return;
    }
    this.isTestProcessRunning = true;

    this.logger.info(() => 'Starting debug session');
    this.logger.debug(() => `Test debug is requested for ${testIds.length} test ids`);
    this.logger.trace(() => `Requested test ids for test debug: ${JSON.stringify(testIds)}`);

    try {
      let debugSessionExecution: Execution<DebugSession>;
      let debugSession: DebugSession;

      try {
        this.logger.debug(() => 'Ensuring Test Manager is started for debug test run');

        const serverStartInfo: ServerStartInfo = await this.testManager.start();

        const debuggerConfig = this.config.debuggerConfigName || {
          ...this.config.debuggerConfig,
          port: serverStartInfo.debugPort ?? this.config.debuggerConfig.port
        };

        const debuggerConfigName = typeof debuggerConfig === 'string' ? debuggerConfig : debuggerConfig.name;
        const debuggerPort = typeof debuggerConfig !== 'string' ? debuggerConfig.port : undefined;

        if (debuggerPort) {
          this.logger.debug(
            () =>
              `Starting debug session '${debuggerConfigName}' ` +
              'with requested --> available debug port: ' +
              `${this.config.debuggerConfig.port ?? '<none>'} --> ${debuggerPort}`
          );
        } else {
          this.logger.debug(() => `Starting debug session '${debuggerConfigName}'`);
        }

        const deferredDebugSessionStart = new DeferredPromise();

        this.notificationHandler.notifyStatus(
          StatusType.Busy,
          `Starting debug session: ${debuggerConfigName}`,
          deferredDebugSessionStart.promise()
        );

        debugSessionExecution = this.testDebugger.startDebugSession(
          this.workspaceFolder,
          debuggerConfig,
          DEBUG_SESSION_START_TIMEOUT
        );

        debugSession = await debugSessionExecution.started();
        deferredDebugSessionStart.fulfill();
      } catch (error) {
        const errorMessage = `Test debug run failed - ${(error as Error).message ?? error}`;
        this.logger.error(() => errorMessage);

        this.notificationHandler.notify(MessageType.Error, errorMessage, [
          { label: 'Retry Debug', handler: () => this.debugTests(testIds) },
          { label: 'Retry With Run', handler: () => this.runTests(testIds) }
        ]);

        return;
      }

      await this.runTests(testIds, true);
      await debug.stopDebugging(debugSession);
      await debugSessionExecution.ended();
    } finally {
      this.isTestProcessRunning = false;
    }
  }