diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2021-10-07 19:19:30 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-07 19:19:30 -0600 |
commit | 7f93b2ab01c93720820712a3c81462a58d04dfa0 (patch) | |
tree | 49193cb5cc673d719a95cbb6d9ca935510b85ed9 /runtime/lua/vim/diagnostic.lua | |
parent | e16adbf238ee46b59b68a84af17bdee10ca49418 (diff) | |
download | rneovim-7f93b2ab01c93720820712a3c81462a58d04dfa0.tar.gz rneovim-7f93b2ab01c93720820712a3c81462a58d04dfa0.tar.bz2 rneovim-7f93b2ab01c93720820712a3c81462a58d04dfa0.zip |
fix: support severity_sort option for show_diagnostic functions (#15948)
Support the severity_sort option for show_{line,position}_diagnostics.
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
-rw-r--r-- | runtime/lua/vim/diagnostic.lua | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 7b74f4ec96..b58055f07e 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -125,9 +125,7 @@ local function get_namespace(ns) end end - if not name then - return vim.notify("namespace does not exist or is anonymous", vim.log.levels.ERROR) - end + assert(name, "namespace does not exist or is anonymous") all_namespaces[ns] = { name = name, @@ -398,6 +396,17 @@ local function show_diagnostics(opts, diagnostics) diagnostics = prefix_source(opts.source, diagnostics) end + -- Use global setting for severity_sort since 'show_diagnostics' is namespace + -- independent + local severity_sort = global_diagnostic_options.severity_sort + if severity_sort then + if type(severity_sort) == "table" and severity_sort.reverse then + table.sort(diagnostics, function(a, b) return a.severity > b.severity end) + else + table.sort(diagnostics, function(a, b) return a.severity < b.severity end) + end + end + for i, diagnostic in ipairs(diagnostics) do local prefix = string.format("%d. ", i) local hiname = floating_highlight_map[diagnostic.severity] @@ -1143,7 +1152,6 @@ function M.show_position_diagnostics(opts, bufnr, position) local diagnostics = M.get(bufnr, opts) clamp_line_numbers(bufnr, diagnostics) local position_diagnostics = vim.tbl_filter(match_position_predicate, diagnostics) - table.sort(position_diagnostics, function(a, b) return a.severity < b.severity end) return show_diagnostics(opts, position_diagnostics) end |