Skip to content

Commit 5f8e04f

Browse files
committed
feat(ghost_text): Added multi-line ghost_text support for custom snippets of luasnip
1 parent d818fd0 commit 5f8e04f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lua/cmp/view/ghost_text_view.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,19 @@ end
8484
--- This function calculates the bytes of the entry to display calculating the number
8585
--- of character differences instead of just byte difference.
8686
ghost_text_view.text_gen = function(self, line, cursor_col)
87-
local word = self.entry:get_insert_text()
87+
local word
88+
local completion_kind = self.entry:get_kind()
89+
local completion_item = self.entry:get_completion_item()
90+
-- Check if completion_kind indicates a snippet
91+
-- Handle custom snippet
92+
if completion_kind == 15 and completion_item and completion_item.documentation and completion_item.documentation.value then
93+
local doc_value = completion_item.documentation.value
94+
local pattern = '```(.-)\n(.-)\n```'
95+
_, word = doc_value:match(pattern)
96+
else
97+
-- Handle built-in snippet and non-snippet completion
98+
word = self.entry:get_insert_text()
99+
end
88100
if self.entry:get_completion_item().insertTextFormat == types.lsp.InsertTextFormat.Snippet then
89101
word = tostring(snippet.parse(word))
90102
end

0 commit comments

Comments
 (0)