perf: cache repo root and harden async paths (#100)
## Problem `get_repo_root()` shells out to `git rev-parse` on every call, causing 4-6 redundant subprocesses per `gdiff_file()` invocation. Three other minor issues: `highlight_vim_syntax()` leaks a scratch buffer if `nvim_buf_call` errors, `lib.ensure()` silently drops callbacks during download so hunks highlighted mid-download permanently miss intra-line highlights, and the debounce timer callback can operate on a deleted buffer. ## Solution Cache `get_repo_root()` results by parent directory — repo roots don't change within a session. Wrap `nvim_buf_call` and `nvim_buf_delete` in pcall so the scratch buffer is always cleaned up. Replace the early `callback(nil)` in `lib.ensure()` with a pending callback queue that fires once the download completes. Guard the debounce timer callback with `nvim_buf_is_valid`.
This commit is contained in:
parent
a2053a132b
commit
f5a090baae
4 changed files with 30 additions and 14 deletions
|
|
@ -238,7 +238,7 @@ local function highlight_vim_syntax(bufnr, ns, hunk, code_lines, covered_lines,
|
|||
|
||||
local spans = {}
|
||||
|
||||
vim.api.nvim_buf_call(scratch, function()
|
||||
pcall(vim.api.nvim_buf_call, scratch, function()
|
||||
vim.cmd('setlocal syntax=' .. ft)
|
||||
vim.cmd('redraw')
|
||||
|
||||
|
|
@ -256,7 +256,7 @@ local function highlight_vim_syntax(bufnr, ns, hunk, code_lines, covered_lines,
|
|||
spans = M.coalesce_syntax_spans(query_fn, code_lines)
|
||||
end)
|
||||
|
||||
vim.api.nvim_buf_delete(scratch, { force = true })
|
||||
pcall(vim.api.nvim_buf_delete, scratch, { force = true })
|
||||
|
||||
local hunk_line_count = #hunk.lines
|
||||
local extmark_count = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue