feat: blame single line and remove all blame implemented
This commit is contained in:
@@ -1,6 +1,44 @@
|
|||||||
local ns = vim.api.nvim_create_namespace('line_blame');
|
local ns = vim.api.nvim_create_namespace('line_blame');
|
||||||
|
|
||||||
local lineBlame = function(input_file_path, input_comma_separated_mail_list, blame_text, blame_highlight, blame_position)
|
local clearBlame = function()
|
||||||
|
vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
|
||||||
|
end
|
||||||
|
|
||||||
|
local setNvimMark = function(line_number, blame_text, blame_highlight, blame_position)
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns, line_number, 0, {
|
||||||
|
id = line_number + 1, -- cant be 0
|
||||||
|
virt_text = { { blame_text, blame_highlight } },
|
||||||
|
virt_text_pos = blame_position,
|
||||||
|
priority = 700,
|
||||||
|
hl_mode = 'combine',
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local lineBlame = function(input_file_path, line_number, input_comma_separated_mail_list, blame_text, blame_highlight,
|
||||||
|
blame_position)
|
||||||
|
local handler = io.popen("git blame -L " .. line_number .. "," .. line_number .. " -e " ..
|
||||||
|
input_file_path .. " | awk '{print $2}'")
|
||||||
|
if handler == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = handler:read("L")
|
||||||
|
|
||||||
|
if result == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local mail = string.match(result, "%(<(.+)>")
|
||||||
|
|
||||||
|
if not mail then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
for target_mail in string.gmatch(input_comma_separated_mail_list, "[^,]+") do
|
||||||
|
if target_mail == mail then
|
||||||
|
setNvimMark(tonumber(line_number), blame_text, blame_highlight, blame_position)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- lineBlame
|
-- lineBlame
|
||||||
@@ -19,13 +57,7 @@ local fileBlame = function(input_file_path, input_comma_separated_mail_list, bla
|
|||||||
for current_line_mail, line_number in string.gmatch(result, "%(<(.+)>(%d+)%)") do
|
for current_line_mail, line_number in string.gmatch(result, "%(<(.+)>(%d+)%)") do
|
||||||
for target_mail in string.gmatch(input_comma_separated_mail_list, "[^,]+") do
|
for target_mail in string.gmatch(input_comma_separated_mail_list, "[^,]+") do
|
||||||
if target_mail == current_line_mail then
|
if target_mail == current_line_mail then
|
||||||
vim.api.nvim_buf_set_extmark(0, ns, tonumber(line_number) - 1, 0, {
|
setNvimMark(tonumber(line_number) - 1, blame_text, blame_highlight, blame_position)
|
||||||
id = tonumber(line_number),
|
|
||||||
virt_text = { { blame_text, blame_highlight } },
|
|
||||||
virt_text_pos = blame_position,
|
|
||||||
priority = 700,
|
|
||||||
hl_mode = 'combine',
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -35,6 +67,7 @@ local fileBlame = function(input_file_path, input_comma_separated_mail_list, bla
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
clearBlame = clearBlame,
|
||||||
lineBlame = lineBlame,
|
lineBlame = lineBlame,
|
||||||
fileBlame = fileBlame,
|
fileBlame = fileBlame,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,19 @@ local function blameCurrentFile()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function blameCurrentLine()
|
local function blameCurrentLine()
|
||||||
blame.lineBlame(vim.api.nvim_buf_get_name(0), vim.g.monkeyMailList, vim.g.monkeyBlameText,
|
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||||
|
blame.lineBlame(vim.api.nvim_buf_get_name(0), tonumber(row) - 1, vim.g.monkeyMailList,
|
||||||
|
vim.g.monkeyBlameText,
|
||||||
"Monkey", vim.g.monkeyBlamePosition)
|
"Monkey", vim.g.monkeyBlamePosition)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function clearBlame()
|
||||||
|
blame.clearBlame()
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setup = setup,
|
setup = setup,
|
||||||
blameLine = blameCurrentLine,
|
blameLine = blameCurrentLine,
|
||||||
blameFile = blameCurrentFile
|
blameFile = blameCurrentFile,
|
||||||
|
blameClear = clearBlame
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user