Skip to content

Commit

Permalink
feat(lsp): add relatedInformation to diagnostics message
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-anders committed May 4, 2024
1 parent e948d7f commit 7d44a02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ The following new APIs and features were added.
respective capability can be unset.
|vim.lsp.start()| accepts a "silent" option for suppressing messages
if an LSP server failed to start.
• Add support for `relatedInformation` field in LSP diagnostics.

• Treesitter
• Bundled parsers and queries (highlight, folds) for Markdown, Python, and
Expand Down
8 changes: 8 additions & 0 deletions runtime/lua/vim/lsp/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ local function diagnostic_lsp_to_vim(diagnostics, bufnr, client_id)
return vim.tbl_map(function(diagnostic)
local start = diagnostic.range.start
local _end = diagnostic.range['end']
for _, relatedInfo in pairs(diagnostic.relatedInformation or {}) do
if relatedInfo.location then
local filename = vim.fn.fnamemodify(vim.uri_to_fname(relatedInfo.location.uri), ':t')
diagnostic.message = string.format("%s\n%s(%d, %d): %s", diagnostic.message, filename,
relatedInfo.location.range.start.line + 1, relatedInfo.location.range.start.character + 1,
relatedInfo.message)
end
end
--- @type vim.Diagnostic
return {
lnum = start.line,
Expand Down

0 comments on commit 7d44a02

Please sign in to comment.