Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lua/blink/cmp/completion/accept/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 17 additions & 4 deletions lua/blink/cmp/lib/text_edits.lua
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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('<C-g>U' .. (amount > 0 and '<Right>' or '<Left>'), 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('<C-g>U' .. (amount > 0 and '<Right>' or '<Left>'), math.abs(amount))
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, true, true), 'in', false)
end)
end

return text_edits
4 changes: 1 addition & 3 deletions lua/blink/cmp/sources/lib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions lua/blink/cmp/sources/lib/provider/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions lua/blink/cmp/sources/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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