From 0e8362a073aaa72df449c7c24dd01fa913ad1abe Mon Sep 17 00:00:00 2001 From: abeldekat Date: Wed, 8 Jan 2025 19:08:16 +0100 Subject: [PATCH] revert using vim.schedule. Makes the code harder to reason about. --- lua/cmp_mini_snippets/init.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lua/cmp_mini_snippets/init.lua b/lua/cmp_mini_snippets/init.lua index 4860e39..87ae65e 100644 --- a/lua/cmp_mini_snippets/init.lua +++ b/lua/cmp_mini_snippets/init.lua @@ -121,7 +121,7 @@ end -- Remove the word inserted by nvim-cmp and insert snippet -- It's safe to assume that mode is insert during completion -local insert_snippet = vim.schedule_wrap(function(snip, word) +local function insert_snippet(snip, word) local cursor = vim.api.nvim_win_get_cursor(0) cursor[1] = cursor[1] - 1 -- nvim_buf_set_text: line is zero based local start_col = cursor[2] - #word @@ -129,17 +129,14 @@ local insert_snippet = vim.schedule_wrap(function(snip, word) local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert insert({ body = snip.body }) -- insert at cursor -end) +end ---Executed after the item was selected. ---@param completion_item lsp.CompletionItem ---@param callback fun(completion_item: lsp.CompletionItem|nil) function source:execute(completion_item, callback) - callback(completion_item) - - -- After callback, scheduled - -- Sometimes cmp-nvim-lsp kicks in when it should not(#6) insert_snippet(completion_item.data.snip, completion_item.word) + callback(completion_item) end return source