Skip to content

Commit 80fd5d4

Browse files
committed
perf: improve file scanning and async input handling
The changes optimize file scanning by using a dedicated scan_dir utility with gitignore support and improve async handling in context input processing: - Replace vim.fn.glob with optimized scan_dir utility - Add gitignore respect to file scanning - Fix potential UI freezes by properly handling async context input - Ensure scheduler is called before UI operations Closes #690 Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 3094dd8 commit 80fd5d4

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

lua/CopilotChat/config/contexts.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local async = require('plenary.async')
12
local context = require('CopilotChat.context')
23
local utils = require('CopilotChat.utils')
34

@@ -54,10 +55,12 @@ return {
5455
description = 'Includes content of provided file in chat context. Supports input.',
5556
input = function(callback, source)
5657
local cwd = utils.win_cwd(source.winnr)
57-
local files = vim.tbl_filter(function(file)
58-
return vim.fn.isdirectory(file) == 0
59-
end, vim.fn.glob(cwd .. '/**/*', false, true))
58+
local files = utils.scan_dir(cwd, {
59+
add_dirs = false,
60+
respect_gitignore = true,
61+
})
6062

63+
async.util.scheduler()
6164
vim.ui.select(files, {
6265
prompt = 'Select a file> ',
6366
}, callback)

lua/CopilotChat/init.lua

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,17 @@ function M.trigger_complete(with_context)
350350
if with_context and vim.startswith(prefix, '#') and vim.endswith(prefix, ':') then
351351
local found_context = M.config.contexts[prefix:sub(2, -2)]
352352
if found_context and found_context.input then
353-
found_context.input(function(value)
354-
if not value then
355-
return
356-
end
353+
async.run(function()
354+
found_context.input(function(value)
355+
if not value then
356+
return
357+
end
357358

358-
local value_str = tostring(value)
359-
vim.api.nvim_buf_set_text(bufnr, row - 1, col, row - 1, col, { value_str })
360-
vim.api.nvim_win_set_cursor(0, { row, col + #value_str })
361-
end, state.source or {})
359+
local value_str = tostring(value)
360+
vim.api.nvim_buf_set_text(bufnr, row - 1, col, row - 1, col, { value_str })
361+
vim.api.nvim_win_set_cursor(0, { row, col + #value_str })
362+
end, state.source or {})
363+
end)
362364
end
363365

364366
return

0 commit comments

Comments
 (0)