Skip to content

Commit

Permalink
feat: allow top-level filter
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 30, 2024
1 parent 9fb1be0 commit 12447df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lua/trouble/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
local M = {}

---@class trouble.Mode: trouble.Config
---@field filter? trouble.spec.filter
---@field sections? trouble.spec.section[]|trouble.spec.section

---@class trouble.Config
Expand Down Expand Up @@ -72,9 +73,7 @@ local defaults = {
modes = {
diagnostics_buffer = {
mode = "diagnostics",
sections = {
filter = { buf = 0 },
},
filter = { buf = 0 },
},
},
}
Expand Down Expand Up @@ -113,7 +112,10 @@ end

function M.modes()
require("trouble.source").load()
return vim.tbl_keys(options.modes)
---@type string[]
local ret = vim.tbl_keys(options.modes)
table.sort(ret)
return ret
end

---@param ...? trouble.Config|string
Expand Down
10 changes: 6 additions & 4 deletions lua/trouble/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,15 @@ function M:refresh()
for s, section in ipairs(self.sections) do
self.fetching = self.fetching + 1
Source.get(section.source, function(items)
self.items[s] = Filter.filter(items, section.filter, self)
self.items[s] = Sort.sort(self.items[s], section.sort, self)
for i, item in ipairs(self.items[s]) do
items = Filter.filter(items, self.opts.filter, self)
items = Filter.filter(items, section.filter, self)
items = Sort.sort(items, section.sort, self)
for i, item in ipairs(items) do
item.idx = i
end
self.items[s] = items
-- self.items[s] = vim.list_slice(self.items[s], 1, 10)
self.nodes[s] = Tree.build(self.items[s], section)
self.nodes[s] = Tree.build(items, section)
self.fetching = self.fetching - 1
self:update()
end, { filter = section.filter, view = self })
Expand Down

0 comments on commit 12447df

Please sign in to comment.