【问题标题】:VSCode JSON language server unhandled methodVSCode JSON 语言服务器未处理方法
【发布时间】: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


    【解决方案1】:

    EDIT2:更新,我发现其中一些问题出在哪里。根据 LSP,initialized 和 textDocument/didChange 是通知,而不是请求。请求具有通知没有的 id 字段,因此在发送通知时,请删除 ID 字段。

    【讨论】:

      猜你喜欢
      • 2018-09-15
      • 1970-01-01
      • 2016-06-04
      • 2022-01-15
      • 2013-11-28
      • 2018-10-17
      • 2016-05-19
      • 2017-03-10
      • 1970-01-01
      相关资源
      最近更新 更多