Lazy buffer creation

This commit is contained in:
hrsh7th
2021-10-10 13:57:37 +09:00
parent d901dae302
commit 0a31d67219
4 changed files with 39 additions and 34 deletions

View File

@@ -89,8 +89,6 @@ custom_entries_view.redraw = function()
end
custom_entries_view.open = function(self, offset, entries)
self.entries_win:ensure()
self.offset = offset
self.entries = {}
self.column_bytes = { abbr = 0, kind = 0, menu = 0 }
@@ -121,7 +119,7 @@ custom_entries_view.open = function(self, offset, entries)
i = i + 1
end
end
vim.api.nvim_buf_set_lines(self.entries_win.buf, 0, -1, false, lines)
vim.api.nvim_buf_set_lines(self.entries_win:get_buffer(), 0, -1, false, lines)
local width = 0
width = width + 1
@@ -202,7 +200,7 @@ custom_entries_view.draw = function(self)
table.insert(texts, table.concat(text, ''))
end
end
vim.api.nvim_buf_set_lines(self.entries_win.buf, topline, botline, false, texts)
vim.api.nvim_buf_set_lines(self.entries_win:get_buffer(), topline, botline, false, texts)
end
custom_entries_view.visible = function(self)

View File

@@ -22,8 +22,6 @@ end
---@param e cmp.Entry
---@param view cmp.WindowStyle
docs_view.open = function(self, e, view)
self.window:ensure()
local documentation = config.get().documentation
if not documentation then
return
@@ -45,16 +43,16 @@ docs_view.open = function(self, e, view)
end
self.entry = e
vim.api.nvim_buf_call(self.window.buf, function()
vim.api.nvim_buf_call(self.window:get_buffer(), function()
vim.cmd([[syntax clear]])
end)
vim.lsp.util.stylize_markdown(self.window.buf, documents, {
vim.lsp.util.stylize_markdown(self.window:get_buffer(), documents, {
max_width = maxwidth,
max_height = documentation.maxheight,
})
end
local width, height = vim.lsp.util._make_floating_popup_size(vim.api.nvim_buf_get_lines(self.window.buf, 0, -1, false), {
local width, height = vim.lsp.util._make_floating_popup_size(vim.api.nvim_buf_get_lines(self.window:get_buffer(), 0, -1, false), {
max_width = maxwidth,
max_height = documentation.maxheight,
})
@@ -113,7 +111,7 @@ docs_view.scroll = function(self, delta)
top = math.min(top, self.window:get_content_height() - info.height + 1)
vim.defer_fn(function()
vim.api.nvim_buf_call(self.window.buf, function()
vim.api.nvim_buf_call(self.window:get_buffer(), function()
vim.api.nvim_command('normal! ' .. top .. 'zt')
self.window:update()
end)