Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: respect vim.diagnostic.config.severity_sort #1511

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions lua/lspsaga/diagnostic/show.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ local function new_node()
}
end

---single linked list
local function generate_list(entrys)
local function create_linked_list(entrys)
local list = new_node()

local curnode
for _, item in ipairs(entrys) do
if #list.diags == 0 then
Expand All @@ -53,6 +51,37 @@ local function generate_list(entrys)
return list
end

local function sort_entries(entrys)
table.sort(entrys, function(a, b)
if a.severity ~= b.severity then
return a.severity < b.severity
elseif a.lnum ~= b.lnum then
return a.lnum < b.lnum
else
return a.col < b.col
end
end)
end

---single linked list
local function generate_list(entrys, callback)
local diagnostic_config = vim.diagnostic.config and vim.diagnostic.config()
local severity_sort_enabled = diagnostic_config and diagnostic_config.severity_sort

if severity_sort_enabled then
vim.defer_fn(function()
sort_entries(entrys)
local list = create_linked_list(entrys)
if callback then
callback(list)
end
end, 0)
return nil
else
return create_linked_list(entrys)
end
end

local function find_node(list, lnum)
local curnode = list
while curnode do
Expand Down Expand Up @@ -345,8 +374,11 @@ function sd:show_diagnostics(opt)
if next(entrys) == nil then
return
end
opt.entrys_list = generate_list(entrys)
self:show(opt)

generate_list(entrys, function(sorted_list)
opt.entrys_list = sorted_list
self:show(opt)
end)
end

return setmetatable(ctx, sd)