Skip to content

Instantly share code, notes, and snippets.

@jsr-p
Last active February 17, 2023 18:15
Show Gist options
  • Save jsr-p/93cfeda90588365feefaf4a8c78ff086 to your computer and use it in GitHub Desktop.
Save jsr-p/93cfeda90588365feefaf4a8c78ff086 to your computer and use it in GitHub Desktop.
lua function akin to https://github.com/onsails/lspkind.nvim/pull/30 but for Ultisnips
local cmp = require('cmp')
local lspkind = require('lspkind')
--- Function to preview snippet before completion with nvim-cmp
---@param entry cmp.Entry
---@param vim_item vim.CompletedItem
---@return vim.CompletedItem
function CmpBefore(entry, vim_item)
if entry.completion_item.snippet then
local snippet_value = entry.completion_item.snippet.value
local parsed_snippet = vim.lsp.util.parse_snippet(snippet_value)
local snippet_preview = str.oneline(str.oneline(parsed_snippet))
vim_item.abbr = snippet_preview
else
vim_item.abbr = entry:get_insert_text()
end
return vim_item
end
cmp.setup {
-- ...
formatting = {
-- ...
format = lspkind.cmp_format({
before = CmpBefore
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment