diff --git a/lua/blink/cmp/init.lua b/lua/blink/cmp/init.lua index 7dae5b38..6818fb4a 100644 --- a/lua/blink/cmp/init.lua +++ b/lua/blink/cmp/init.lua @@ -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) diff --git a/lua/blink/cmp/sources/lib/init.lua b/lua/blink/cmp/sources/lib/init.lua index b69b971d..636c6785 100644 --- a/lua/blink/cmp/sources/lib/init.lua +++ b/lua/blink/cmp/sources/lib/init.lua @@ -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 @@ -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