【发布时间】:2019-04-08 13:51:15
【问题描述】:
我上周发布了 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 是通知,而不是请求。
【问题讨论】:
标签: json visual-studio-code vscode-extensions language-server-protocol