mirror of
https://github.com/lewis6991/gitsigns.nvim
synced 2025-02-15 19:56:52 +00:00
feat(blame): run formatter with pcall
If it fails, use the default format.
This commit is contained in:
parent
0349546134
commit
9ca00df1c8
@ -34,7 +34,7 @@
|
||||
--- | 'changedelete'
|
||||
--- | 'untracked'
|
||||
|
||||
--- @alias Gitsigns.CurrentLineBlameFmtFun fun(user: string, info: table<string,any>): {[1]:string,[2]:string}[]
|
||||
--- @alias Gitsigns.CurrentLineBlameFmtFun fun(user: string, info: table<string,any>): [string,string][]
|
||||
|
||||
--- @class (exact) Gitsigns.CurrentLineBlameOpts : Gitsigns.BlameOpts
|
||||
--- @field virt_text? boolean
|
||||
|
@ -1,8 +1,11 @@
|
||||
local async = require('gitsigns.async')
|
||||
local cache = require('gitsigns.cache').cache
|
||||
local config = require('gitsigns.config').config
|
||||
local schema = require('gitsigns.config').schema
|
||||
local util = require('gitsigns.util')
|
||||
|
||||
local error_once = require('gitsigns.message').error_once
|
||||
|
||||
local api = vim.api
|
||||
|
||||
local debounce = require('gitsigns.debounce')
|
||||
@ -72,19 +75,27 @@ end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param blame_info Gitsigns.BlameInfoPublic
|
||||
---@return {[1]: string, [2]:string}[]
|
||||
---@return [string, string][]
|
||||
local function get_blame_virt_text(bufnr, blame_info)
|
||||
local git_obj = assert(cache[bufnr]).git_obj
|
||||
local use_nc = blame_info.author == 'Not Committed Yet'
|
||||
|
||||
local clb_formatter = blame_info.author == 'Not Committed Yet'
|
||||
and config.current_line_blame_formatter_nc
|
||||
local clb_formatter = use_nc and config.current_line_blame_formatter_nc
|
||||
or config.current_line_blame_formatter
|
||||
|
||||
if type(clb_formatter) == 'string' then
|
||||
clb_formatter = default_formatter(clb_formatter)
|
||||
if type(clb_formatter) == 'function' then
|
||||
local ok, res = pcall(clb_formatter, git_obj.repo.username, blame_info)
|
||||
if ok then
|
||||
return res
|
||||
end
|
||||
|
||||
local nc_sfx = use_nc and '_nc' or ''
|
||||
error_once('Failed running config.current_line_blame_formatter%s, using default', nc_sfx)
|
||||
--- @type string
|
||||
clb_formatter = schema.current_line_blame_formatter.default
|
||||
end
|
||||
|
||||
return clb_formatter(git_obj.repo.username, blame_info)
|
||||
return default_formatter(clb_formatter)(git_obj.repo.username, blame_info)
|
||||
end
|
||||
|
||||
--- @param bufnr integer
|
||||
|
Loading…
Reference in New Issue
Block a user