perf(git): minor performance cleanups

This commit is contained in:
2026-04-27 13:27:22 +02:00
parent 5966454462
commit 20dc6cc3c9
4 changed files with 51 additions and 30 deletions
+28 -11
View File
@@ -18,16 +18,8 @@ local SPLIT_HANDLERS = {
---@type string[]?
local cached_cmds
---@return string[]
local function git_cmds()
if cached_cmds then
return cached_cmds
end
local result = vim.system(
{ "git", "--list-cmds=main,others,alias" },
{ text = true }
)
:wait()
---@param result vim.SystemCompleted
local function populate_cached_cmds(result)
cached_cmds = {}
if result.code == 0 then
for line in (result.stdout or ""):gmatch("[^\r\n]+") do
@@ -37,7 +29,31 @@ local function git_cmds()
end
table.sort(cached_cmds)
end
return cached_cmds
end
---Prime `cached_cmds` asynchronously so the first `:G <Tab>` doesn't block.
local function prefetch_cmds()
vim.system(
{ "git", "--list-cmds=main,others,alias" },
{ text = true },
function(result)
vim.schedule(function()
populate_cached_cmds(result)
end)
end
)
end
---@return string[]
local function git_cmds()
if cached_cmds then
return cached_cmds
end
populate_cached_cmds(
vim.system({ "git", "--list-cmds=main,others,alias" }, { text = true })
:wait()
)
return cached_cmds or {}
end
---@param content string
@@ -204,6 +220,7 @@ local function complete(arg_lead, cmd_line, _)
end
function M.setup()
prefetch_cmds()
vim.api.nvim_create_user_command("G", function(opts)
M.run(opts.fargs)
end, {