Replies: 4 comments 9 replies
|
I am also interested in this , any news on this? |
|
@DrKGD @LamprosPitsillos I got triggering snippets by a semicolon opts = {
sources = {
providers = {
snippy = {
name = 'snippy',
module = 'utils.snippy',
min_keyword_length = 1,
max_items = 8,
should_show_items = function(ctx) return ctx.trigger.initial_character == ';' end,
override = {
get_trigger_characters = function(_) return { ';' } end,
resolve = function(_, item) item.insertText = ';' .. item.insertText end,
},
},
buffer = {
min_keyword_length = 2,
max_items = 8,
should_show_items = function(ctx) return ctx.trigger.initial_character ~= ';' end,
},
},
},
} |
|
Good news everyone, I've found a somewhat reliable solution with luasnip (at least, it seems reliable with my limited testing) Basically it consists of monkeypatching the
{ 'snippets', true, {
-- This is not needed, kept it in just for the demo
-- name = "SNP",
score_offset = 100,
module = "blink.cmp.sources.snippets",
min_keyword_length = 0,
max_items = 10,
override = {
get_trigger_characters = function(_)
return { ';' }
end,
},
should_show_items = function(ctx)
return ctx.trigger.initial_character == ';'
end,
}},
-- Additional snippet engine
return {
'L3MON4D3/LuaSnip',
name = 'blink-cmp.dep.snip',
build = "make install_jsregexp",
dependencies = { 'blink-cmp.dep.friendly-snippets' },
version = "v2.*",
config = function()
-- From runtime
require('luasnip.loaders.from_vscode').lazy_load { }
-- From scissors
require("luasnip.loaders.from_vscode").lazy_load {
paths = { config.dirs.scissors },
}
-- HIJACK: Hijack expand function to work with blink_cmp
-- https://github.com/Saghen/blink.cmp/discussions/1104
local ls = require('luasnip')
local expand_orig = ls.snip_expand
ls.snip_expand = function(snip, opts)
if opts and opts.clear_region then
opts.clear_region.from[2] = opts.clear_region.from[2] - (';'):len() end
return expand_orig(snip, opts)
end
-- Assert that if luasnip were to be unloaded
-- it'd load our patched version instead
package.preload['luasnip'] = function() return ls end
end
}
Let me know if that works out for you as well! AhVj7iUhIzpLl6CC.mp4 |


Uh oh!
There was an error while loading. Please reload this page.
I'd like to display snippets only by prefixing them using ";", so far i've found someone who already dealt with that
He also provides a way to "delete" the special prefix character soon after accepting the snippet, but I feel like it is more of a hack and could easily break.
I tried experimenting on my own, but I don't think it is possibile to hijack the item itself to drop the prefix character, all I managed to do is prefixing the displayed label with the character itself
Note that I am not using luasnip as of now (as it is duplicating results) but the builtin snippet source, having friendly-snippets installed. Thanks!
All reactions