Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added on_attach_after config option #1146

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lua/gitsigns/attach.lua
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ local attach_throttled = throttle_by_id(function(cbuf, ctx, aucmd)

-- Initial update
manager.update(cbuf)
if config.on_attach_after then
config.on_attach_after(cbuf)
end

if config.current_line_blame then
require('gitsigns.current_line_blame').update(cbuf)
Expand Down
21 changes: 21 additions & 0 deletions lua/gitsigns/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
--- @field sign_priority integer
--- @field _on_attach_pre fun(bufnr: integer, callback: fun(_: table))
--- @field on_attach fun(bufnr: integer)
--- @field on_attach_after fun(bufnr: integer)
--- @field watch_gitdir { enable: boolean, follow_files: boolean }
--- @field max_file_length integer
--- @field update_debounce integer
Expand Down Expand Up @@ -390,6 +391,26 @@ M.schema = {
]],
},

on_attach_after = {
type = 'function',
default = nil,
description = [[
Callback called after initial update of attached buffer.
The buffer number is passed as the only argument.

Use this callback if you need hunk information,
for example to automatically navigate to some hunk

Example: >lua
on_attach_after = function(bufnr)
if jump_to_first_hunk then
require("gitsigns").nav_hunk("first")
end
end
<
]],
},

on_attach = {
type = 'function',
default = nil,
Expand Down
Loading