5

I'm writing a Language Server Protocol (LSP) server for use with neovim, and I'd like to test it against VSCode to make sure I've got all the details right and that I'm not accidentally encoding any neovim-isms into my implementation.

The current docs suggest I should write a VSCode extension to act as the client to my server, but I'm not really interested in putting that much effort into a platform I won't use.

In neovim I can just define a CLI command and the filetype it corresponds to and hit go:

let g:LanguageClient_serverCommands = {
    \ 'rust': ['rustup', 'run', 'nightly', 'rls'],
    \ 'javascript': ['/opt/javascript-typescript-langserver/lib/language-server-stdio.js'],
    \ }

does something similar exist in Visual Studio code?

alloyed
  • 51
  • 1
  • 3
  • You won't need a full bloat VSCode extension, but a minimal one to activate its LSP client. Unfortunately there is no simpler way I can think of. – Lex Li Dec 26 '17 at 14:25

1 Answers1

4

It takes little effort to write a language client in VSCode, here is how I did it:

export function activate(context: vscode.ExtensionContext) {

    // This line of code will only be executed once when your extension is activated

    // TODO: Start server exe and communicate with it
    let serverExe = <Path_to_server>;

    let ServerOptions: ServerOptions = {
        run: {command: serverExe, args:['-lsp']},
        debug: {command: serverExe, args:['-lsp']}
    }

    let clientOptions: LanguageClientOptions = {
        // Register the server for plain text documents
        documentSelector: [
            {
                pattern: '**/*.txt',
            }
        ],

    }

    let lspClient = new LanguageClient("Hello LSP", ServerOptions, clientOptions);

    // For debugging only
    //lspClient.trace = Trace.Verbose;

    //add all disposables here
    context.subscriptions.push(lspClient.start());
}

Once the client starts, it starts the server and starts the initialization conversation, the client watches all the important events on VSCode (document opened/closed/modified, Ctrl+space,...) and sends the right requests/notifications to the server

Ghost4Man
  • 1,040
  • 1
  • 12
  • 19
Youssef SABIH
  • 629
  • 6
  • 11
  • 5
    can you give the steps to actually running this in VSCode without publishing it in the npm and all that? – eri0o May 24 '20 at 01:45