Skip to content

Commit 119b36d

Browse files
committed
feat(oil): add debounced git highlights
- Highlights are now applied with a debounce effect. - Git status checks are more compatible with Windows. - Only relevant highlights are applied when in a git repository. - Improved performance by reducing unnecessary highlight updates.
1 parent 8c3699f commit 119b36d

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

plugin/filetypes/oil.lua

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,20 @@ local function get_git_status(callback)
5353
rel_path = "."
5454
end
5555

56+
-- Use git -c core.quotepath=false for Windows compatibility
57+
-- Only check current directory, not subdirectories
5658
vim.system({
5759
"git",
5860
"-C",
5961
git_root,
62+
"-c",
63+
"core.quotepath=false",
6064
"status",
61-
"--porcelain",
62-
"--ignored",
63-
"--",
64-
rel_path,
65-
}, { text = true }, function(result)
65+
"--porcelain=v1",
66+
"--untracked-files=normal",
67+
"--ignored=no",
68+
".",
69+
}, { text = true, cwd = current_dir }, function(result)
6670
if result.code ~= 0 or not result.stdout or result.stdout == "" then
6771
callback({})
6872
return
@@ -149,11 +153,30 @@ local function safe_apply_highlights()
149153
apply_git_highlights()
150154
end
151155

156+
local debounce_timer = nil
157+
local DEBOUNCE_MS = 150
158+
159+
local function debounced_apply_highlights()
160+
if debounce_timer then
161+
vim.uv.timer_stop(debounce_timer)
162+
end
163+
164+
debounce_timer = vim.uv.new_timer()
165+
debounce_timer:start(DEBOUNCE_MS, 0, function()
166+
vim.schedule(apply_git_highlights)
167+
debounce_timer:close()
168+
debounce_timer = nil
169+
end)
170+
end
171+
152172
vim.api.nvim_create_autocmd("BufEnter", {
153173
group = augroup,
154174
pattern = "oil://*",
155175
callback = function()
156-
vim.schedule(safe_apply_highlights)
176+
-- Only run if we're in a git repository
177+
if vim.git.get_root_dir() then
178+
vim.defer_fn(debounced_apply_highlights, 50)
179+
end
157180
end,
158181
})
159182

0 commit comments

Comments
 (0)