Skip to content

Commit

Permalink
feat(blame): added config.current_line_blame_formatter_nc
Browse files Browse the repository at this point in the history
Used to format uncommitted lines.

Resolves: #476
  • Loading branch information
lewis6991 committed Apr 14, 2022
1 parent a6a772d commit 43e6fc5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
9 changes: 9 additions & 0 deletions doc/gitsigns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,15 @@ current_line_blame_formatter *gitsigns-config-current_line_blame_formatter*
field of |nvim_buf_set_extmark| and thus must be a list of
[text, highlight] tuples.

current_line_blame_formatter_nc
*gitsigns-config-current_line_blame_formatter_nc*
Type: `string|function`, Default: `' <author>'`

String or function used to format the virtual text of
|gitsigns-config-current_line_blame| for lines that aren't committed.

See |gitsigns-config-current_line_blame_formatter| for more information.

trouble *gitsigns-config-trouble*
Type: `boolean`, Default: true if installed

Expand Down
12 changes: 12 additions & 0 deletions lua/gitsigns/config.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions lua/gitsigns/current_line_blame.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions teal/gitsigns/config.tl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ local record M
end

current_line_blame_formatter: string|function(string, {string:any}, current_line_blame_formatter_opts): {{string,string}}
current_line_blame_formatter_nc: string|function(string, {string:any}, current_line_blame_formatter_opts): {{string,string}}

record current_line_blame_opts
virt_text: boolean
Expand Down Expand Up @@ -557,6 +558,17 @@ M.schema = {
]]
},

current_line_blame_formatter_nc = {
type = {'string', 'function'},
default = ' <author>',
description = [[
String or function used to format the virtual text of
|gitsigns-config-current_line_blame| for lines that aren't committed.
See |gitsigns-config-current_line_blame_formatter| for more information.
]]
},

trouble = {
type = 'boolean',
default = function(): boolean
Expand Down
8 changes: 3 additions & 5 deletions teal/gitsigns/current_line_blame.tl
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ local function expand_blame_format(fmt: string, name: string, info: BlameInfo):
info.author = 'You'
end

if info.author == 'Not Committed Yet' then
return info.author
end

for k, v in pairs{
author_time = info.author_time,
committer_time = info.committer_time,
Expand Down Expand Up @@ -182,7 +178,9 @@ local update = void(function()
api.nvim_buf_set_var(bufnr, 'gitsigns_blame_line_dict', result)
if opts.virt_text and result then
local virt_text: {{string, string}}
local clb_formatter = config.current_line_blame_formatter
local clb_formatter = result.author == 'Not Committed Yet' and
config.current_line_blame_formatter_nc or
config.current_line_blame_formatter
if clb_formatter is string then
virt_text = {{
expand_blame_format(clb_formatter, bcache.git_obj.repo.username, result),
Expand Down

0 comments on commit 43e6fc5

Please sign in to comment.