feat: add filter option to sources (#1067)
* feat: add `source.filter` config
This allows the user to specify a `filter` function for each source,
like this:
```lua
-- don't show entries with kind "Text" from the "nvim_lsp" source
sources = {
{
name = "nvim_lsp",
filter = function(entry, ctx)
local kind = types.lsp.CompletionItemKind[entry:get_kind()]
if kind == "Text" then
return true
end
},
}
```
By utilizing the `ctx` parameter, the user can also ignore certain
entries in certain contexts.
* fixup! feat: add `source.filter` config
* fixup! feat: add `source.filter` config
This commit is contained in:
25
doc/cmp.txt
25
doc/cmp.txt
@@ -560,6 +560,31 @@ sources[n].group_index~
|
||||
})
|
||||
}
|
||||
<
|
||||
|
||||
*cmp-config.sources[n].entry_filter*
|
||||
sources[n].entry_filter~
|
||||
`function`
|
||||
A source-specific entry filter, with the following function signature:
|
||||
>
|
||||
function(entry: cmp.Entry, ctx: cmp.Context): boolean
|
||||
<
|
||||
|
||||
Returning `true` will keep the entry, while returning `false` will remove it.
|
||||
|
||||
This can be used to hide certain entries from a given source. For instance, you
|
||||
could hide all entries with kind `Text` from the `nvim_lsp` filter using the
|
||||
following source definition:
|
||||
>
|
||||
{
|
||||
name = 'nvim_lsp',
|
||||
entry_filter = function(entry, ctx)
|
||||
return require('cmp.types').lsp.CompletionItemKind[entry:get_kind()] ~= 'Text'
|
||||
end
|
||||
}
|
||||
<
|
||||
Using the `ctx` parameter, you can further customize the behaviour of the
|
||||
source.
|
||||
|
||||
*cmp-config.view*
|
||||
view~
|
||||
`{ entries: cmp.EntriesConfig|string }`
|
||||
|
||||
Reference in New Issue
Block a user