Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/cmp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ window.documentation.max_height~

*cmp-config.experimental.ghost_text*
experimental.ghost_text~
`boolean | { hl_group = string }`
`boolean | { hl_group = string, hl_group_selected = string | nil}`
Whether to enable the ghost_text feature.

==============================================================================
Expand Down
1 change: 1 addition & 0 deletions lua/cmp/types/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ cmp.ItemField = {

---@class cmp.GhostTextConfig
---@field hl_group string
---@field hl_group_selected string|nil

---@class cmp.SourceConfig
---@field public name string
Expand Down
8 changes: 6 additions & 2 deletions lua/cmp/view/ghost_text_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ ghost_text_view.new = function()

local text = self.text_gen(self, line, col)
if #text > 0 then
local text_hl = 'Comment'
if type(c) == 'table' then
text_hl = require('cmp').core.view:get_selected_entry() and (c.hl_group_selected or c.hl_group) or c.hl_group
end
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' } })
table.insert(virt_lines, { { l, text_hl} })
end
local first_line = table.remove(virt_lines, 1)
self.extmark_buf = vim.api.nvim_get_current_buf()
Expand All @@ -87,7 +91,7 @@ end
--- of character differences instead of just byte difference.
ghost_text_view.text_gen = function(self, line, cursor_col)
local word = self.entry:get_insert_text()
if self.entry:get_completion_item().insertTextFormat == types.lsp.InsertTextFormat.Snippet then
if self.entry.completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet then
word = tostring(snippet.parse(word))
end
local word_clen = vim.fn.strchars(word, true)
Expand Down