mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-26 02:38:50 +02:00
feat(cmp): add missing documentation to snippets when needed
This commit is contained in:
parent
39f3ebcadf
commit
24a2a9fb0b
2 changed files with 23 additions and 0 deletions
|
@ -89,6 +89,9 @@ return {
|
|||
LazyVim.cmp.auto_brackets(event.entry)
|
||||
end
|
||||
end)
|
||||
cmp.event:on("menu_opened", function(event)
|
||||
LazyVim.cmp.add_missing_snippet_docs(event.window)
|
||||
end)
|
||||
end,
|
||||
},
|
||||
|
||||
|
|
|
@ -16,4 +16,24 @@ function M.auto_brackets(entry)
|
|||
end
|
||||
end
|
||||
|
||||
-- This function adds missing documentation to snippets.
|
||||
-- The documentation is a preview of the snippet.
|
||||
---@param window cmp.CustomEntriesView|cmp.NativeEntriesView
|
||||
function M.add_missing_snippet_docs(window)
|
||||
local cmp = require("cmp")
|
||||
local Kind = cmp.lsp.CompletionItemKind
|
||||
local entries = window:get_entries()
|
||||
for _, entry in ipairs(entries) do
|
||||
if entry:get_kind() == Kind.Snippet then
|
||||
local item = entry:get_completion_item()
|
||||
if not item.documentation and item.insertText then
|
||||
item.documentation = {
|
||||
kind = cmp.lsp.MarkupKind.Markdown,
|
||||
value = string.format("```%s\n%s\n```", vim.bo.filetype, item.insertText),
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue