Skip to content

Commit

Permalink
Attempt to fix missing label in some situations
Browse files Browse the repository at this point in the history
Seems like doesn't help much, but not bad to control scheduling a little
bit better
  • Loading branch information
monkoose committed Nov 5, 2024
1 parent 38213b9 commit 17580e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
41 changes: 25 additions & 16 deletions lua/neocodeium/completer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ function Completer:enabled()
end

function Completer:update_label()
if utils.is_insert() and utils.is_empty(self.inline) and not self.block.text then
vim.schedule(function()
vim.schedule(function()
if utils.is_insert() and utils.is_empty(self.inline) and not self.block.text then
self:display_label()
end)
end
end
end)
end

---@private
Expand Down Expand Up @@ -352,13 +352,9 @@ end
---@private
function Completer:start_clear_timer()
if not self.clear_timer:is_active() then
self.clear_timer:start(
350,
0,
vim.schedule_wrap(function()
self:clear_all()
end)
)
self.clear_timer:start(350, 0, function()
self:clear_all(false, true)
end)
end
end

Expand Down Expand Up @@ -498,20 +494,33 @@ end

---Clears plugin's namespace and resets cache
---@param with_reset? boolean
function Completer:clear_all(with_reset)
---@param scheduled? boolean
function Completer:clear_all(with_reset, scheduled)
if with_reset then
self.clear_timer:stop()
nvim_buf_clear_namespace(0, ns, 0, -1)
self.label.id = nil
self.inline = {}
self.block.id = nil
self.block.text = nil
self.fulltext = ""
if scheduled then
vim.schedule(function()
nvim_buf_clear_namespace(0, ns, 0, -1)
end)
else
nvim_buf_clear_namespace(0, ns, 0, -1)
end
events.emit("NeoCodeiumCompletionCleared", nil, true)
else
-- self:clear_label()
self:clear_inline()
self:clear_block()
if scheduled then
vim.schedule(function()
self:clear_inline()
self:clear_block()
end)
else
self:clear_inline()
self:clear_block()
end
end
end

Expand Down
1 change: 0 additions & 1 deletion lua/neocodeium/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ local function enable_autocmds()

create_autocmd("InsertEnter", {
callback = function()
completer:update_label()
completer:initiate()
end,
})
Expand Down

0 comments on commit 17580e5

Please sign in to comment.