Skip to content

Commit

Permalink
Normalize config
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbeam committed Feb 17, 2024
1 parent bab395f commit 3b04fa9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,18 @@ require("autocomplete.lsp").setup {

-- cmdline autocompletion
require("autocomplete.cmd").setup {
window = {
border = nil,
columns = 5,
rows = 0.3
},
mappings = {
accept = '<C-y>',
reject = '<C-e>',
complete = '<C-space>',
next = '<C-n>',
previous = '<C-p>',
},
debounce_delay = 100,
border = nil, -- Cmdline completion border style
columns = 5, -- Number of columns per row
rows = 0.3, -- Number of rows, if < 1 then its fraction of total vim lines, if > 1 then its absolute number
close_on_done = true, -- Close completion window when done (accept/reject)
debounce_delay = 100,
}
```

Expand All @@ -84,7 +82,7 @@ when resolving completion items:
-- Here we grab default Neovim capabilities and extend them with ones we want on top
local capabilities = vim.tbl_deep_extend('force',
vim.lsp.protocol.make_client_capabilities(),
require('completion.lsp').capabilities())
require('completion.lsp').capabilities)

-- Now set capabilities on your LSP servers
require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
Expand Down
16 changes: 7 additions & 9 deletions lua/autocomplete/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ local function open_win(height)
if not state.window.id or not vim.api.nvim_win_is_valid(state.window.id) then
state.window.id = vim.api.nvim_open_win(state.window.bufnr, false, {
relative = 'editor',
border = M.config.window.border,
border = M.config.border,
style = 'minimal',
width = vim.o.columns,
height = height,
Expand Down Expand Up @@ -115,12 +115,12 @@ local function cmdline_changed()
return
end

local window_height = M.config.window.rows
local window_height = M.config.rows
if window_height < 1 then
window_height = math.floor(vim.o.lines * window_height)
end

local col_width = math.floor(vim.o.columns / M.config.window.columns)
local col_width = math.floor(vim.o.columns / M.config.columns)

-- Recreate window if we closed it before
open_win(window_height)
Expand Down Expand Up @@ -242,20 +242,18 @@ local function leave_handler()
end

M.config = {
window = {
border = nil,
columns = 5,
rows = 0.3,
},
mappings = {
accept = '<C-y>',
reject = '<C-e>',
complete = '<C-space>',
next = '<C-n>',
previous = '<C-p>',
},
debounce_delay = 100,
border = nil, -- Cmdline completion border style
columns = 5, -- Number of columns per row
rows = 0.3, -- Number of rows, if < 1 then its fraction of total vim lines, if > 1 then its absolute number
close_on_done = true, -- Close completion window when done (accept/reject)
debounce_delay = 100,
}

function M.setup(config)
Expand Down
26 changes: 12 additions & 14 deletions lua/autocomplete/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,22 @@ M.config = {
debounce_delay = 100,
}

function M.capabilities()
return {
textDocument = {
completion = {
completionItem = {
-- Fetch additional info for completion items
resolveSupport = {
properties = {
'documentation',
'detail',
'additionalTextEdits',
},
M.capabilities = {
textDocument = {
completion = {
completionItem = {
-- Fetch additional info for completion items
resolveSupport = {
properties = {
'documentation',
'detail',
'additionalTextEdits',
},
},
},
},
}
end
},
}

function M.setup(config)
M.config = vim.tbl_deep_extend('force', M.config, config or {})
Expand Down

0 comments on commit 3b04fa9

Please sign in to comment.