首页 > 解决方案 > 如何连接我用 C++ 实现的语言服务器

问题描述

我假设协议使用标准输入/标准输出作为通道

但是当我开始 vscode 调试时,我的 exe 没有启动。如何启动我的 exe?


我的配置:

{
        "type": "extensionHost",
        "request": "launch",
        "name": "Launch Client",
        // "runtimeExecutable": "${execPath}",
        "runtimeExecutable": "C:/vscode-ext/lsp_cpp_ravi/cmake-build-debug/lsp-aaa.exe",
        "args": ["--extensionDevelopmentPath=${workspaceRoot}"],
        "outFiles": ["${workspaceRoot}/client/out/**/*.js"],
        "preLaunchTask": {
            "type": "npm",
            "script": "watch"
        }
    },

此配置是从 lsp-sample 复制的,我更改了runtimeexecutable字段


客户端代码:

export function activate(context: ExtensionContext) {
    // The server is implemented in node
    // let serverModule = context.asAbsolutePath(
    //  // path.join('server', 'out', 'server.js')
    //  path.join('C:\\vscode-ext\\lsp_cpp_ravi\\cmake-build-debug', 'lsp-ravi.exe')
    // );
    let serverModule = ''

    // The debug options for the server
    // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
    let debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };

    // If the extension is launched in debug mode then the debug server options are used
    // Otherwise the run options are used
    let serverOptions: ServerOptions = {
        run: { module: serverModule, transport: TransportKind.ipc },
        debug: {
            module: serverModule,
            transport: TransportKind.ipc,
            options: debugOptions
        }
    };

    // Options to control the language client
    let clientOptions: LanguageClientOptions = {
        // Register the server for plain text documents
        documentSelector: [{ scheme: 'file', language: 'plaintext' }],
        synchronize: {
            // Notify the server about file changes to '.clientrc files contained in the workspace
            fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
        }
    };

    // Create the language client and start the client.
    client = new LanguageClient(
        'languageServerExample',
        'Language Server Example',
        serverOptions,
        clientOptions
    );

    // Start the client. This will also launch the server
    client.start();
}

是否可以使用 TCP 作为连接方式?

标签: visual-studio-codevscode-extensionslanguage-server-protocol

解决方案


好的,这就解决了。

因为我没有打开任何文件夹,所以客户端没有调用“活动”。

然后我使用这里的答案 [https://github.com/microsoft/vscode-languageserver-node/issues/662] 连接到 TCP


推荐阅读