Skip to content

Commit f4e53f2

Browse files
committed
feat: expose reload function
Closes #428
1 parent 2cbb02d commit f4e53f2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lua/blink/cmp/init.lua

+4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ function cmp.snippet_backward()
133133
return true
134134
end
135135

136+
--- Tells the sources to reload a specific provider or all providers (when nil)
137+
--- @param provider? string
138+
function cmp.reload(provider) require('blink.cmp.sources.lib').reload(provider) end
139+
136140
--- @param override? lsp.ClientCapabilities
137141
--- @param include_nvim_defaults? boolean
138142
function cmp.get_lsp_capabilities(override, include_nvim_defaults)

lua/blink/cmp/sources/lib/init.lua

+14-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ local config = require('blink.cmp.config')
2323
--- @field get_signature_help fun(context: blink.cmp.SignatureHelpContext, callback: fun(signature_help: lsp.SignatureHelp | nil))
2424
--- @field cancel_signature_help fun()
2525
---
26-
--- @field reload fun()
26+
--- @field reload fun(source?: string)
2727
--- @field get_lsp_capabilities fun(override?: lsp.ClientCapabilities, include_nvim_defaults?: boolean): lsp.ClientCapabilities
2828

2929
--- @class blink.cmp.SourceCompletionsEvent
@@ -220,7 +220,19 @@ end
220220
--- Misc ---
221221

222222
--- For external integrations to force reloading the source
223-
function sources.reload()
223+
function sources.reload(provider)
224+
-- Reload specific provider
225+
if provider ~= nil then
226+
assert(type(provider) == 'string', 'Expected string for provider')
227+
assert(
228+
sources.providers[provider] ~= nil or config.sources.providers[provider] ~= nil,
229+
'Source ' .. provider .. ' does not exist'
230+
)
231+
if sources.providers[provider] ~= nil then sources.providers[provider]:reload() end
232+
return
233+
end
234+
235+
-- Reload all providers
224236
for _, source in pairs(sources.providers) do
225237
source:reload()
226238
end

0 commit comments

Comments
 (0)