diff options
author | Marco Hinz <mh.codebro@gmail.com> | 2021-04-23 20:09:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-23 20:09:56 +0200 |
commit | 4de404a681426f9d5a1253ca7bc97b075ca14bee (patch) | |
tree | 7edff9d6344fa595ed4fd9f0724fd41f90741ccf /runtime/lua/vim/lsp/diagnostic.lua | |
parent | bb33727922ca4549bb3b9b7aaaac1b535154b669 (diff) | |
download | rneovim-4de404a681426f9d5a1253ca7bc97b075ca14bee.tar.gz rneovim-4de404a681426f9d5a1253ca7bc97b075ca14bee.tar.bz2 rneovim-4de404a681426f9d5a1253ca7bc97b075ca14bee.zip |
lsp: sort diagnostics by severity (#14372)
Allow to sort diagnostics (and thus signs and virtual text) by severity, so that
the most important message is shown first.
vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
severity_sort = true,
}
)
Fixes https://github.com/neovim/neovim/issues/13929
Diffstat (limited to 'runtime/lua/vim/lsp/diagnostic.lua')
-rw-r--r-- | runtime/lua/vim/lsp/diagnostic.lua | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index e6132e78bf..dcd54fd587 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -406,9 +406,7 @@ function M.get_line_diagnostics(bufnr, line_nr, opts, client_id) line_diagnostics = filter_by_severity_limit(opts.severity_limit, line_diagnostics) end - if opts.severity_sort then - table.sort(line_diagnostics, function(a, b) return a.severity < b.severity end) - end + table.sort(line_diagnostics, function(a, b) return a.severity < b.severity end) return line_diagnostics end @@ -997,6 +995,8 @@ end --- - See |vim.lsp.diagnostic.set_signs()| --- - update_in_insert: (default=false) --- - Update diagnostics in InsertMode or wait until InsertLeave +--- - severity_sort: (default=false) +--- - Sort diagnostics (and thus signs and virtual text) function M.on_publish_diagnostics(_, _, params, client_id, _, config) local uri = params.uri local bufnr = vim.uri_to_bufnr(uri) @@ -1007,6 +1007,10 @@ function M.on_publish_diagnostics(_, _, params, client_id, _, config) local diagnostics = params.diagnostics + if if_nil(config.severity_sort, false) then + table.sort(diagnostics, function(a, b) return a.severity > b.severity end) + end + -- Always save the diagnostics, even if the buf is not loaded. -- Language servers may report compile or build errors via diagnostics -- Users should be able to find these, even if they're in files which @@ -1034,6 +1038,7 @@ function M.display(diagnostics, bufnr, client_id, config) underline = true, virtual_text = true, update_in_insert = false, + severity_sort = false, }, config) -- TODO(tjdevries): Consider how we can make this a "standardized" kind of thing for |lsp-handlers|. @@ -1116,7 +1121,6 @@ end ---@return table {popup_bufnr, win_id} function M.show_line_diagnostics(opts, bufnr, line_nr, client_id) opts = opts or {} - opts.severity_sort = if_nil(opts.severity_sort, true) local show_header = if_nil(opts.show_header, true) |