0

I posted this last week and have made progress since, where I've discovered the packages that VSCode's JSON support is delivered via extensions:

https://github.com/vscode-langservers/vscode-json-languageserver https://github.com/Microsoft/vscode-json-languageservice

and all the rest. I'm trying to reuse this in an Electron (NodeJS) app. I'm able to fork a process starting the language server and initialize it:

lspProcess = child_process.fork("node_modules/vscode-json-languageserver/out/jsonServerMain.js", [ "--node-ipc" ]);    
function initialize() {
    send("initialize", {
        rootPath: process.cwd(),
        processId: process.pid,
        capabilities: {
            textDocument: true
        }
    });
}

lspProcess.on('message', function (json) {
    console.log(json);
});

and I see that console.log firing and showing it seems to be up correctly. My thoughts are that I just want to send a textDocument/didChange event as per the LSP:

send('textDocument/didChange', {
    textDocument: TextDocument.create('foo://bar/file.json', 'json', 0, JSON.stringify(data))
});

where data is a JSON object representing a file.

When I send that message and other attempts at it I get

error: {code: -32601, message: "Unhandled method textDocument/didChange"}
id: 2
jsonrpc: "2.0"

Any idea what I'm doing wrong here? My main goal is to allow edits through my Electron app and then send the updated JSON to the language server to get schema validation done.

EDIT: I'm even seeing unhandled method initialized when I implement connection.onInitialized() in the jsonServerMain.js.

EDIT2: Update, I figured out where I was going wrong with some of this. initialized and textDocument/didChange are notifications, not requests.

cdietschrun
  • 1,623
  • 6
  • 23
  • 39

1 Answers1

1

EDIT2: Update, I figured out where I was going wrong with some of this. According to the LSP, initialized and textDocument/didChange are notifications, not requests. Requests have an id field that notifications don't, so when sending a notification, remove the ID field.

cdietschrun
  • 1,623
  • 6
  • 23
  • 39