Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
update doc render with popup
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Nov 1, 2023
1 parent eae3c8c commit a59af42
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions lua/epo/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,48 +59,36 @@ local function lspkind(kind)
return k:lower():sub(1, 1)
end

local function get_documentation(selected, param, bufnr)
lsp.buf_request(bufnr, ms.completionItem_resolve, param, function(_, result)
if not vim.tbl_get(result, 'documentation', 'value') then
return
end
local wininfo = api.nvim_complete_set_info(selected, result.documentation.value)
if not vim.tbl_isempty(wininfo) and wininfo.bufnr and api.nvim_buf_is_valid(wininfo.bufnr) then
vim.bo[wininfo.bufnr].filetype = 'markdown'
end
end)
end

local function show_info(cmp_info, bufnr)
if not cmp_info.items[cmp_info.selected + 1] then
return
end
local info = vim.tbl_get(cmp_info.items[cmp_info.selected + 1], 'info')
local function show_info(bufnr)
local info = vim.tbl_get(vim.v.event, 'completed_item', 'info')
local data = vim.fn.complete_info()
local selected = data.selected
if not info or #info == 0 then
local param = vim.tbl_get(
cmp_info.items[cmp_info.selected + 1],
'user_data',
'nvim',
'lsp',
'completion_item'
)
get_documentation(cmp_info.selected, param, bufnr)
local param =
vim.tbl_get(vim.v.event.completed_item, 'user_data', 'nvim', 'lsp', 'completion_item')
local client = lsp.get_clients({ id = context[bufnr].client_id })[1]
client.request(ms.completionItem_resolve, param, function(_, result)
if not result then
return
end
local value = vim.tbl_get(result, 'documentation', 'value')
local kind = vim.tbl_get(result, 'documentation', 'kind')
if value then
local wininfo = api.nvim_complete_set_info(selected, value)
api.nvim_set_option_value('filetype', kind or '', { buf = wininfo.bufnr })
end
end, bufnr)
end
end

local function complete_changed(bufnr)
api.nvim_create_autocmd('CompleteChanged', {
buffer = bufnr,
group = group,
once = true,
callback = function(args)
local cmp_info = vfn.complete_info()
if cmp_info.selected == -1 then
return
end
local build = vim.version().build
if build:match('^g') or build:match('dirty') then
show_info(cmp_info, args.buf)
show_info(args.buf)
end
end,
})
Expand Down

0 comments on commit a59af42

Please sign in to comment.