Skip to content

Commit

Permalink
fix(cmp): handle LuaSnip jump failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Jint-lzxy authored and singlemancombat committed Apr 3, 2023
1 parent 28c13f1 commit ebee7b8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lua/modules/configs/completion/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ return function()
}
end

local cmp_window = require("cmp.utils.window")
---Handling situations where LuaSnip failed to perform any jumps
---@param r integer @Cursor position (row) before calling LuaSnip
---@param c integer @Cursor position (col) before calling LuaSnip
---@param fallback function @Fallback function inherited from cmp
local luasnip_fallback = vim.schedule_wrap(function(r, c, fallback)
local _r, _c = unpack(vim.api.nvim_win_get_cursor(0))
if _r == r and _c == c then
fallback()
end
end)

local cmp_window = require("cmp.utils.window")

cmp_window.info_ = cmp_window.info
cmp_window.info = function(self)
Expand Down Expand Up @@ -97,7 +108,9 @@ return function()
if cmp.visible() then
cmp.select_next_item()
elseif require("luasnip").expand_or_locally_jumpable() then
vim.fn.feedkeys(t("<Plug>luasnip-expand-or-jump"), "")
local _r, _c = unpack(vim.api.nvim_win_get_cursor(0))
vim.fn.feedkeys(t("<Plug>luasnip-expand-or-jump"))
luasnip_fallback(_r, _c, fallback)
else
fallback()
end
Expand Down

0 comments on commit ebee7b8

Please sign in to comment.