refactor: add frontend.hover.load function to set buffer content

This commit is contained in:
JuanZoran
2023-03-13 21:41:17 +08:00
parent 7731c6c8cb
commit 693dd0c7aa
8 changed files with 201 additions and 345 deletions

View File

@ -1,23 +1,20 @@
local api = vim.api
local add_hl = api.nvim_buf_add_highlight
local item_meta = {
render = function(self, bufnr, line, col)
render = function(self, buffer, line, col)
if self[2] then
add_hl(bufnr, self.ns or -1, self[2], line, col, col + #self[1])
buffer:add_highlight(line, self[2], col, col + #self[1])
end
end,
}
local text_meta = {
render = function(self, bufnr, line, col)
render = function(self, buffer, line, col)
local items = self.items
local step = self.step or ''
local len = #step
for i = 1, self.size do
local item = items[i]
item:render(bufnr, line, col)
item:render(buffer, line, col)
col = col + #item[1] + len
end
end
@ -28,6 +25,7 @@ text_meta.__index = function(self, key)
return text_meta[key] or (key == 1 and table.concat(self.strs, self.step) or nil)
end
return {
item = function(text, highlight)
return setmetatable({