From 5df526c148e630dd550956c18463445a98e81f82 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 22 Oct 2024 13:29:59 +0200 Subject: [PATCH] feat: autocomplete with trigger chars after confirm fixes https://github.com/max397574/care.nvim/issues/115 --- lua/care/menu/confirm.lua | 4 ++++ lua/care/sources.lua | 14 +++++++++++++- lua/care/types/misc.lua | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lua/care/menu/confirm.lua b/lua/care/menu/confirm.lua index 6dddd96..eb56115 100644 --- a/lua/care/menu/confirm.lua +++ b/lua/care/menu/confirm.lua @@ -92,4 +92,8 @@ return function(entry) entry.source:execute(entry) end unblock() + vim.schedule(function() + require("care").core.context = require("care.context").new(require("care").core.context) + require("care").core:complete(3) + end) end diff --git a/lua/care/sources.lua b/lua/care/sources.lua index b5f16b6..b9ed4f6 100644 --- a/lua/care/sources.lua +++ b/lua/care/sources.lua @@ -60,12 +60,24 @@ function care_sources.complete(context, source, callback) callback(require("care.matcher").match(source.entries, prefix)) return end + elseif context.reason == 3 then + print(last_char) + vim.print(source:get_trigger_characters()) + if vim.tbl_contains(source:get_trigger_characters(), last_char) then + completion_context = { + triggerKind = 2, + triggerCharacter = last_char, + } + else + callback({}) + return + end else completion_context = { triggerKind = 1, } end - if source.incomplete then + if source.incomplete and not context.reason == 3 then completion_context = { triggerKind = 3, } diff --git a/lua/care/types/misc.lua b/lua/care/types/misc.lua index bdd9f27..130c84e 100644 --- a/lua/care/types/misc.lua +++ b/lua/care/types/misc.lua @@ -7,6 +7,7 @@ ---@alias care.completionReason ---| 1 # Auto ---| 2 # Manual +---| 3 # TriggerOnly --- The icons used for the different completion item types ---@alias care.config.ui.type_icons table