diff options
Diffstat (limited to 'Common/nvim/lua/lsp-conf.lua')
-rw-r--r-- | Common/nvim/lua/lsp-conf.lua | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/Common/nvim/lua/lsp-conf.lua b/Common/nvim/lua/lsp-conf.lua index 18a8f12..20ffcc5 100644 --- a/Common/nvim/lua/lsp-conf.lua +++ b/Common/nvim/lua/lsp-conf.lua @@ -76,6 +76,18 @@ autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) -- Completion Plugin Setup local cmp = require'cmp' + +local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 + and vim.api + .nvim_buf_get_lines(0, line - 1, line, true)[1] + :sub(col, col) + :match("%s") + == nil +end + cmp.setup({ -- Enable LSP snippets snippet = { @@ -85,13 +97,15 @@ cmp.setup({ }, mapping = { ['<C-p>'] = cmp.mapping.select_prev_item(), - ['<C-n>'] = cmp.mapping.select_next_item(), - -- Add tab support - ['<S-Tab>'] = cmp.mapping.select_prev_item(), - ['<Tab>'] = cmp.mapping.select_next_item(), - ['<C-S-f>'] = cmp.mapping.scroll_docs(-4), - ['<C-f>'] = cmp.mapping.scroll_docs(4), - ['<C-Space>'] = cmp.mapping.complete(), + ["<C-n>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), ['<C-e>'] = cmp.mapping.close(), ['<CR>'] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, @@ -112,6 +126,10 @@ cmp.setup({ completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, + completion = { + autocomplete = false, + completeopt = "menu,menuone,preview", + }, formatting = { fields = {'menu', 'abbr', 'kind'}, format = function(entry, item) |