Context: I am trying to write an extension to vscode that will connect to a language server that is already running. The reason I want to do this is so I can run the language server in my IDE, and attach a debugger to it.
I am trying to connect using websockets. This is the code I have in my extension:
import * as vscode from 'vscode';
import WebSocket from 'ws';
import { TextDecoder } from 'util';
// Import the language client, language client options and server options from VSCode language client.
import { LanguageClient } from 'vscode-languageclient';
// Name of the launcher class which contains the main.
const main: string = 'com.ajanuary.ashlang.lsp.AsLangLanguageServerLauncher';
export function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "ashlang" is now active!');
const ws = new WebSocket(`ws://localhost:5000/`);
const connection = WebSocket.createWebSocketStream(ws);
connection.on("data", function (chunk) {
console.log(new TextDecoder().decode(chunk));
});
let disposable = new LanguageClient('ashLS', 'Ash Language Server',
() => Promise.resolve({
reader: connection,
writer: connection,
}), {
documentSelector: [{ scheme: 'file', language: 'ash' }]
}).start();
context.subscriptions.push(disposable);
}
// this method is called when your extension is deactivated
export function deactivate() {
console.log('Your extension "ashlang" is now deactivated!');
}
The data handler prints out:
{"jsonrpc":"2.0","id":0,"result":{"capabilities":{"textDocumentSync":1,"completionProvider":{}}}}
So I know it is able to talk to my server and read the response. However, the extension doesn't seem to handle the response because it never sends any more messages.
How do I get it to read and process the messages from the websocket correctly? Or is there a better way of tackling the problem of developing the languageserver in an IDE?