-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Related information of diagnostics is not parsed & displayed. #19649
Comments
@glepnir Are you still working on this? I also really would like to have this feature and would like to help out with the implementation if needed! |
In the meantime, for anyone who wants this, here's a quick and dirty implementation I added to my config: local function getlines(location)
local uri = location.targetUri or location.uri
if uri == nil then
return
end
local bufnr = vim.uri_to_bufnr(uri)
if not vim.api.nvim_buf_is_loaded(bufnr) then
vim.fn.bufload(bufnr)
end
local range = location.targetRange or location.range
local lines = vim.api.nvim_buf_get_lines(bufnr, range.start.line, range['end'].line+1, false)
return table.concat(lines, '\n')
end
vim.diagnostic.config({float = {format = function(diag)
local message = diag.message
local client = vim.lsp.get_active_clients({name = message.source})[1]
if not client then
return diag.message
end
local relatedInfo = {messages = {}, locations = {}}
for _, info in ipairs(diag.user_data.lsp.relatedInformation) do
table.insert(relatedInfo.messages, info.message)
table.insert(relatedInfo.locations, info.location)
end
for i, loc in ipairs(vim.lsp.util.locations_to_items(relatedInfo.locations, client.offset_encoding)) do
message = string.format("%s\n%s (%s:%d):\n\t%s", message, relatedInfo.messages[i],
vim.fn.fnamemodify(loc.filename, ':.'), loc.lnum,
getlines(relatedInfo.locations[i]))
end
return message
end}}) |
@tom-anders Got an error:
|
The following redefinition of the local original = vim.lsp.handlers['textDocument/publishDiagnostics']
vim.lsp.handlers['textDocument/publishDiagnostics'] = function(_, result, ctx, config)
vim.tbl_map(function(item)
if item.relatedInformation and #item.relatedInformation > 0 then
vim.tbl_map(function(k)
if k.location then
local tail = vim.fn.fnamemodify(vim.uri_to_fname(k.location.uri), ':t')
k.message = tail ..
'(' .. (k.location.range.start.line + 1) .. ', ' .. (k.location.range.start.character + 1) ..
'): ' .. k.message
if k.location.uri == vim.uri_from_bufnr(0) then
table.insert(result.diagnostics, {
code = item.code,
message = k.message,
range = k.location.range,
severity = vim.lsp.protocol.DiagnosticSeverity.Hint,
source = item.source,
relatedInformation = {},
})
end
end
item.message = item.message .. '\n' .. k.message
end, item.relatedInformation)
end
end, result.diagnostics)
original(_, result, ctx, config)
end |
Neovim version (nvim -v)
NVIM v0.8.0-dev-758-g711ef4eac9
Language server name/version
clangd 14.0
Operating system/version
Arch Linux
Steps to reproduce using "nvim -u minimal_init.lua"
Many servers support relatedInformation; I'm personally struggling with clagnd.
Expected behavior
Clangd shows three diagnostics (error + 2x info), just like standalone compiler:
VSCode handles this correctly:
Actual behavior
Clangd reports one diagnostic with two items in the
relatedInformation
list:https://gist.github.com/BigRedEye/253629638e1d71f4df667a3e8e05a1d3.
Neovim does not parse relatedInformation and displays just one main diagnostic:
Log file
No response
The text was updated successfully, but these errors were encountered: