refactor: start pulling out the prr config into a plugin

All the prr code review stuff will be in its own plugin soon. There are
some sweet features coming with a treesitter parser for syntax
highlighting.
This commit is contained in:
Ade Attwood 2024-04-10 19:03:41 +01:00
parent 6dc809f985
commit 2f6e30fb53
2 changed files with 0 additions and 56 deletions

View file

@ -1,31 +0,0 @@
"
" function for the `foldexpr` to fold git diffs and hunks
"
" Inspired from https://github.com/sgeb/vim-diff-fold
"
function! s:fold_diff_hunk()
let l:line=getline(v:lnum)
if l:line =~# '^> \(diff\|Index\)'
return '>1'
elseif l:line =~# '^> \(@@\|\d\)'
return '>2'
elseif l:line =~# '^> \*\*\* \d\+,\d\+ \*\*\*\*$'
return '>2'
elseif l:line =~# '^> --- \d\+,\d\+ ----$'
return '>2'
else
return '='
endif
endfunction
setlocal foldenable
setlocal nomodeline formatoptions-=croq formatoptions+=tl
setlocal foldmethod=expr
setlocal foldexpr=s:fold_diff_hunk()
setlocal foldlevel=99
" Add "go to definition" mapping for prr lines. This will allow you to go to
" the line of code when reviewing a pull request. Seeing the code in full
" context is really helpful when reviewing.
noremap <silent> gd :PrrGoToLine<cr>

View file

@ -1,25 +0,0 @@
vim.api.nvim_create_user_command("PrrGoToLine", function()
local content = vim.api.nvim_buf_get_lines(0, 0, -1, false)
local line, column = unpack(vim.api.nvim_win_get_cursor(0))
local target_file = ""
local target_line = 0
for i = 1, line do
local line_content = content[i]
local file_match = line_content:match "> diff .* b/(.*)"
if file_match ~= nil then
target_file = file_match
end
local line_match = line_content:match "+(%d+)"
if line_match ~= nil then
target_line = line_match
elseif line_content:match "> (-).*" == nil then
target_line = target_line + 1
end
end
vim.cmd("e " .. target_file)
vim.fn.cursor(target_line - 1, column)
end, { bang = true, desc = "Open the current file at the poin in a prr buffer" })