mirror of
https://github.com/neovim/neovim.git
synced 2025-11-09 20:15:24 +00:00
Add signs for Lsp diagnostics (#11668)
* Add signs for Lsp diagnostics * defer sign definition until init.vim is loaded
This commit is contained in:
@@ -953,6 +953,18 @@ buf_diagnostics_underline({bufnr}, {diagnostics})
|
|||||||
buf_diagnostics_virtual_text({bufnr}, {diagnostics})
|
buf_diagnostics_virtual_text({bufnr}, {diagnostics})
|
||||||
TODO: Documentation
|
TODO: Documentation
|
||||||
|
|
||||||
|
*vim.lsp.util.buf_diagnostics_signs()*
|
||||||
|
buf_diagnostics_signs({bufnr}, {diagnostics})
|
||||||
|
Place signs for each diagnostic in the sign column.
|
||||||
|
Sign characters can be customized with the following options:
|
||||||
|
>
|
||||||
|
let g:LspDiagnosticsErrorSign = 'E'
|
||||||
|
let g:LspDiagnosticsWarningSign = 'W'
|
||||||
|
let g:LspDiagnosticsInformationSign = 'I'
|
||||||
|
let g:LspDiagnosticsHintSign = 'H'
|
||||||
|
<
|
||||||
|
|
||||||
|
|
||||||
character_offset({buf}, {row}, {col}) *vim.lsp.util.character_offset()*
|
character_offset({buf}, {row}, {col}) *vim.lsp.util.character_offset()*
|
||||||
TODO: Documentation
|
TODO: Documentation
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ M['textDocument/publishDiagnostics'] = function(_, _, result)
|
|||||||
util.buf_diagnostics_save_positions(bufnr, result.diagnostics)
|
util.buf_diagnostics_save_positions(bufnr, result.diagnostics)
|
||||||
util.buf_diagnostics_underline(bufnr, result.diagnostics)
|
util.buf_diagnostics_underline(bufnr, result.diagnostics)
|
||||||
util.buf_diagnostics_virtual_text(bufnr, result.diagnostics)
|
util.buf_diagnostics_virtual_text(bufnr, result.diagnostics)
|
||||||
|
util.buf_diagnostics_signs(bufnr, result.diagnostics)
|
||||||
-- util.set_loclist(result.diagnostics)
|
-- util.set_loclist(result.diagnostics)
|
||||||
vim.api.nvim_command("doautocmd User LspDiagnosticsChanged")
|
vim.api.nvim_command("doautocmd User LspDiagnosticsChanged")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -570,7 +570,7 @@ do
|
|||||||
|
|
||||||
local diagnostic_ns = api.nvim_create_namespace("vim_lsp_diagnostics")
|
local diagnostic_ns = api.nvim_create_namespace("vim_lsp_diagnostics")
|
||||||
local reference_ns = api.nvim_create_namespace("vim_lsp_references")
|
local reference_ns = api.nvim_create_namespace("vim_lsp_references")
|
||||||
|
local sign_ns = 'vim_lsp_signs'
|
||||||
local underline_highlight_name = "LspDiagnosticsUnderline"
|
local underline_highlight_name = "LspDiagnosticsUnderline"
|
||||||
vim.cmd(string.format("highlight default %s gui=underline cterm=underline", underline_highlight_name))
|
vim.cmd(string.format("highlight default %s gui=underline cterm=underline", underline_highlight_name))
|
||||||
for kind, _ in pairs(protocol.DiagnosticSeverity) do
|
for kind, _ in pairs(protocol.DiagnosticSeverity) do
|
||||||
@@ -603,6 +603,12 @@ do
|
|||||||
|
|
||||||
function M.buf_clear_diagnostics(bufnr)
|
function M.buf_clear_diagnostics(bufnr)
|
||||||
validate { bufnr = {bufnr, 'n', true} }
|
validate { bufnr = {bufnr, 'n', true} }
|
||||||
|
bufnr = bufnr == 0 and api.nvim_get_current_buf() or bufnr
|
||||||
|
|
||||||
|
-- clear sign group
|
||||||
|
vim.fn.sign_unplace(sign_ns, {buffer=bufnr})
|
||||||
|
|
||||||
|
-- clear virtual text namespace
|
||||||
api.nvim_buf_clear_namespace(bufnr, diagnostic_ns, 0, -1)
|
api.nvim_buf_clear_namespace(bufnr, diagnostic_ns, 0, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -755,6 +761,22 @@ do
|
|||||||
end
|
end
|
||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
function M.buf_diagnostics_signs(bufnr, diagnostics)
|
||||||
|
vim.fn.sign_define('LspDiagnosticsErrorSign', {text=vim.g['LspDiagnosticsErrorSign'] or 'E', texthl='LspDiagnosticsError', linehl='', numhl=''})
|
||||||
|
vim.fn.sign_define('LspDiagnosticsWarningSign', {text=vim.g['LspDiagnosticsWarningSign'] or 'W', texthl='LspDiagnosticsWarning', linehl='', numhl=''})
|
||||||
|
vim.fn.sign_define('LspDiagnosticsInformationSign', {text=vim.g['LspDiagnosticsInformationSign'] or 'I', texthl='LspDiagnosticsInformation', linehl='', numhl=''})
|
||||||
|
vim.fn.sign_define('LspDiagnosticsHintSign', {text=vim.g['LspDiagnosticsHintSign'] or 'H', texthl='LspDiagnosticsHint', linehl='', numhl=''})
|
||||||
|
|
||||||
|
for _, diagnostic in ipairs(diagnostics) do
|
||||||
|
local diagnostic_severity_map = {
|
||||||
|
[protocol.DiagnosticSeverity.Error] = "LspDiagnosticsErrorSign";
|
||||||
|
[protocol.DiagnosticSeverity.Warning] = "LspDiagnosticsWarningSign";
|
||||||
|
[protocol.DiagnosticSeverity.Information] = "LspDiagnosticsInformationSign";
|
||||||
|
[protocol.DiagnosticSeverity.Hint] = "LspDiagnosticsHintSign";
|
||||||
|
}
|
||||||
|
vim.fn.sign_place(0, sign_ns, diagnostic_severity_map[diagnostic.severity], bufnr, {lnum=(diagnostic.range.start.line+1)})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local position_sort = sort_by_key(function(v)
|
local position_sort = sort_by_key(function(v)
|
||||||
|
|||||||
Reference in New Issue
Block a user