mirror of
https://github.com/neovim/neovim.git
synced 2026-04-25 16:54:12 +00:00
fix(lsp): handle completion/resolve response arriving after on_insert_leave
If a user accepts completion and immediately exits insert mode, it could happen that `Context.cursor` was nil by the time the `completion/resolve` response arrives, leading to an error.
This commit is contained in:
committed by
Mathias Fußenegger
parent
24684f90ea
commit
507cd63418
@@ -850,6 +850,10 @@ local function on_complete_done()
|
|||||||
local position_encoding = client.offset_encoding or 'utf-16'
|
local position_encoding = client.offset_encoding or 'utf-16'
|
||||||
local resolve_provider = (client.server_capabilities.completionProvider or {}).resolveProvider
|
local resolve_provider = (client.server_capabilities.completionProvider or {}).resolveProvider
|
||||||
|
|
||||||
|
-- Keep reference to avoid race where completion/resolve response arrives after on_insert_leave
|
||||||
|
-- and Context.cursor got cleared before clear_word() gets called
|
||||||
|
local context_cursor = assert(Context.cursor)
|
||||||
|
|
||||||
local function clear_word()
|
local function clear_word()
|
||||||
if not expand_snippet then
|
if not expand_snippet then
|
||||||
return nil
|
return nil
|
||||||
@@ -858,8 +862,8 @@ local function on_complete_done()
|
|||||||
-- Remove the already inserted word.
|
-- Remove the already inserted word.
|
||||||
api.nvim_buf_set_text(
|
api.nvim_buf_set_text(
|
||||||
bufnr,
|
bufnr,
|
||||||
Context.cursor[1] - 1,
|
context_cursor[1] - 1,
|
||||||
Context.cursor[2] - 1,
|
context_cursor[2] - 1,
|
||||||
cursor_row,
|
cursor_row,
|
||||||
cursor_col,
|
cursor_col,
|
||||||
{ '' }
|
{ '' }
|
||||||
|
|||||||
Reference in New Issue
Block a user