Skip to content

Commit

Permalink
fix: trigger GitSignsUpdate autocmd more often
Browse files Browse the repository at this point in the history
Resolves #831 #832
  • Loading branch information
lewis6991 committed Apr 4, 2024
1 parent 2b96835 commit 1389134
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions doc/gitsigns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1167,8 +1167,8 @@ like so: >lua

vim.api.nvim_create_autocmd('User', {
pattern = 'GitSignsUpdate',
callback = function()
print(os.time() .. ' Gitsigns made an update')
callback = function(args)
print(os.time(), ' Gitsigns made an update on ', args.data.buffer)
end
})

Expand Down
4 changes: 2 additions & 2 deletions etc/doc_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ like so: >lua

vim.api.nvim_create_autocmd('User', {
pattern = 'GitSignsUpdate',
callback = function()
print(os.time() .. ' Gitsigns made an update')
callback = function(args)
print(os.time(), ' Gitsigns made an update on ', args.data.buffer)
end
})

Expand Down
6 changes: 6 additions & 0 deletions lua/gitsigns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ local function update_cwd_head()
end

async.scheduler()

api.nvim_exec_autocmds('User', {
pattern = 'GitSignsUpdate',
modeline = false,
})

vim.g.gitsigns_head = head

if not gitdir then
Expand Down
11 changes: 3 additions & 8 deletions lua/gitsigns/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -521,16 +521,11 @@ M.update = throttle_by_id(function(bufnr)
update_show_deleted(bufnr)
bcache.force_next_update = false

api.nvim_exec_autocmds('User', {
pattern = 'GitSignsUpdate',
modeline = false,
})
local summary = gs_hunks.get_summary(bcache.hunks)
summary.head = git_obj.repo.abbrev_head
Status:update(bufnr, summary)
end

local summary = gs_hunks.get_summary(bcache.hunks)
summary.head = git_obj.repo.abbrev_head
Status:update(bufnr, summary)

update_cnt = update_cnt + 1

dprintf('updates: %s, jobs: %s', update_cnt, system.job_cnt)
Expand Down
16 changes: 12 additions & 4 deletions lua/gitsigns/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ local api = vim.api

local M = {}

--- @param bufnr integer
local function autocmd_update(bufnr)
api.nvim_exec_autocmds('User', {
pattern = 'GitSignsUpdate',
modeline = false,
data = { buffer = bufnr },
})
end

--- @param bufnr integer
--- @param status Gitsigns.StatusObj
function M:update(bufnr, status)
Expand All @@ -26,6 +35,8 @@ function M:update(bufnr, status)
local config = require('gitsigns.config').config

vim.b[bufnr].gitsigns_status = config.status_formatter(status)

autocmd_update(bufnr)
end

function M:clear(bufnr)
Expand All @@ -35,10 +46,7 @@ function M:clear(bufnr)
vim.b[bufnr].gitsigns_head = nil
vim.b[bufnr].gitsigns_status_dict = nil
vim.b[bufnr].gitsigns_status = nil
end

function M:clear_diff(bufnr)
self:update(bufnr, { added = 0, removed = 0, changed = 0 })
autocmd_update(bufnr)
end

return M
15 changes: 7 additions & 8 deletions test/actions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,19 @@ describe('actions', function()
eq(pos, helpers.api.nvim_win_get_cursor(0))
end

check_cursor({6,0})
check_cursor({ 6, 0 })
command('Gitsigns next_hunk') -- Wrap
check_cursor({1,0})
check_cursor({ 1, 0 })
command('Gitsigns next_hunk')
check_cursor({4,0})
check_cursor({ 4, 0 })
command('Gitsigns next_hunk')
check_cursor({6,0})
check_cursor({ 6, 0 })

command('Gitsigns prev_hunk')
check_cursor({4,0})
check_cursor({ 4, 0 })
command('Gitsigns prev_hunk')
check_cursor({1,0})
check_cursor({ 1, 0 })
command('Gitsigns prev_hunk') -- Wrap
check_cursor({6,0})

check_cursor({ 6, 0 })
end)
end)

0 comments on commit 1389134

Please sign in to comment.