Skip to content

Commit

Permalink
feat: expose reload function
Browse files Browse the repository at this point in the history
Closes #428
  • Loading branch information
Saghen committed Dec 3, 2024
1 parent 2cbb02d commit f4e53f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lua/blink/cmp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ function cmp.snippet_backward()
return true
end

--- Tells the sources to reload a specific provider or all providers (when nil)
--- @param provider? string
function cmp.reload(provider) require('blink.cmp.sources.lib').reload(provider) end

--- @param override? lsp.ClientCapabilities
--- @param include_nvim_defaults? boolean
function cmp.get_lsp_capabilities(override, include_nvim_defaults)
Expand Down
16 changes: 14 additions & 2 deletions lua/blink/cmp/sources/lib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local config = require('blink.cmp.config')
--- @field get_signature_help fun(context: blink.cmp.SignatureHelpContext, callback: fun(signature_help: lsp.SignatureHelp | nil))
--- @field cancel_signature_help fun()
---
--- @field reload fun()
--- @field reload fun(source?: string)
--- @field get_lsp_capabilities fun(override?: lsp.ClientCapabilities, include_nvim_defaults?: boolean): lsp.ClientCapabilities

--- @class blink.cmp.SourceCompletionsEvent
Expand Down Expand Up @@ -220,7 +220,19 @@ end
--- Misc ---

--- For external integrations to force reloading the source
function sources.reload()
function sources.reload(provider)
-- Reload specific provider
if provider ~= nil then
assert(type(provider) == 'string', 'Expected string for provider')
assert(
sources.providers[provider] ~= nil or config.sources.providers[provider] ~= nil,
'Source ' .. provider .. ' does not exist'
)
if sources.providers[provider] ~= nil then sources.providers[provider]:reload() end
return
end

-- Reload all providers
for _, source in pairs(sources.providers) do
source:reload()
end
Expand Down

0 comments on commit f4e53f2

Please sign in to comment.