Skip to content

Commit

Permalink
feat: expose reload function for sources
Browse files Browse the repository at this point in the history
closes #28
  • Loading branch information
Saghen committed Oct 15, 2024
1 parent 90d6394 commit ff1f5fa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lua/blink/cmp/sources/lib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,13 @@ function sources.cancel_signature_help()
end
end

--- Misc ---

--- For external integrations to force reloading the source
function sources.reload()
for _, source in ipairs(sources.providers) do
source:reload()
end
end

return sources
8 changes: 8 additions & 0 deletions lua/blink/cmp/sources/lib/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,12 @@ function source:get_signature_help(context)
end)
end

--- Misc ---

--- For external integrations to force reloading the source
function source:reload()
if self.module.reload == nil then return end
self.module:reload()
end

return source
4 changes: 4 additions & 0 deletions lua/blink/cmp/sources/lib/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
--- @field filter_completions (fun(self: blink.cmp.Source, response: blink.cmp.CompletionResponse): blink.cmp.CompletionItem[]) | nil
--- @field should_show_completions (fun(self: blink.cmp.Source, context: blink.cmp.Context, response: blink.cmp.CompletionResponse): boolean) | nil
--- @field resolve (fun(self: blink.cmp.Source, item: blink.cmp.CompletionItem, callback: fun(resolved_item: lsp.CompletionItem | nil)): ((fun(): nil) | nil)) | nil
--- @field get_signature_help_trigger_characters fun(self: blink.cmp.Source): string[]
--- @field get_signature_help fun(self: blink.cmp.Source, context: blink.cmp.SignatureHelpContext): blink.cmp.Task
--- @field reload (fun(self: blink.cmp.Source): nil) | nil
---
--- @class blink.cmp.SourceProvider
--- @field name string
Expand All @@ -27,3 +30,4 @@
--- @field resolve fun(self: blink.cmp.SourceProvider, item: blink.cmp.CompletionItem): blink.cmp.Task
--- @field get_signature_help_trigger_characters fun(self: blink.cmp.SourceProvider): string[]
--- @field get_signature_help fun(self: blink.cmp.SourceProvider, context: blink.cmp.SignatureHelpContext): blink.cmp.Task
--- @field reload (fun(self: blink.cmp.Source): nil) | nil
6 changes: 4 additions & 2 deletions lua/blink/cmp/sources/snippets/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ function snippets.new(config)
--- @type table<string, blink.cmp.CompletionItem[]>
self.cache = {}
--- @type blink.cmp.SnippetsOpts
local opts = config.opts or {}
self.registry = require('blink.cmp.sources.snippets.registry').new(opts)
self.registry = require('blink.cmp.sources.snippets.registry').new(config.opts or {})
return self
end

Expand Down Expand Up @@ -59,4 +58,7 @@ function snippets:resolve(item, callback)
callback(resolved_item)
end

--- For external integrations to force reloading the snippets
function snippets:reload() self.cache = {} end

return snippets

0 comments on commit ff1f5fa

Please sign in to comment.