diff --git a/lua/blink/cmp/completion/accept/init.lua b/lua/blink/cmp/completion/accept/init.lua index 1562734a4..076dbf9b1 100644 --- a/lua/blink/cmp/completion/accept/init.lua +++ b/lua/blink/cmp/completion/accept/init.lua @@ -72,9 +72,6 @@ local function apply_item(ctx, item) text_edits_lib.move_cursor_in_dot_repeat(offset) end - -- Notify the rust module that the item was accessed - require('blink.cmp.fuzzy').access(item) - -- Check semantic tokens for brackets, if needed, asynchronously if brackets_status == 'check_semantic_token' then brackets_lib.add_brackets_via_semantic_token(ctx, vim.bo.filetype, item):map(function(added_brackets) @@ -111,12 +108,17 @@ local function accept(ctx, item, callback) return sources.execute( ctx, resolved_item, - function(alternate_ctx, alternate_item) apply_item(alternate_ctx or ctx, alternate_item or resolved_item) end + function(alternate_ctx, alternate_item) return apply_item(alternate_ctx or ctx, alternate_item or resolved_item) end ) end) :map(function() + -- Notify the rust module that the item was accessed + require('blink.cmp.fuzzy').access(item) + + -- Notify signature/completion require('blink.cmp.completion.trigger').show_if_on_trigger_character({ is_accept = true }) require('blink.cmp.signature.trigger').show_if_on_trigger_character() + callback() end) :catch(function(err) vim.notify(err, vim.log.levels.ERROR, { title = 'blink.cmp' }) end) diff --git a/lua/blink/cmp/lib/text_edits.lua b/lua/blink/cmp/lib/text_edits.lua index d5ce29394..e14321fa8 100644 --- a/lua/blink/cmp/lib/text_edits.lua +++ b/lua/blink/cmp/lib/text_edits.lua @@ -1,3 +1,4 @@ +local async = require('blink.cmp.lib.async') local config = require('blink.cmp.config') local utils = require('blink.cmp.lib.utils') local context = require('blink.cmp.completion.trigger.context') @@ -416,10 +417,22 @@ end --- Moves the cursor while preserving dot repeat --- @param amount number Number of characters to move the cursor by, can be negative to move left function text_edits.move_cursor_in_dot_repeat(amount) - if amount == 0 then return end - - local keys = string.rep('U' .. (amount > 0 and '' or ''), math.abs(amount)) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, true, true), 'in', false) + if amount == 0 then return async.task.empty() end + + return async.task.new(function(resolve) + local augroup = vim.api.nvim_create_augroup('BlinkCmpDotRepeatCursorCallback', { clear = true }) + vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { + group = augroup, + callback = function() + resolve() + vim.api.nvim_del_augroup_by_id(augroup) + end, + once = true, + }) + + local keys = string.rep('U' .. (amount > 0 and '' or ''), math.abs(amount)) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, true, true), 'in', false) + end) end return text_edits diff --git a/lua/blink/cmp/sources/lib/init.lua b/lua/blink/cmp/sources/lib/init.lua index 129365672..6b4db95db 100644 --- a/lua/blink/cmp/sources/lib/init.lua +++ b/lua/blink/cmp/sources/lib/init.lua @@ -238,9 +238,7 @@ function sources.execute(context, item, default_implementation) break end end - if item_source == nil then - return async.task.new(function(resolve) resolve() end) - end + if item_source == nil then return async.task.empty() end return item_source :execute(context, item, default_implementation) diff --git a/lua/blink/cmp/sources/lib/provider/init.lua b/lua/blink/cmp/sources/lib/provider/init.lua index 080dd293f..4c231780c 100644 --- a/lua/blink/cmp/sources/lib/provider/init.lua +++ b/lua/blink/cmp/sources/lib/provider/init.lua @@ -15,7 +15,7 @@ --- @field should_show_items fun(self: blink.cmp.SourceProvider, context: blink.cmp.Context, items: blink.cmp.CompletionItem[]): boolean --- @field transform_items fun(self: blink.cmp.SourceProvider, context: blink.cmp.Context, items: blink.cmp.CompletionItem[]): blink.cmp.CompletionItem[] --- @field resolve fun(self: blink.cmp.SourceProvider, context: blink.cmp.Context, item: blink.cmp.CompletionItem): blink.cmp.Task ---- @field execute fun(self: blink.cmp.SourceProvider, context: blink.cmp.Context, item: blink.cmp.CompletionItem, default_implementation: fun(context?: blink.cmp.Context, item?: blink.cmp.CompletionItem)): blink.cmp.Task +--- @field execute fun(self: blink.cmp.SourceProvider, context: blink.cmp.Context, item: blink.cmp.CompletionItem, default_implementation: fun(context?: blink.cmp.Context, item?: blink.cmp.CompletionItem): blink.cmp.Task): blink.cmp.Task --- @field get_signature_help_trigger_characters fun(self: blink.cmp.SourceProvider): { trigger_characters: string[], retrigger_characters: string[] } --- @field get_signature_help fun(self: blink.cmp.SourceProvider, context: blink.cmp.SignatureHelpContext): blink.cmp.Task --- @field reload (fun(self: blink.cmp.SourceProvider): nil) | nil @@ -157,10 +157,7 @@ end --- Execute --- function source:execute(context, item, default_implementation) - if self.module.execute == nil then - default_implementation() - return async.task.empty() - end + if self.module.execute == nil then return default_implementation() end return async.task.new( function(resolve) return self.module:execute(context, item, resolve, default_implementation) end diff --git a/lua/blink/cmp/sources/lsp/init.lua b/lua/blink/cmp/sources/lsp/init.lua index d4a437def..9966b2f7a 100644 --- a/lua/blink/cmp/sources/lsp/init.lua +++ b/lua/blink/cmp/sources/lsp/init.lua @@ -192,19 +192,19 @@ end --- Execute --- function lsp:execute(ctx, item, callback, default_implementation) - default_implementation() - - local client = vim.lsp.get_client_by_id(item.client_id) - if client and item.command then - if vim.fn.has('nvim-0.11') == 1 then - client:exec_cmd(item.command, { bufnr = ctx.bufnr }, function() callback() end) + return default_implementation():map(function() + local client = vim.lsp.get_client_by_id(item.client_id) + if client and item.command then + if vim.fn.has('nvim-0.11') == 1 then + client:exec_cmd(item.command, { bufnr = ctx.bufnr }, function() callback() end) + else + -- TODO: remove this once 0.11 is the minimum version + client:_exec_cmd(item.command, { bufnr = ctx.bufnr }, function() callback() end) + end else - -- TODO: remove this once 0.11 is the minimum version - client:_exec_cmd(item.command, { bufnr = ctx.bufnr }, function() callback() end) + callback() end - else - callback() - end + end) end return lsp