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

Commit

Permalink
feat: preview lsp snippet in popup
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Apr 29, 2024
1 parent 3fceefb commit ed24941
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lua/epo/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local function timer_remove(t)
if t and t:is_active() and not t:is_closing() then
t:stop()
t:close()
---@diagnostic disable-next-line: cast-local-type
t = nil
end
end
Expand Down Expand Up @@ -90,8 +91,25 @@ local function close_popup_win(winid)
end
end

local function popup_markdown_set(wininfo)
vim.wo[wininfo.winid].conceallevel = 2
vim.wo[wininfo.winid].concealcursor = 'niv'
vim.treesitter.start(wininfo.bufnr, 'markdown')
end

local function show_info(bufnr, curitem, selected)
local param = vim.tbl_get(curitem, 'user_data', 'nvim', 'lsp', 'completion_item')
-- snippet preview in info
if curitem.kind == 's' then
local lang = vim.treesitter.language.get_lang(vim.bo[bufnr].filetype)
local info = ('```' .. lang .. '\n%s' .. '```'):format(
lsp._snippet_grammar.parse(param.insertText)
)
local wininfo = api.nvim_complete_set(selected, { info = info })
popup_markdown_set(wininfo)
return
end

local client = lsp.get_clients({ id = context[bufnr].client_id })[1]
client.request(ms.completionItem_resolve, param, function(_, result)
local data = vim.fn.complete_info()
Expand All @@ -112,9 +130,7 @@ local function show_info(bufnr, curitem, selected)
if vim.tbl_isempty(wininfo) then
return
end
vim.wo[wininfo.winid].conceallevel = 2
vim.wo[wininfo.winid].concealcursor = 'niv'
vim.treesitter.start(wininfo.bufnr, 'markdown')
popup_markdown_set(wininfo)
end, bufnr)
end

Expand Down

0 comments on commit ed24941

Please sign in to comment.