我上周发布了this,并取得了进展,在那里我发现了VSCode的JSON支持通过扩展提供的包:
https://github.com/vscode-langservers/vscode-json-languageserver https://github.com/Microsoft/vscode-json-languageservice
以及其他所有的事情。我正尝试在一个电子(NodeJS)应用程序中重用它。我能够派生一个启动语言服务器并初始化它的进程:
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);
});我看到console.log启动,并显示它似乎是正确的。我的想法是,我只想根据LSP发送一个textDocument/didChange事件
send('textDocument/didChange', {
textDocument: TextDocument.create('foo://bar/file.json', 'json', 0, JSON.stringify(data))
});其中data是表示文件的JSON对象。
当我发送该消息并尝试其他操作时,我收到
error: {code: -32601, message: "Unhandled method textDocument/didChange"}
id: 2
jsonrpc: "2.0"你知道我哪里做错了吗?我的主要目标是允许通过我的Electron应用程序进行编辑,然后将更新后的JSON发送到语言服务器以完成模式验证。
编辑:当我在jsonServerMain.js中实现connection.onInitialized()时,我甚至看到未处理的方法被初始化。
EDIT2:更新,我找出了我在这方面的一些错误。initialized和textDocument/didChange是通知,而不是请求。
发布于 2019-04-09 01:46:39
EDIT2:更新,我找出了我在这方面的一些错误。根据LSP,initialized和textDocument/didChange是通知,而不是请求。请求有一个通知没有的id字段,所以在发送通知时,删除ID字段。
https://stackoverflow.com/questions/55575040
复制相似问题