Skip to content

Commit 1c2720b

Browse files
committed
bugfix
1 parent 8594939 commit 1c2720b

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

lua/easycomplete/ghost_text.lua

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
local M = {}
2+
local hint_ns = vim.api.nvim_create_namespace('hint_ns')
3+
4+
function M.init()
5+
M.init_hl()
6+
vim.api.nvim_create_autocmd({"ColorScheme"}, {
7+
pattern = {"*"},
8+
callback = function()
9+
M.init_hl()
10+
end
11+
})
12+
end
13+
14+
function M.init_hl()
15+
local cursorline_bg = vim.fn["easycomplete#ui#GetBgColor"]("CursorLine")
16+
local normal_bg = vim.fn["easycomplete#ui#GetBgColor"]("Normal")
17+
local linenr_fg = vim.fn["easycomplete#ui#GetFgColor"]("LineNr")
18+
if vim.fn.matchstr(cursorline_bg, "^\\d\\+") ~= "" then
19+
cursorline_bg = vim.fn.str2nr(cursorline_bg)
20+
end
21+
if vim.fn.matchstr(normal_bg, "^\\d\\+") ~= "" then
22+
normal_bg = vim.fn.str2nr(normal_bg)
23+
end
24+
if vim.fn.matchstr(linenr_fg, "^\\d\\+") ~= "" then
25+
linenr_fg = vim.fn.str2nr(linenr_fg)
26+
end
27+
28+
vim.api.nvim_set_hl(0, "HintFirstLine", {
29+
bg = cursorline_bg,
30+
fg = linenr_fg
31+
})
32+
vim.api.nvim_set_hl(0, "HintNoneFirstLine", {
33+
fg = linenr_fg,
34+
bg = normal_bg
35+
})
36+
end
37+
38+
-- code_block 是一个字符串,有可能包含回车符
39+
-- call v:lua.require("copilot").show_hint()
40+
-- code_block 是数组类型
41+
function M.show_hint(code_block)
42+
local lines = {}
43+
local count = 1
44+
local code_lines = code_block
45+
for key, line in pairs(code_lines) do
46+
local highlight_group = ""
47+
if count == 1 then
48+
highlight_group = "HintFirstLine"
49+
else
50+
highlight_group = "HintNoneFirstLine"
51+
end
52+
count = count + 1
53+
table.insert(lines, {{line, highlight_group}})
54+
end
55+
56+
local virt_text = lines[1]
57+
local virt_lines
58+
59+
if #lines >= 2 then
60+
table.remove(lines, 1)
61+
virt_lines = lines
62+
else
63+
virt_lines = nil
64+
end
65+
66+
vim.api.nvim_buf_set_extmark(0, hint_ns, vim.fn.line('.') - 1, vim.fn.col('.') - 1, {
67+
id = 1,
68+
virt_text_pos = "overlay",
69+
virt_text = virt_text,
70+
virt_lines = virt_lines
71+
})
72+
end
73+
74+
function M.delete_hint()
75+
vim.api.nvim_buf_del_extmark(0, hint_ns, 1)
76+
end
77+
78+
return M

plugin/easycomplete.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ endif
117117
if !exists("g:easycomplete_tabnine_enable")
118118
let g:easycomplete_tabnine_enable = 1
119119
endif
120+
if !exists("g:easycomplete_ghost_text")
121+
let g:easycomplete_ghost_text = 1
122+
endif
120123
if !exists("g:easycomplete_winborder")
121124
let g:easycomplete_winborder = 0
122125
endif
@@ -192,6 +195,7 @@ let g:easycomplete_config = {
192195
\ 'g:easycomplete_menuflag_tabnine': g:easycomplete_menuflag_tabnine,
193196
\ 'g:easycomplete_lsp_type_font': g:easycomplete_lsp_type_font,
194197
\ 'g:easycomplete_tabnine_config': g:easycomplete_tabnine_config,
198+
\ 'g:easycomplete_ghost_text': g:easycomplete_ghost_text,
195199
\ 'g:easycomplete_cursor_word_hl': g:easycomplete_cursor_word_hl,
196200
\ 'g:easycomplete_signature_offset': g:easycomplete_signature_offset,
197201
\ 'g:easycomplete_directory_enable': g:easycomplete_directory_enable,

0 commit comments

Comments
 (0)