mirror of
https://github.com/iofq/nvim.nix.git
synced 2026-01-23 16:55:17 -06:00
combine diffs
This commit is contained in:
parent
a004f24728
commit
7e27221c7e
4 changed files with 87 additions and 32 deletions
|
|
@ -62,6 +62,21 @@ function M.file_history(filename)
|
|||
end
|
||||
end
|
||||
|
||||
local function confirm(picker, item)
|
||||
picker:close()
|
||||
local cmd = string.format('jj show --git -r %s', item.rev)
|
||||
local out = vim.fn.systemlist(cmd)
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, out)
|
||||
vim.bo[bufnr].bufhidden = 'wipe'
|
||||
vim.bo[bufnr].buftype = 'nofile'
|
||||
vim.bo[bufnr].filetype = 'diff'
|
||||
vim.keymap.set('n', 'q', vim.cmd.bdelete, { buffer = bufnr, noremap = true })
|
||||
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
end
|
||||
|
||||
local function get_history(f)
|
||||
local status_raw = vim.fn.system(
|
||||
'jj log --ignore-working-copy --no-graph'
|
||||
|
|
@ -85,6 +100,7 @@ function M.file_history(filename)
|
|||
title = 'jj file history for ' .. filename,
|
||||
items = get_history(filename),
|
||||
preview = preview,
|
||||
confirm = confirm,
|
||||
}
|
||||
end
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ cmd('FileType', {
|
|||
local ns = vim.api.nvim_create_namespace('nvim.difftool.hl')
|
||||
vim.api.nvim_buf_clear_namespace(event.buf, ns, 0, -1)
|
||||
for i, item in ipairs(qf) do
|
||||
local path = vim.fn.fnamemodify(item.user_data.right, ':t')
|
||||
local path = vim.fn.fnamemodify(item.user_data.right, ':.')
|
||||
local hl = 'Added'
|
||||
if
|
||||
exec('git diff --quiet -- %s', path) ~= 0
|
||||
|
|
@ -98,6 +98,45 @@ cmd('BufWinEnter', {
|
|||
vim.cmd(string.format('%dcopen', math.min(10, #items)))
|
||||
end)
|
||||
end
|
||||
|
||||
local function get_hunks(bufnr)
|
||||
local conf_start = vim.fn.search('^<<<<<<<', 'bc')
|
||||
local base_start = vim.fn.search('^|||||||', 'W')
|
||||
local base_end = vim.fn.search('^=======', 'W')
|
||||
local conf_end = vim.fn.search('^>>>>>>>', 'W')
|
||||
|
||||
local left = vim.api.nvim_buf_get_lines(bufnr, conf_start, base_start - 1, false)
|
||||
local right = vim.api.nvim_buf_get_lines(bufnr, base_end, conf_end - 1, false)
|
||||
|
||||
return {
|
||||
start = conf_start,
|
||||
stop = conf_end,
|
||||
left = left,
|
||||
right = right,
|
||||
}
|
||||
end
|
||||
|
||||
local function apply_hunk(hunks, first)
|
||||
local result = {}
|
||||
if first == -1 then -- left first
|
||||
vim.list_extend(result, hunks.left)
|
||||
vim.list_extend(result, hunks.right)
|
||||
else
|
||||
vim.list_extend(result, hunks.right)
|
||||
vim.list_extend(result, hunks.left)
|
||||
end
|
||||
|
||||
-- apply hunk in place
|
||||
vim.api.nvim_buf_set_lines(0, hunks.start - 1, hunks.stop, false, result)
|
||||
end
|
||||
|
||||
-- "combine" mappings ala vscode's merge editor
|
||||
vim.keymap.set('n', '<leader>dl', function()
|
||||
apply_hunk(get_hunks(event.buf), -1)
|
||||
end, { buffer = event.buf })
|
||||
vim.keymap.set('n', '<leader>dr', function()
|
||||
apply_hunk(get_hunks(event.buf), 1)
|
||||
end, { buffer = event.buf })
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ vim.schedule(function()
|
|||
sources = {
|
||||
default = { 'lsp', 'path', 'snippets', 'ripgrep', 'buffer' },
|
||||
providers = {
|
||||
lsp = { fallbacks = {} }, -- include buffer even when LSP is active
|
||||
lsp = { fallbacks = {}, async = true }, -- include buffer even when LSP is active
|
||||
path = { opts = { get_cwd = vim.fn.getcwd } }, -- use nvim pwd instead of current file pwd
|
||||
ripgrep = {
|
||||
module = 'blink-ripgrep',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue