Refactor a bit

This commit is contained in:
hrsh7th
2022-11-25 01:57:19 +09:00
parent 0a9ccdf122
commit 431f045968
2 changed files with 8 additions and 6 deletions

View File

@@ -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

View File

@@ -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()