vscode-languageclient#ExecutableOptions TypeScript Examples

The following examples show how to use vscode-languageclient#ExecutableOptions. 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: server.ts    From plugin-vscode with Apache License 2.0 6 votes vote down vote up
export function getServerOptions(ballerinaCmd: string): ServerOptions {
    debug(`Using Ballerina CLI command '${ballerinaCmd}' for Language server.`);
    let cmd = process.platform === 'win32' ? getConvertedPath(ballerinaCmd) : ballerinaCmd;
    let args = ["start-language-server"];
    let opt: ExecutableOptions = {};
    opt.env = Object.assign({}, process.env);

    if (process.env.LS_EXTENSIONS_PATH !== "") {
        if (opt.env.BALLERINA_CLASSPATH_EXT) {
            opt.env.BALLERINA_CLASSPATH_EXT += delimiter + process.env.LS_EXTENSIONS_PATH;
        } else {
            opt.env.BALLERINA_CLASSPATH_EXT = process.env.LS_EXTENSIONS_PATH;
        }
    }
    if (process.env.LSDEBUG === "true") {
        debug('Language Server is starting in debug mode.');
        let debugPort = 5005;
        opt.env.BAL_JAVA_DEBUG = debugPort;
        opt.env.BAL_DEBUG_OPTS = "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + debugPort + ",quiet=y";
    }

    if (process.env.LS_CUSTOM_CLASSPATH) {
        args.push('--classpath', process.env.LS_CUSTOM_CLASSPATH);
    }

    return {
        command: cmd,
        args,
        options: opt
    };
}
Example #2
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 #3
Source File: debugger.test.ts    From plugin-vscode with Apache License 2.0 4 votes vote down vote up
suite('Ballerina Debug Adapter', () => {

    const PROJECT_ROOT = path.join(__dirname, '..', '..', '..');
    const DATA_ROOT = path.join(PROJECT_ROOT, 'test', 'data');
    const BALLERINA_HOME = getBallerinaHome();
    const DEBUG_PORT = 4711;

    let dc: DebugClient;
    let serverProcess: any;

    setup(async () => {
        const cwd = path.join(BALLERINA_HOME, "bin");

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

        let cmd = '';
        let args: string[] = [];
        if (process.platform === 'win32') {
            cmd = path.join(cwd, 'bal.bat');
        } else {
            cmd = path.join(cwd, 'bal');
        }
        args.push('start-debugger-adapter');
        args.push(DEBUG_PORT.toString());
        serverProcess = child_process.spawn(cmd, args, opt);
        dc = new DebugClient("", "", 'ballerina', { cwd: PROJECT_ROOT });
        dc.defaultTimeout = 60000;

        await new Promise<void>((resolve) => {
            serverProcess.stdout.on('data', (data: any) => {
                if (data.toString().includes('Debug server started')) {
                    resolve();
                }
            });
            serverProcess.stderr.on('data', (data_1: any) => {
                console.error(`${data_1}`);
            });
        });
        return await dc.start(DEBUG_PORT);
    });

    teardown(() => {
        if (process.platform === 'win32') {
            dc.stop();
            if (serverProcess) {
                serverProcess.kill();
            }
            return Promise.resolve();
        } else {
            dc.terminateRequest({}).then(() => {
                if (serverProcess) {
                    serverProcess.kill();
                }
            });
        }
        return new Promise<void>((resolve) => {
            serverProcess.on('close', (code: any) => {
                resolve();
                console.log(`child process exited with code ${code}`);
            });
        });
    });

    suite('vscode debugger integration tests', () => {
        test('Initialize request', async () => {
            const response = await dc.initializeRequest();
            response.body = response.body || {};
            assert.equal(response.body.supportsConfigurationDoneRequest, true, 'Invalid config done rquest.');
        }).timeout(20000);

        test('launch request', async () => {
            const program = path.join(DATA_ROOT, 'hello_world.bal');
            const debuggeePort = await getAvailablePort(5005);
            const response = await dc.launch({
                script: program,
                "ballerina.home": BALLERINA_HOME,
                request: "launch",
                name: "Ballerina Debug",
                "debugServer": DEBUG_PORT,
                "debuggeePort": debuggeePort
            });

            assert.equal(response.success, true, 'Invalid response state.');
            assert.equal(response.command, 'launch', 'Invalid response command.');
        }).timeout(20000);

        test('should stop on a breakpoint, main function', async () => {
            const program = path.join(DATA_ROOT, 'hello_world.bal');
            const debuggeePort = await getAvailablePort(5006);
            const launchArgs = {
                script: program,
                "ballerina.home": BALLERINA_HOME,
                request: "launch",
                name: "Ballerina Debug",
                "debugServer": DEBUG_PORT,
                "debuggeePort": debuggeePort
            };
            return await dc.hitBreakpoint(launchArgs, { path: program, line: 5 });
        }).timeout(20000);

        test('should stop on a breakpoint, hello world service', async () => {
            const program = path.join(DATA_ROOT, 'hello_world_service.bal');
            const debuggeePort = await getAvailablePort(5007);
            const launchArgs = {
                script: program,
                "ballerina.home": BALLERINA_HOME,
                request: "launch",
                name: "Ballerina Debug",
                "debugServer": DEBUG_PORT,
                "debuggeePort": debuggeePort
            };

            dc.on('output', (res) => {
                if (res.body.output.indexOf("started HTTP/WS") > -1) {
                    http.get('http://0.0.0.0:9090/hello/sayHello');
                }
            });
            return await dc.hitBreakpoint(launchArgs, { path: program, line: 11 });
        }).timeout(20000);

        test('should stop on a breakpoint, hello world service - package', async () => {
            const program = path.join(DATA_ROOT, 'helloServicePackage', 'hello_service.bal');
            const debuggeePort = await getAvailablePort(5008);
            const launchArgs = {
                script: program,
                "ballerina.home": BALLERINA_HOME,
                request: "launch",
                name: "Ballerina Debug",
                "debugServer": DEBUG_PORT,
                "debuggeePort": debuggeePort
            };

            dc.on('output', (res) => {
                if (res.body.output.indexOf("started HTTP/WS") > -1) {
                    http.get('http://0.0.0.0:9091/hello/sayHello');
                }
            });
            return await dc.hitBreakpoint(launchArgs, { path: program, line: 11 });
        }).timeout(20000);

        test('step In, hello world service - package', async () => {
            const program = path.join(DATA_ROOT, 'helloPackage', 'modules', 'hello', 'hello_service.bal');
            const debuggeePort = await getAvailablePort(5009);
            const launchArgs = {
                script: program,
                "ballerina.home": BALLERINA_HOME,
                request: "launch",
                name: "Ballerina Debug",
                "debugServer": DEBUG_PORT,
                "debuggeePort": debuggeePort
            };

            const location = { path: program, line: 17, column: undefined };
            return await Promise.all([
                dc.waitForEvent('initialized').then(event => {
                    return dc.setBreakpointsRequest({
                        lines: [location.line],
                        breakpoints: [{ line: location.line, column: location.column }],
                        source: { path: location.path }
                    });
                }).then(response => {
                    const bp = response.body.breakpoints[0];
                    assert.equal(bp.verified, true, 'breakpoint verification mismatch: verified');
                    const actualLocation = {
                        column: bp.column,
                        line: bp.line,
                        path: bp.source && bp.source.path
                    };
                    if (actualLocation.path) {
                        assert.equal(actualLocation.path, location.path, 'breakpoint verification mismatch: path');
                    }
                    if (typeof actualLocation.line === 'number') {
                        assert.equal(actualLocation.line, location.line, 'breakpoint verification mismatch: line');
                    }
                    if (typeof location.column === 'number' && typeof actualLocation.column === 'number') {
                        assert.equal(actualLocation.column, location.column, 'breakpoint verification mismatch: column');
                    }
                    return dc.configurationDoneRequest();
                }),
                dc.launch(launchArgs),
                dc.waitForEvent('stopped').then(async event => {
                    assert.equal(event.body.reason, 'breakpoint', 'Invalid \'breakpoint\' stopped event.');
                    await dc.stepInRequest({
                        threadId: event.body.threadId
                    });
                    const stepInEvent = await dc.waitForEvent('stopped', 12000);
                    assert.equal(stepInEvent.body.reason, "step", 'Invalid \'step\' stopped event.');
                    return await dc.stackTraceRequest({
                        threadId: stepInEvent.body.threadId,
                    });
                })
            ]);
        }).timeout(100000);
    });
});