VS Code中如何显示LSP的相关信息
How to display LSP's relatedInformation in VS Code
我正在编写一个语言服务器。它提供了额外的 DiagnosticRelatedInformation as part of its diagnostics response. Just like in https://code.visualstudio.com/updates/v1_22#_related-information-in-errors-and-warnings。
目前,虽然我确实看到 "Problems" window 和主文本区域中都显示了主要错误,但附加的 "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 是正确的(虽然为了便于阅读而在此处进行了修改)因为我可以单击它们并且编辑器会跳转到正确的文件。
我的问题是我不知道如何检验关于问题所在的一个或另一个假设。或者也许我错过了一些完全不同的东西?
问题只是 package.json 的依赖项部分中 vscode-languageclient
的过时版本。该功能是在 4.1.0 中实现的,但由于我的项目有点过时,它只需要 3.5 以上的东西。我现在已经更新到最新版本,一切正常。
我正在编写一个语言服务器。它提供了额外的 DiagnosticRelatedInformation as part of its diagnostics response. Just like in https://code.visualstudio.com/updates/v1_22#_related-information-in-errors-and-warnings。 目前,虽然我确实看到 "Problems" window 和主文本区域中都显示了主要错误,但附加的 "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 是正确的(虽然为了便于阅读而在此处进行了修改)因为我可以单击它们并且编辑器会跳转到正确的文件。
我的问题是我不知道如何检验关于问题所在的一个或另一个假设。或者也许我错过了一些完全不同的东西?
问题只是 package.json 的依赖项部分中 vscode-languageclient
的过时版本。该功能是在 4.1.0 中实现的,但由于我的项目有点过时,它只需要 3.5 以上的东西。我现在已经更新到最新版本,一切正常。