Skip to content

Commit

Permalink
feat(core): allow custom filter per source
Browse files Browse the repository at this point in the history
fixes #13
  • Loading branch information
max397574 committed Aug 1, 2024
1 parent d0bcd5b commit 47a4016
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lua/care/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ end
function core:complete(reason)
reason = reason or 2
local sources = require("care.sources").get_sources()
---@type care.entry[]
local entries = {}
local remaining = #sources
self.context.reason = reason
Expand All @@ -35,6 +36,9 @@ function core:complete(reason)
local filtered_items = vim.iter(items):filter(function(entry)
return not entry.score or entry.score > 0
end)
if source.config.filter then
filtered_items:filter(source.config.filter)
end
if source.config.max_entries then
filtered_items:take(source.config.max_entries)
end
Expand Down
2 changes: 2 additions & 0 deletions lua/care/types/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
---@field max_entries integer?
--- The priority of this source. Is more important than matching score
---@field priority integer?
--- Filter function for entries by the source
---@field filter fun(entry: care.entry): boolean

--- Configuration of the completion menu of care.nvim
---@class care.config.ui.docs
Expand Down

0 comments on commit 47a4016

Please sign in to comment.