mirror of
https://github.com/neovim/neovim
synced 2025-07-17 17:51:48 +00:00
fix(lsp): cancel session when leaving snippet region (#25762)
This commit is contained in:
committed by
GitHub
parent
9de157bce4
commit
15983cf2c6
@ -278,13 +278,26 @@ local function setup_autocmds(bufnr)
|
|||||||
desc = 'Update snippet state when the cursor moves',
|
desc = 'Update snippet state when the cursor moves',
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function()
|
||||||
|
local cursor_row, cursor_col = cursor_pos()
|
||||||
|
|
||||||
|
-- The cursor left the snippet region.
|
||||||
|
local snippet_range = get_extmark_range(bufnr, M._session.extmark_id)
|
||||||
|
if
|
||||||
|
cursor_row < snippet_range[1]
|
||||||
|
or (cursor_row == snippet_range[1] and cursor_col < snippet_range[2])
|
||||||
|
or cursor_row > snippet_range[3]
|
||||||
|
or (cursor_row == snippet_range[3] and cursor_col > snippet_range[4])
|
||||||
|
then
|
||||||
|
M.exit()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
-- Just update the tabstop in insert and select modes.
|
-- Just update the tabstop in insert and select modes.
|
||||||
if not vim.fn.mode():match('^[isS]') then
|
if not vim.fn.mode():match('^[isS]') then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update the current tabstop to be the one containing the cursor.
|
-- Update the current tabstop to be the one containing the cursor.
|
||||||
local cursor_row, cursor_col = cursor_pos()
|
|
||||||
for tabstop_index, tabstops in pairs(M._session.tabstops) do
|
for tabstop_index, tabstops in pairs(M._session.tabstops) do
|
||||||
for _, tabstop in ipairs(tabstops) do
|
for _, tabstop in ipairs(tabstops) do
|
||||||
local range = tabstop:get_range()
|
local range = tabstop:get_range()
|
||||||
|
@ -164,4 +164,11 @@ describe('vim.snippet', function()
|
|||||||
feed('<esc>Vjjd')
|
feed('<esc>Vjjd')
|
||||||
eq(false, exec_lua('return vim.snippet.active()'))
|
eq(false, exec_lua('return vim.snippet.active()'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('cancels session when leaving snippet region', function()
|
||||||
|
feed('i<cr>')
|
||||||
|
test_success({ 'local function $1()', ' $0', 'end' }, { '', 'local function ()', ' ', 'end' })
|
||||||
|
feed('<esc>k')
|
||||||
|
eq(false, exec_lua('return vim.snippet.active()'))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user