【问题标题】:How to display LSP's relatedInformation in VS Code如何在 VS Code 中显示 LSP 相关信息
【发布时间】:2018-11-13 14:16:21
【问题描述】:

我正在编写一个语言服务器。它提供额外的DiagnosticRelatedInformation 作为其诊断响应的一部分。就像在https://code.visualstudio.com/updates/v1_22#_related-information-in-errors-and-warnings 中一样。 目前,虽然我确实在“问题”窗口和主文本区域中都看到了主要错误,但看不到额外的“relatedInformation”。

我怀疑这可能有两个原因。任一客户端:在 VS Code 中未启用显示此信息的功能。至少在协议启动的时候,这个能力是看不到的,下面是来自客户端的初始 JSON 消息:

[Trace - 2:22:13 PM] Sending request 'initialize - (0)'.
Params: {
    "processId": 6640,
    "rootPath": null,
    "rootUri": null,
    "capabilities": {
        "workspace": {
            "applyEdit": true,
            "didChangeConfiguration": {
                "dynamicRegistration": true
            },
            "didChangeWatchedFiles": {
                "dynamicRegistration": true
            },
            "symbol": {
                "dynamicRegistration": true
            },
            "executeCommand": {
                "dynamicRegistration": true
            }
        },
        "textDocument": {
            "synchronization": {
                "dynamicRegistration": true,
                "willSave": true,
                "willSaveWaitUntil": true,
                "didSave": true
            },
            "completion": {
                "dynamicRegistration": true,
                "completionItem": {
                    "snippetSupport": true,
                    "commitCharactersSupport": true
                }
            },
            "hover": {
                "dynamicRegistration": true
            },
            "signatureHelp": {
                "dynamicRegistration": true
            },
            "definition": {
                "dynamicRegistration": true
            },
            "references": {
                "dynamicRegistration": true
            },
            "documentHighlight": {
                "dynamicRegistration": true
            },
            "documentSymbol": {
                "dynamicRegistration": true
            },
            "codeAction": {
                "dynamicRegistration": true
            },
            "codeLens": {
                "dynamicRegistration": true
            },
            "formatting": {
                "dynamicRegistration": true
            },
            "rangeFormatting": {
                "dynamicRegistration": true
            },
            "onTypeFormatting": {
                "dynamicRegistration": true
            },
            "rename": {
                "dynamicRegistration": true
            },
            "documentLink": {
                "dynamicRegistration": true
            }
        }
    },
    "trace": "verbose"
}

顺便说一句,我在 Win10 上使用 VS Code 1.28.2。

另一个原因可能是服务器端:包含诊断的响应可能格式错误。它看起来像这样:

Params: {
    "diagnostics": [
        {
            "code": null,
            "message": "the declaration of 'x' shadows an existing declaration",
            "range": {
                "end": {
                    "character": 17,
                    "line": 8
                },
                "start": {
                    "character": 17,
                    "line": 8
                }
            },
            "relatedInformation": [
                {
                    "location": {
                        "uri": "file:///c%3A/Users/blabla/XlocalShadow3.blc",
                        "range": {
                            "end": {
                                "character": 13,
                                "line": 6
                            },
                            "start": {
                                "character": 13,
                                "line": 6
                            }
                        }
                    },
                    "message": "existing declaration"
                },
                {
                    "location": {
                        "uri": "file:///c%3A/Users/blabla/XlocalShadow3.blc",
                        "range": {
                            "end": {
                                "character": 17,
                                "line": 8
                            },
                            "start": {
                                "character": 17,
                                "line": 8
                            }
                        }
                    },
                    "message": "shadowing declaration"
                }
            ],
            "severity": {
                "_tag": 0
            },
            "source": "Parsing Error"
        }
    ],
    "uri": "file:///c%3A/Users/blabla/XlocalShadow3.blc"
}

至少 URI 是正确的(尽管为了便于阅读而在此处进行了修改),因为我可以单击它们并且编辑器会跳转到正确的文件。

我的问题是我不知道如何检验关于出了什么问题的一种或另一种假设。或者也许我错过了一些完全不同的东西?

【问题讨论】:

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


    【解决方案1】:

    问题只是 package.json 的依赖项部分中的 vscode-languageclient 版本过时。该功能是在 4.1.0 中实现的,但由于我的项目有点过时,它只需要 3.5 以上的东西。我现在已经更新到最新版本,一切正常。

    【讨论】:

      猜你喜欢
      • 2013-05-22
      • 2022-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-08
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多