VSCode JSON language server unhandled method

时间:2019-04-08 13:51:16

标签: json visual-studio-code vscode-extensions language-server-protocol

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.

1 个答案:

答案 0 :(得分:0)

EDIT2:更新,我弄清楚了其中的一些错误。根据LSP,initialized和textDocument / didChange是通知,不是请求。请求中有一个ID字段,通知没有,所以发送通知时,请删除ID字段。