From 431f0459681724c97e58899272b6acf5ff039cba Mon Sep 17 00:00:00 2001 From: hrsh7th <629908+hrsh7th@users.noreply.github.com> Date: Fri, 25 Nov 2022 01:57:19 +0900 Subject: [PATCH] Refactor a bit --- lua/cmp/config/default.lua | 8 +++++--- lua/cmp/core.lua | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lua/cmp/config/default.lua b/lua/cmp/config/default.lua index 5ad0e92..80f667c 100644 --- a/lua/cmp/config/default.lua +++ b/lua/cmp/config/default.lua @@ -5,7 +5,8 @@ local WIDE_HEIGHT = 40 ---@return cmp.ConfigSchema return function() - return { + ---@type cmp.ConfigSchema + local config = { enabled = function() local disabled = false disabled = disabled or (vim.api.nvim_buf_get_option(0, 'buftype') == 'prompt') @@ -17,7 +18,7 @@ return function() performance = { debounce = 60, throttle = 30, - fetching_timeout = 200, + fetching_timeout = 500, }, preselect = types.cmp.PreselectMode.Item, @@ -25,7 +26,7 @@ return function() mapping = {}, snippet = { - expand = function() + expand = function(_) error('snippet engine is not configured.') end, }, @@ -105,4 +106,5 @@ return function() }, }, } + return config end diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index ced21a1..574dc5e 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -369,6 +369,7 @@ core.confirm = function(self, e, option, callback) feedkeys.call(table.concat(keys, ''), 'in') end) feedkeys.call('', 'n', function() + -- Restore the line at the time of request. local ctx = context.new() if api.is_cmdline_mode() then local keys = {} @@ -377,13 +378,12 @@ core.confirm = function(self, e, option, callback) feedkeys.call(table.concat(keys, ''), 'in') else vim.cmd([[silent! undojoin]]) - vim.api.nvim_buf_set_text(0, ctx.cursor.row - 1, e:get_offset() - 1, ctx.cursor.row - 1, ctx.cursor.col - 1, { - string.sub(e.context.cursor_before_line, e:get_offset()), - }) + vim.api.nvim_set_current_line(e.context.cursor_line) vim.api.nvim_win_set_cursor(0, { e.context.cursor.row, e.context.cursor.col - 1 }) end end) feedkeys.call('', 'n', function() + -- Apply additionalTextEdits. local ctx = context.new() if #(misc.safe(e:get_completion_item().additionalTextEdits) or {}) == 0 then e:resolve(function()