Repository navigation
How to show on cmp_doc and cmp_menu in a vertical way. #2213
Unanswered
ankushbhagats
asked this question in
Q&A
Replies: 1 comment
|
Hm... You need to overwrite documentation routine. local cmp = require('cmp')
local ok_w, window_util = pcall(require, 'cmp.utils.window')
local ok_cfg, config = pcall(require, 'cmp.config')
local ok_lsp = pcall(function() vim.lsp.util._make_floating_popup_size end)
if not ok_w or not ok_cfg or not ok_lsp then
return
end
local docs_view = cmp.core.view.docs_view
local orig_open = docs_view.open
docs_view.open = function(self, e, view, bottom_up)
local documentation = config.get().window.documentation
if not documentation then
return
end
if not e or not view then
return self:close()
end
local border_info = window_util.get_border_info({ style = documentation })
local top_space = view.row - 1
local bottom_space = vim.o.lines - (view.row + view.height - 1)
local max_width = view.width
if documentation.max_width and documentation.max_width > 0 then
max_width = math.min(documentation.max_width, max_width)
end
if not self.entry or e.id ~= self.entry.id then
local documents = e:get_documentation()
if #documents == 0 then
return self:close()
end
self.entry = e
vim.api.nvim_buf_call(self.window:get_buffer(), function()
vim.cmd([[syntax clear]])
vim.api.nvim_buf_set_lines(self.window:get_buffer(), 0, -1, false, {})
end)
local opts = {
max_width = max_width - border_info.horiz,
}
if documentation.max_height > 0 then
opts.max_height = documentation.max_height
end
vim.lsp.util.stylize_markdown(self.window:get_buffer(), documents, opts)
end
vim.api.nvim_buf_set_option(self.window:get_buffer(), 'modified', 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 = max_width - border_info.horiz,
max_height = documentation.max_height - border_info.vert,
}
)
if width <= 0 or height <= 0 then
return self:close()
end
local row
local place_above = false
if bottom_space >= height then
row = view.row + view.height
elseif top_space >= height then
row = view.row - height
place_above = true
else
if bottom_space >= top_space then
height = math.max(1, bottom_space)
row = view.row + view.height
else
height = math.max(1, top_space)
row = view.row - height
place_above = true
end
end
local col = view.col
self.window:option('winblend', documentation.winblend)
self.window:option('winhighlight', documentation.winhighlight)
local style = {
relative = 'editor',
style = 'minimal',
width = width,
height = height,
row = row,
col = col + documentation.col_offset,
border = documentation.border,
zindex = documentation.zindex or 50,
}
self.window:open(style)
end |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
How to show cmp_doc and cmp_menu in a vertical way, is there any inbuilt way of doing this ?
All reactions