Skip to content

Commit

Permalink
feat: make sorting keys configurable (#190)
Browse files Browse the repository at this point in the history
For example, to sort entries by line number, use:

    require("trouble").setup({
      sort_keys = {
        "filename",
        "lnum",
        "col",
        "severity",
      }
    })

The defaults remain the same.

Fixes: #65
  • Loading branch information
Hugo committed Sep 4, 2022
1 parent 1923ec9 commit 68d3dc5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 6 additions & 0 deletions lua/trouble/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ local defaults = {
other = "",
},
use_diagnostic_signs = false, -- enabling this will use the signs defined in your lsp client
sort_keys = {
"severity",
"filename",
"lnum",
"col",
},
}

---@type TroubleOptions
Expand Down
8 changes: 2 additions & 6 deletions lua/trouble/providers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function M.get(win, buf, cb, options)
return {}
end

local sort_keys = {
local sort_keys = vim.list_extend({
function(item)
local cwd = vim.loop.fs_realpath(vim.fn.getcwd())
local path = vim.loop.fs_realpath(item.filename)
Expand All @@ -50,11 +50,7 @@ function M.get(win, buf, cb, options)
end
return ret
end,
"severity",
"filename",
"lnum",
"col",
}
}, options.sort_keys)

provider(win, buf, function(items)
table.sort(items, function(a, b)
Expand Down

0 comments on commit 68d3dc5

Please sign in to comment.