Skip to content

Commit

Permalink
fix: schedule get_bufnrs for buffer source
Browse files Browse the repository at this point in the history
  • Loading branch information
Saghen committed Dec 12, 2024
1 parent f0ab5e5 commit 342c5ed
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions lua/blink/cmp/sources/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,25 @@ function buffer:get_completions(_, callback)
callback({ is_incomplete_forward = false, is_incomplete_backward = false, items = items })
end

local bufnrs = require('blink.cmp.lib.utils').deduplicate(self.get_bufnrs())
local buf_texts = {}
for _, buf in ipairs(bufnrs) do
table.insert(buf_texts, get_buf_text(buf))
end
local buf_text = table.concat(buf_texts, '\n')
-- should take less than 2ms
if #buf_text < 20000 then
run_sync(buf_text, transformed_callback)
-- should take less than 10ms
elseif #buf_text < 500000 then
run_async(buf_text, transformed_callback)
-- too big so ignore
else
transformed_callback({})
end
vim.schedule(function()
local bufnrs = require('blink.cmp.lib.utils').deduplicate(self.get_bufnrs())
local buf_texts = {}
for _, buf in ipairs(bufnrs) do
table.insert(buf_texts, get_buf_text(buf))
end
local buf_text = table.concat(buf_texts, '\n')

-- should take less than 2ms
if #buf_text < 20000 then
run_sync(buf_text, transformed_callback)
-- should take less than 10ms
elseif #buf_text < 500000 then
run_async(buf_text, transformed_callback)
-- too big so ignore
else
transformed_callback({})
end
end)

-- TODO: cancel run_async
return function() end
Expand Down

0 comments on commit 342c5ed

Please sign in to comment.