Skip to content

Commit

Permalink
enable ghost_text for multi-line completions (#1886)
Browse files Browse the repository at this point in the history
  • Loading branch information
LoganWalls authored Jun 8, 2024
1 parent 5260e5e commit a110e12
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lua/cmp/view/ghost_text_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ ghost_text_view.new = function()

local text = self.text_gen(self, line, col)
if #text > 0 then
local virt_lines = {}
for _, l in ipairs(vim.fn.split(text, '\n')) do
table.insert(virt_lines, { { l, type(c) == 'table' and c.hl_group or 'Comment' } })
end
local first_line = table.remove(virt_lines, 1)
self.extmark_buf = vim.api.nvim_get_current_buf()
self.extmark_id = vim.api.nvim_buf_set_extmark(self.extmark_buf, ghost_text_view.ns, row - 1, col, {
right_gravity = true,
virt_text = { { text, type(c) == 'table' and c.hl_group or 'Comment' } },
virt_text = first_line,
virt_text_pos = has_inline and 'inline' or 'overlay',
virt_lines = virt_lines,
hl_mode = 'combine',
ephemeral = false,
})
Expand All @@ -82,7 +88,6 @@ ghost_text_view.text_gen = function(self, line, cursor_col)
if self.entry:get_completion_item().insertTextFormat == types.lsp.InsertTextFormat.Snippet then
word = tostring(snippet.parse(word))
end
word = str.oneline(word)
local word_clen = vim.str_utfindex(word)
local cword = string.sub(line, self.entry:get_offset(), cursor_col)
local cword_clen = vim.str_utfindex(cword)
Expand Down

0 comments on commit a110e12

Please sign in to comment.