Skip to content

Commit

Permalink
Add support for documentation border
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Slusny <[email protected]>
  • Loading branch information
deathbeam committed Nov 22, 2024
1 parent b837603 commit eb58fef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ require("autocomplete.signature").setup {

-- buffer autocompletion with LSP and Tree-sitter
require("autocomplete.buffer").setup {
border = nil, -- Documentation border style
entry_mapper = nil, -- Custom completion entry mapper
debounce_delay = 100
debounce_delay = 100,
}

-- cmdline autocompletion
Expand Down
15 changes: 14 additions & 1 deletion lua/autocomplete/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ local function complete(prefix, cmp_start, items)
elseif entry1_under < entry2_under then
return true
end
return false
end)

vim.fn.complete(cmp_start + 1, items)
Expand Down Expand Up @@ -150,6 +151,14 @@ local function complete_changed(args)
local cur_info = vim.fn.complete_info()
local selected = cur_info.selected

if
M.config.border
and cur_info.preview_winid
and vim.api.nvim_win_is_valid(cur_info.preview_winid)
then
vim.api.nvim_win_set_config(cur_info.preview_winid, { border = M.config.border })
end

util.debounce(state.entries.info, M.config.debounce_delay, function()
local completion_item = vim.tbl_get(cur_item, 'user_data', 'nvim', 'lsp', 'completion_item')
if not completion_item then
Expand All @@ -175,7 +184,7 @@ local function complete_changed(args)
end

local info = vim.fn.complete_info()
if not info.items or not info.selected or not info.selected == selected then
if not info.items or not info.selected or info.selected ~= selected then
return
end

Expand All @@ -195,6 +204,7 @@ local function complete_changed(args)
end

M.config = {
border = nil, -- Documentation border style
entry_mapper = nil, -- Custom completion entry mapper
debounce_delay = 100,
}
Expand Down Expand Up @@ -227,6 +237,9 @@ function M.setup(config)
if not client then
return
end
if not vim.lsp.completion or not vim.lsp.completion.enable then
return
end
vim.lsp.completion.enable(true, client.id, event.buf, { autotrigger = false })
end,
})
Expand Down

0 comments on commit eb58fef

Please sign in to comment.