Skip to content

Commit

Permalink
feat: support should_show_items from sources
Browse files Browse the repository at this point in the history
Closes #972
  • Loading branch information
Saghen committed Jan 13, 2025
1 parent bee8725 commit fc9276d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lua/blink/cmp/sources/lib/provider/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ function source:should_show_items(context, items)
local current_keyword_length = context.bounds.length
if current_keyword_length < min_keyword_length then return false end

-- check if the source wants to show items
if self.module.should_show_items ~= nil and not self.module:should_show_items(context, items) then return false end

-- check if the user wants to show items
if self.config.should_show_items == nil then return true end
return self.config.should_show_items(context, items)
end
Expand Down
4 changes: 2 additions & 2 deletions lua/blink/cmp/sources/lib/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
--- @field enabled? fun(self: blink.cmp.Source): boolean
--- @field get_trigger_characters? fun(self: blink.cmp.Source): string[]
--- @field get_completions? fun(self: blink.cmp.Source, context: blink.cmp.Context, callback: fun(response?: blink.cmp.CompletionResponse)): (fun(): nil) | nil
--- @field should_show_completions? fun(self: blink.cmp.Source, context: blink.cmp.Context, response: blink.cmp.CompletionResponse): boolean
--- @field should_show_items? fun(self: blink.cmp.Source, context: blink.cmp.Context, items: blink.cmp.CompletionItem[]): boolean
--- @field resolve? fun(self: blink.cmp.Source, item: blink.cmp.CompletionItem, callback: fun(resolved_item?: lsp.CompletionItem)): ((fun(): nil) | nil)
--- @field execute? fun(self: blink.cmp.Source, context: blink.cmp.Context, item: blink.cmp.CompletionItem, callback: fun()): (fun(): nil) | nil
--- @field get_signature_help_trigger_characters? fun(self: blink.cmp.Source): string[]
Expand All @@ -23,7 +23,7 @@
--- @field enabled? fun(self: blink.cmp.Source): boolean
--- @field get_trigger_characters? fun(self: blink.cmp.Source): string[]
--- @field get_completions? fun(self: blink.cmp.Source, context: blink.cmp.Context, callback: fun(response: blink.cmp.CompletionResponse | nil)): (fun(): nil) | nil
--- @field should_show_completions? fun(self: blink.cmp.Source, context: blink.cmp.Context, response: blink.cmp.CompletionResponse): boolean
--- @field should_show_items? fun(self: blink.cmp.Source, context: blink.cmp.Context, items: blink.cmp.CompletionItem[]): boolean
--- @field resolve? fun(self: blink.cmp.Source, item: blink.cmp.CompletionItem, callback: fun(resolved_item: lsp.CompletionItem | nil)): ((fun(): nil) | nil)
--- @field execute? fun(self: blink.cmp.Source, context: blink.cmp.Context, item: blink.cmp.CompletionItem, callback: fun()): (fun(): nil) | nil
--- @field get_signature_help_trigger_characters? fun(self: blink.cmp.Source): string[]
Expand Down

0 comments on commit fc9276d

Please sign in to comment.