diff options
Diffstat (limited to 'runtime/lua')
-rw-r--r-- | runtime/lua/vim/diagnostic.lua | 23 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/diagnostic.lua | 4 |
2 files changed, 19 insertions, 8 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index dae785647b..6547188594 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -440,13 +440,20 @@ end --- - `function`: Function with signature (namespace, bufnr) that returns any of the above. --- ---@param opts table Configuration table with the following keys: ---- - underline: (default true) Use underline for diagnostics ---- - virtual_text: (default true) Use virtual text for diagnostics ---- - signs: (default true) Use signs for diagnostics +--- - underline: (default true) Use underline for diagnostics. Options: +--- * severity: Only underline diagnostics matching the given severity +--- |diagnostic-severity| +--- - virtual_text: (default true) Use virtual text for diagnostics. Options: +--- * severity: Only show virtual text for diagnostics matching the given +--- severity |diagnostic-severity| +--- - signs: (default true) Use signs for diagnostics. Options: +--- * severity: Only show signs for diagnostics matching the given severity +--- |diagnostic-severity| --- - update_in_insert: (default false) Update diagnostics in Insert mode (if false, --- diagnostics are updated on InsertLeave) --- - severity_sort: (default false) Sort diagnostics by severity. This affects the order in ---- which signs and virtual text are displayed +--- which signs and virtual text are displayed. Options: +--- * reverse: (boolean) Reverse sort order ---@param namespace number|nil Update the options for the given namespace. When omitted, update the --- global diagnostic options. function M.config(opts, namespace) @@ -989,6 +996,14 @@ function M.show(namespace, bufnr, diagnostics, opts) end end + if vim.F.if_nil(opts.severity_sort, false) then + if type(opts.severity_sort) == "table" and opts.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 + if opts.underline then M._set_underline(namespace, bufnr, diagnostics, opts.underline) end diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 4d0b6f83bc..41c8bd36ec 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -195,10 +195,6 @@ function M.on_publish_diagnostics(_, result, ctx, config) local diagnostics = result.diagnostics if config then - if vim.F.if_nil(config.severity_sort, false) then - table.sort(diagnostics, function(a, b) return a.severity > b.severity end) - end - for _, opt in pairs(config) do if type(opt) == 'table' then if not opt.severity and opt.severity_limit then |