Created
November 6, 2020 16:16
-
-
Save tjdevries/ccbe3b79bd918208f2fa8dfe15b95793 to your computer and use it in GitHub Desktop.
Aligned Virt Text Example (not guaranteed to work forever)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim.lsp.diagnostic.get_virtual_text_chunks_for_line = function(bufnr, line, line_diagnostics) | |
if #line_diagnostics == 0 then | |
return nil | |
end | |
local line_length = #(vim.api.nvim_buf_get_lines(bufnr, line, line + 1, false)[1] or '') | |
local get_highlight = vim.lsp.diagnostic._get_severity_highlight_name | |
-- Create a little more space between virtual text and contents | |
local virt_texts = {{string.rep(" ", 80 - line_length)}} | |
for i = 1, #line_diagnostics - 1 do | |
table.insert(virt_texts, {"■", get_highlight(line_diagnostics[i].severity)}) | |
end | |
local last = line_diagnostics[#line_diagnostics] | |
-- TODO(ashkan) use first line instead of subbing 2 spaces? | |
-- TODO(tjdevries): Allow different servers to be shown first somehow? | |
-- TODO(tjdevries): Display server name associated with these? | |
if last.message then | |
table.insert( | |
virt_texts, | |
{ | |
string.format("■ %s", last.message:gsub("\r", ""):gsub("\n", " ")), | |
get_highlight(last.severity) | |
} | |
) | |
return virt_texts | |
end | |
return virt_texts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment