-
Notifications
You must be signed in to change notification settings - Fork 1
🌈 TEST 💩 PR 🚀 😎 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
16b6beb
2d85efd
a07f67e
59e94fc
7df50ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,13 +79,12 @@ function M.load_pr_diff() | |
| local diff_content_lines = vim.split(diff_content, '\n') | ||
| construct_mappings(diff_content_lines, function() | ||
| vim.schedule(function() | ||
| vim.api.nvim_buf_set_name( | ||
| buf, | ||
| 'PR Diff: ' .. selected_pr.number .. ' (' .. os.date('%Y-%m-%d %H:%M:%S') .. ')' | ||
| ) | ||
| buf = state.try_set_buf_name(buf, 'diff', selected_pr.number) | ||
| state.diff_buffer_id = buf | ||
|
|
||
| vim.bo[buf].buftype = 'nofile' | ||
| vim.bo[buf].readonly = false | ||
| vim.bo[buf].modifiable = true | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test diff.lua line 87 |
||
|
|
||
| vim.api.nvim_buf_set_lines(buf, 0, -1, false, diff_content_lines) | ||
|
|
||
|
|
@@ -99,65 +98,43 @@ function M.load_pr_diff() | |
| vim.bo[buf].readonly = true | ||
| vim.bo[buf].modifiable = false | ||
|
|
||
| if not utils.is_empty(config.s.keymaps.diff.open_file) then | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.open_file, | ||
| '', | ||
| { desc = 'Open file', noremap = true, silent = true, callback = open_file_from_diff('edit') } | ||
| ) | ||
| end | ||
|
|
||
| if not utils.is_empty(config.s.keymaps.diff.open_file_tab) then | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.open_file_tab, | ||
| '', | ||
| { desc = 'Open file in tab', noremap = true, silent = true, callback = open_file_from_diff('tabedit') } | ||
| ) | ||
| end | ||
|
|
||
| if not utils.is_empty(config.s.keymaps.diff.open_file_split) then | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.open_file_split, | ||
| '', | ||
| { desc = 'Open file in split', noremap = true, silent = true, callback = open_file_from_diff('split') } | ||
| ) | ||
| end | ||
|
|
||
| if not utils.is_empty(config.s.keymaps.diff.open_file_vsplit) then | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.open_file_vsplit, | ||
| '', | ||
| { desc = 'Open file in vertical split', noremap = true, silent = true, callback = open_file_from_diff('vsplit') } | ||
| ) | ||
| end | ||
|
|
||
| if not utils.is_empty(config.s.keymaps.diff.approve) then | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.approve, | ||
| '', | ||
| { desc = 'Approve PR', noremap = true, silent = true, callback = pr_commands.approve_pr } | ||
| ) | ||
| end | ||
|
|
||
| if not utils.is_empty(config.s.keymaps.diff.request_changes) then | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.request_changes, | ||
| '', | ||
| { desc = 'Request PR changes', noremap = true, silent = true, callback = pr_commands.request_changes_pr } | ||
| ) | ||
| end | ||
| utils.buf_keymap(buf, 'n', config.s.keymaps.diff.open_file, 'Open file', open_file_from_diff('edit')) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test comment line 101 diff.lua
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test diff.lua line 101
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another comment on diff.lua line 101 |
||
| utils.buf_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.comment, | ||
| 'Comment on current line', | ||
| '<cmd>GuhCommentLine<cr>' | ||
| ) | ||
| utils.buf_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.open_file_tab, | ||
| 'Open file in tab', | ||
| open_file_from_diff('tabedit') | ||
| ) | ||
| utils.buf_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.open_file_split, | ||
| 'Open file in split', | ||
| open_file_from_diff('split') | ||
| ) | ||
| utils.buf_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.open_file_vsplit, | ||
| 'Open file in vertical split', | ||
| open_file_from_diff('vsplit') | ||
| ) | ||
| utils.buf_keymap(buf, 'n', config.s.keymaps.diff.approve, 'Approve PR', pr_commands.approve_pr) | ||
| utils.buf_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.diff.request_changes, | ||
| 'Request PR changes', | ||
| pr_commands.request_changes_pr | ||
| ) | ||
|
|
||
| progress('success') | ||
| progress = utils.new_progress_report('Loading diff comments') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,10 +166,12 @@ local function show_pr_info(pr_info) | |
| end | ||
|
|
||
| local buf = state.get_buf('info', pr_info.number) | ||
| vim.api.nvim_buf_set_name(buf, 'PR View: ' .. pr_info.number .. ' (' .. os.date('%Y-%m-%d %H:%M:%S') .. ')') | ||
| buf = state.try_set_buf_name(buf, 'info', pr_info.number) | ||
|
|
||
| vim.bo[buf].buftype = 'nofile' | ||
| vim.bo[buf].filetype = 'markdown' | ||
| vim.bo[buf].readonly = false | ||
| vim.bo[buf].modifiable = true | ||
|
|
||
| vim.api.nvim_buf_set_lines(buf, 0, -1, false, pr_view) | ||
|
|
||
|
|
@@ -181,52 +183,13 @@ local function show_pr_info(pr_info) | |
| vim.bo[buf].readonly = true | ||
| vim.bo[buf].modifiable = false | ||
|
|
||
| if not utils.is_empty(config.s.keymaps.pr.approve) then | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.pr.approve, | ||
| '', | ||
| { desc = 'Approve PR', noremap = true, silent = true, callback = M.approve_pr } | ||
| ) | ||
| end | ||
| if not utils.is_empty(config.s.keymaps.pr.request_changes) then | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.pr.request_changes, | ||
| '', | ||
| { desc = 'Request PR changes', noremap = true, silent = true, callback = M.request_changes_pr } | ||
| ) | ||
| end | ||
| if not utils.is_empty(config.s.keymaps.pr.merge) then | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.pr.merge, | ||
| '', | ||
| { desc = 'Merge PR in remote repo', noremap = true, silent = true, callback = M.merge_pr } | ||
| ) | ||
| end | ||
| if not utils.is_empty(config.s.keymaps.pr.comment) then | ||
| vim.api.nvim_buf_set_keymap(buf, 'n', config.s.keymaps.pr.comment, '', { | ||
| desc = 'Comment on PR', | ||
| noremap = true, | ||
| silent = true, | ||
| callback = function() | ||
| M.comment_on_pr(M.load_pr_view) | ||
| end, | ||
| }) | ||
| end | ||
| if not utils.is_empty(config.s.keymaps.pr.diff) then | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| config.s.keymaps.pr.diff, | ||
| ':GuhDiff<cr>', | ||
| { desc = 'View the PR diff', noremap = true, silent = true } | ||
| ) | ||
| end | ||
| utils.buf_keymap(buf, 'n', config.s.keymaps.pr.approve, 'Approve PR', M.approve_pr) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test comment around line 200 in pr_commands.lua |
||
| utils.buf_keymap(buf, 'n', config.s.keymaps.pr.request_changes, 'Request PR changes', M.request_changes_pr) | ||
| utils.buf_keymap(buf, 'n', config.s.keymaps.pr.merge, 'Merge PR in remote repo', M.merge_pr) | ||
| utils.buf_keymap(buf, 'n', config.s.keymaps.pr.comment, 'Comment on PR', function() | ||
| M.comment_on_pr(M.load_pr_view) | ||
| end) | ||
| utils.buf_keymap(buf, 'n', config.s.keymaps.pr.diff, 'View the PR diff', ':GuhDiff<cr>') | ||
|
|
||
| vim.bo.busy = 0 | ||
| end) | ||
|
|
@@ -238,7 +201,9 @@ local function load_pr_view_for_pr(selected_pr) | |
| return | ||
| end | ||
|
|
||
| vim.bo.busy = 1 | ||
| vim.schedule(function() | ||
| vim.bo.busy = 1 | ||
| end) | ||
| gh.get_pr_info(selected_pr.number, show_pr_info) | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,33 +11,45 @@ M.comments_list = {} | |
| --- @type integer|nil Diff view buffer id | ||
| M.diff_buffer_id = nil | ||
|
|
||
| --- @type table<string, table<number, number>> | ||
| M.filename_line_to_diff_line = {} | ||
|
|
||
| --- @type table<number, FileNameAndLinePair> | ||
| M.diff_line_to_filename_line = {} | ||
|
|
||
| --- feat+prnum => bufnr | ||
| local bufs = { | ||
| ---@type table<string, integer> | ||
| diff = { | ||
| }, | ||
| diff = {}, | ||
| ---@type table<string, integer> | ||
| info = { | ||
| }, | ||
| info = {}, | ||
| } | ||
|
|
||
| --- Gets the buf for the given PR + feature, or creates a new one if not found. | ||
| --- @param feat 'diff'|'info' | ||
| --- @param prnum string | ||
| --- @param prnum string|number | ||
| function M.get_buf(feat, prnum) | ||
| local prnumstr = tostring(prnum) | ||
| local b = bufs[feat][prnumstr] | ||
| if type(b) ~= 'number' or vim.api.nvim_buf_is_valid(b) then | ||
| b = vim.api.nvim_create_buf(false, true) | ||
| b = vim.api.nvim_create_buf(true, true) | ||
| bufs[feat][prnumstr] = b | ||
| assert(type(b) == 'number') | ||
| end | ||
| return b | ||
| end | ||
|
|
||
| function M.try_set_buf_name(buf, feat, prnum) | ||
| local bufname = ('guh://%s/%s'):format(feat, prnum) | ||
| local foundbuf = vim.fn.bufnr(bufname) | ||
| if foundbuf > 0 and buf ~= foundbuf then | ||
| vim.api.nvim_set_current_buf(foundbuf) | ||
| -- XXX fucking hack because Vim creates new buffer after (re)naming it. | ||
| bufs[feat][tostring(prnum)] = foundbuf | ||
| return foundbuf | ||
| end | ||
| -- if not vim.api.nvim_buf_get_name(buf):match('guh%:') then | ||
| vim.api.nvim_buf_set_name(buf, ('guh://%s/%s'):format(feat, prnum)) | ||
| -- XXX fucking hack because Vim creates new buffer after (re)naming it. | ||
| bufs[feat][tostring(prnum)] = buf | ||
| return buf | ||
| -- end | ||
| end | ||
|
Comment on lines
+47
to
+51
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test comment state.lua lines 47-51 code sample: print('') |
||
|
|
||
| M.bufs = bufs | ||
|
|
||
| return M | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,17 @@ function M.new_progress_report(action) | |
| end) | ||
| end | ||
|
|
||
| function M.buf_keymap(buf, mode, lhs, desc, rhs) | ||
| if not M.is_empty(lhs) then | ||
| local opts = {} | ||
| opts.desc = opts.desc == nil and desc or opts.desc | ||
| opts.noremap = opts.noremap == nil and true or opts.noremap | ||
| opts.silent = opts.silent == nil and true or opts.silent | ||
| opts.buffer = buf | ||
| vim.keymap.set(mode, lhs, rhs, opts) | ||
| end | ||
| end | ||
|
|
||
| function M.get_comment(buf_name, split_command, prompt, content, key_binding, callback) | ||
| local buf = vim.api.nvim_create_buf(false, true) | ||
| vim.api.nvim_buf_set_name(buf, buf_name) | ||
|
|
@@ -105,20 +116,8 @@ function M.get_comment(buf_name, split_command, prompt, content, key_binding, ca | |
| callback(input) | ||
| end | ||
|
|
||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'n', | ||
| key_binding, | ||
| '', | ||
| { noremap = true, silent = true, callback = capture_input_and_close } | ||
| ) | ||
| vim.api.nvim_buf_set_keymap( | ||
| buf, | ||
| 'i', | ||
| key_binding, | ||
| '', | ||
| { noremap = true, silent = true, callback = capture_input_and_close } | ||
| ) | ||
| M.buf_keymap(buf, 'n', key_binding, '', capture_input_and_close) | ||
| M.buf_keymap(buf, 'i', key_binding, '', capture_input_and_close) | ||
|
Comment on lines
+119
to
+120
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test comment utils.lua |
||
| end | ||
|
|
||
| return M | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| require('guh').setup{} | ||
| require('guh').setup({}) |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test diff.lua line 82