Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose snippet reload function, enables integration with plugins like nvim-scissors #28

Closed
chrisgrieser opened this issue Oct 8, 2024 · 6 comments

Comments

@chrisgrieser
Copy link
Contributor

I am the maintainer of nvim-scissors, and would like to implement a hot-reload-support for blink.cmp. To be able to do that, blink.cmp needs to expose some sort of function that reloads a snippet file inside providers → 'blink.cmp.sources.path' → opts.searchpaths..

snippet engines usually expose such functionality, so other plugins can properly integrate with them, e.g. require("luasnip.loaders").reload_file(path) for luasnip: /~https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#loaders

It would be great for blink.cmp to also expose such a function.

@jose-elias-alvarez
Copy link
Contributor

It looks like the way snippets are loaded makes it pretty tricky to do this cleanly, but it's currently possible to bust the cache in a highly undocumented way:

local reset_snippets_cache = function()
    local snippets_provider = vim.iter(require("blink.cmp").sources.providers):find(function(provider)
        return provider.name == "Snippets"
    end)
    if not snippets_provider then
        return
    end
    -- could theoretically scope this to a filetype, but not much point
    snippets_provider.module.cache = {}
end

I could imagine exposing a reset() method, but I'm not sure if it would see much use beyond this specific case. Happy to put in a PR if there's agreement on an approach.

@Saghen Saghen closed this as completed in ff1f5fa Oct 15, 2024
@Saghen
Copy link
Owner

Saghen commented Oct 16, 2024

require('blink.cmp').sources.reload() should do the trick. This API may change in the future but I'll send a message your way if it does

@chrisgrieser
Copy link
Contributor Author

Thank you!

chrisgrieser added a commit to chrisgrieser/nvim-scissors that referenced this issue Oct 16, 2024
@chrisgrieser
Copy link
Contributor Author

chrisgrieser commented Oct 28, 2024

Unfortunately, it appears the reload function is not working. require('blink.cmp').sources.reload() does not reload the snippets if there are changes. There is also no error of any kind, it just silently does nothing. (using v0.4.1)

@Saghen
Copy link
Owner

Saghen commented Oct 28, 2024

Sorry about that, it got broken during the sources rework. Fixed in 407f2d5

@chrisgrieser
Copy link
Contributor Author

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants