Skip to content

Commit

Permalink
fix(blame): do not run concurrent processes
Browse files Browse the repository at this point in the history
Fixes #877
  • Loading branch information
lewis6991 committed Sep 12, 2023
1 parent 907ae86 commit 853bd37
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lua/gitsigns/current_line_blame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local uv = vim.loop
local api = vim.api

local current_buf = api.nvim_get_current_buf
local throttle_by_id = require('gitsigns.debounce').throttle_by_id

local namespace = api.nvim_create_namespace('gitsigns_blame')

Expand Down Expand Up @@ -183,9 +184,9 @@ local function get_lnum()
return api.nvim_win_get_cursor(0)[1]
end

-- Update function, must be called in async context
local function update0()
local bufnr = current_buf()
--- Update function, must be called in async context
--- @param bufnr integer
local function update0(bufnr)
local lnum = get_lnum()

local old_lnum = get_extmark(bufnr)
Expand Down Expand Up @@ -231,7 +232,7 @@ local function update0()
if bufnr == current_buf() and lnum ~= lnum1 then
-- Cursor has moved during events; abort and tr-trigger another update
-- since it's likely blame jobs where skipped
update0()
update0(bufnr)
return
end

Expand All @@ -242,7 +243,7 @@ local function update0()
end
end

local update = async.void(update0)
local update = async.void(throttle_by_id(update0))

function M.setup()
local group = api.nvim_create_augroup('gitsigns_blame', {})
Expand All @@ -254,7 +255,9 @@ function M.setup()
if config.current_line_blame then
api.nvim_create_autocmd({ 'FocusGained', 'BufEnter', 'CursorMoved', 'CursorMovedI' }, {
group = group,
callback = update,
callback = function(args)
update(args.buf)
end
})

api.nvim_create_autocmd({ 'InsertEnter', 'FocusLost', 'BufLeave' }, {
Expand All @@ -266,7 +269,9 @@ function M.setup()

-- Call via vim.schedule to avoid the debounce timer killing the async
-- coroutine
vim.schedule(update)
vim.schedule(function()
update(api.nvim_get_current_buf())
end)
end
end

Expand Down

0 comments on commit 853bd37

Please sign in to comment.