Replies: 1 comment 4 replies
-
Luasnip picker---@class snacks.Picker
---@field [string] unknown
opts = {
picker = {
sources = {
snippets = {
supports_live = false,
preview = 'preview',
format = function(item, picker)
local name = Snacks.picker.util.align(item.name, picker.align_1 + 5)
return {
{ name, item.ft == '' and 'Conceal' or 'DiagnosticWarn' },
{ item.description },
}
end,
finder = function(_, ctx)
local snippets = {}
for _, snip in ipairs(require('luasnip').get_snippets().all) do
snip.ft = ''
table.insert(snippets, snip)
end
for _, snip in ipairs(require('luasnip').get_snippets(vim.bo.ft)) do
snip.ft = vim.bo.ft
table.insert(snippets, snip)
end
local align_1 = 0
for _, snip in pairs(snippets) do
align_1 = math.max(align_1, #snip.name)
end
ctx.picker.align_1 = align_1
local items = {}
for _, snip in pairs(snippets) do
local docstring = snip:get_docstring()
if type(docstring) == 'table' then
docstring = table.concat(docstring)
end
local name = snip.name
local description = table.concat(snip.description)
description = name == description and '' or description
table.insert(items, {
text = name .. ' ' .. description, -- search string
name = name,
description = description,
trigger = snip.trigger,
ft = snip.ft,
preview = {
ft = snip.ft,
text = docstring,
},
})
end
return items
end,
confirm = function(picker, item)
picker:close()
--
local expand = {}
require('luasnip').available(function(snippet)
if snippet.trigger == item.trigger then
table.insert(expand, snippet)
end
return snippet
end)
if #expand > 0 then
vim.cmd ':startinsert!'
vim.defer_fn(function()
require('luasnip').snip_expand(expand[1])
end, 50)
else
Snacks.notify.warn 'No snippet to expand'
end
end,
},
},
},
}, |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Would like to see a picker for snippets. The problem I have is that the prefix is an abbreviation of some type and it is not always obvious how to trigger snippets based on the prefix only. Thus, it would be useful to fuzzy find the snippets based on the description text which typically describes the snippet in a more human readable format (and possibly also the snippet body itself).
I don't know how to get all VSCode snippets defined for a certain buffer using blink.cmp. Can anyone please share insights on how to accomplish this. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions