Skip to content

Commit

Permalink
Add dismiss_suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed Jun 26, 2024
1 parent 8e2c1b7 commit 0622c67
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lua/fittencode/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ M.api = {
has_suggestions = function()
return InlineEngine.has_suggestions()
end,
dismiss_suggestions = function()
InlineEngine.dismiss()
end,
accept_all_suggestions = function()
InlineEngine.accept_all_suggestions()
end,
Expand Down
21 changes: 21 additions & 0 deletions lua/fittencode/engines/inline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,23 @@ local extmark_ids = { {}, {} }
local generate_one_stage_timer = nil

local ignore_event = false
local ignore_cursor = nil

-- milliseconds
local CURSORMOVED_INTERVAL = 120

---@type uv_timer_t?
local cursormoved_timer = nil

local function testandclear_cursor_ignored(row, col)
local c = ignore_cursor
ignore_cursor = nil
if c and c[1] == row and c[2] == col then
return true
end
return false
end

local function inline_suggestions_ready()
return M.is_inline_enabled() and M.has_suggestions()
end
Expand Down Expand Up @@ -279,6 +289,7 @@ function M.triggering_completion()
end, function()
fx()
end)
ignore_cursor = { Base.get_cursor() }
end

---@param fx? function
Expand Down Expand Up @@ -510,6 +521,8 @@ end

function M.on_leave()
M.reset()
ignore_event = false
ignore_cursor = nil
end

-- '<80>kd', '<80>kD' in Lua
Expand Down Expand Up @@ -558,6 +571,9 @@ function M.on_cursor_hold()
if not row or not col then
return
end
if testandclear_cursor_ignored(row, col) then
return
end
M.generate_one_stage(row, col)
end

Expand Down Expand Up @@ -667,6 +683,11 @@ local function setup_autocmds()
})
end

function M.dismiss()
M.reset()
ignore_cursor = { Base.get_cursor() }
end

function M.setup()
model = Model:new()
tasks = TaskScheduler:new('InlineEngine')
Expand Down

0 comments on commit 0622c67

Please sign in to comment.