Skip to content

Commit

Permalink
enable mini.snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
xzbdmw committed Dec 31, 2024
1 parent 6755b51 commit 20d5e70
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lua/cmp/view/ghost_text_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,24 @@ ghost_text_view.text_gen = function(self, line, cursor_col, entry)
return text
end

local word = entry:get_insert_text()
local c = config.get().experimental.ghost_text

-- Expand lsp snippet and make sure indent is correct
if entry:get_completion_item().insertTextFormat == types.lsp.InsertTextFormat.Snippet then
local completion_item = entry:get_completion_item()
-- Check if completion_kind indicates a snippet
-- Handle custom snippet
local word
if completion_item ~= nil and completion_item.kind == 15 and completion_item.documentation and completion_item.documentation.value then
local doc_value = completion_item.documentation.value
local pattern = '```(.-)\n(.-)\n```'
_, word = doc_value:match(pattern)
word = word or entry:get_insert_text()
else
-- Handle built-in snippet and non-snippet completion
word = entry:get_insert_text()
end

-- Expand snippet and make sure indent is correct
if completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet and word ~= nil then
local sp = snippet.parse(word)
local static_text = sp:to_static_text()
static_text[1] = trim_text(static_text[1])
Expand Down

0 comments on commit 20d5e70

Please sign in to comment.