1 year ago

#375274

test-img

Paulo Aboim Pinto

VSCode Extension with LSP in C#, how to terminate the LSP dll?

I have a very simple extension that loads a DLL that will contain my LSP project.

namespace SimpleLsp
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var server = await OmniSharp.Extensions.LanguageServer.Server.LanguageServer
                .From(
                    options => options
                        .WithInput(Console.OpenStandardInput())
                        .WithOutput(Console.OpenStandardOutput())
                ).ConfigureAwait(false);

            await server.WaitForExit;
        }
    }
}

and the TypeScript extension

import * as vscode from 'vscode';
import path = require('path');
import { workspace } from 'vscode';

import {
    LanguageClient,
    LanguageClientOptions,
    ServerOptions,
    TransportKind,
} from "vscode-languageclient/node";

let client: LanguageClient;

export function activate(context: vscode.ExtensionContext) {
    
    console.log('Congratulations, your extension "simplelspextension" is now active!');

    const extensionPath = vscode.extensions.getExtension("PauloAboimPinto.simplelspextension")?.extensionPath as string;
    const libsFolder = path.join(extensionPath, "libs");
    const dllPath = path.join(libsFolder, "simpleLsp.dll");

    let serverOptions: ServerOptions = {
        run: {
            command: "dotnet",
            args: [dllPath],
            transport: TransportKind.pipe
        },
        debug: {
            command: "dotnet",
            args: [dllPath],
            transport: TransportKind.pipe,
            runtime: ""
        }
    };

    let clientOptions: LanguageClientOptions = {
        documentSelector: [
            {
                pattern: "**/*.xaml",
            },
            {
                pattern: "**/*.axaml",
            },
            {
                pattern: "**/*.csproj",
            },
        ],
          synchronize: {
            // Notify the server about file changes to '.clientrc files contained in the workspace
            fileEvents: workspace.createFileSystemWatcher('**/.axaml')
          }
    };

    client = new LanguageClient(
        "simpleLsp",
        "Simple Language Server Protocol",
        serverOptions,
        clientOptions
    );

    let disposableLsp = client.start();
    context.subscriptions.push(disposableLsp);
}

// this method is called when your extension is deactivated
export function deactivate() {
    if (!client) {
        return undefined;
    }

    return client.stop();
}

During deactivation I'm sending the stop command to the client, expecting the execution DLL to be terminated, but it's not.

When I close the VSCode I would expect the simpleLsp.dll to be terminated but it's not and I have to terminate it manually.

What I'm missing or doing wrong here? How I can terminate the execution of the DLL that contains the LSP?

thanks in advance

language-server-protocol

0 Answers

Your Answer

Accepted video resources