Allow use of --imply_local when calling DiffviewOpen, allowing LSP use and linting in MR review (#162)

Adds the ability to use the local filesystem when doing reviews by passing the `--imply-local` flag to the reviewer. This functionality is disabled by default. If users make changes to their filesystem (the files are "dirty") the default reviewer (hashes not files) will be use. This is a MINOR release.
This commit is contained in:
d-karl
2024-01-21 00:06:24 +01:00
committed by GitHub
parent 9b4526e54c
commit a01a3210c1
4 changed files with 38 additions and 1 deletions

View File

@@ -103,6 +103,11 @@ require("gitlab").setup({
config_path = nil, -- Custom path for `.gitlab.nvim` file, please read the "Connecting to Gitlab" section config_path = nil, -- Custom path for `.gitlab.nvim` file, please read the "Connecting to Gitlab" section
debug = { go_request = false, go_response = false }, -- Which values to log debug = { go_request = false, go_response = false }, -- Which values to log
attachment_dir = nil, -- The local directory for files (see the "summary" section) attachment_dir = nil, -- The local directory for files (see the "summary" section)
reviewer_settings = {
diffview = {
imply_local = false, -- If true, will attempt to use --imply_local option when calling |:DiffviewOpen|
},
},
help = "?", -- Opens a help popup for local keymaps when a relevant view is focused (popup, discussion panel, etc) help = "?", -- Opens a help popup for local keymaps when a relevant view is focused (popup, discussion panel, etc)
popup = { -- The popup for comment creation, editing, and replying popup = { -- The popup for comment creation, editing, and replying
exit = "<Esc>", exit = "<Esc>",

View File

@@ -136,6 +136,11 @@ you call this function with no values the defaults will be used:
config_path = nil, -- Custom path for `.gitlab.nvim` file, please read the "Connecting to Gitlab" section config_path = nil, -- Custom path for `.gitlab.nvim` file, please read the "Connecting to Gitlab" section
debug = { go_request = false, go_response = false }, -- Which values to log debug = { go_request = false, go_response = false }, -- Which values to log
attachment_dir = nil, -- The local directory for files (see the "summary" section) attachment_dir = nil, -- The local directory for files (see the "summary" section)
reviewer_settings = {
diffview = {
imply_local = false, -- If true, will attempt to use --imply_local option when calling |:DiffviewOpen|
},
},
help = "?", -- Opens a help popup for local keymaps when a relevant view is focused (popup, discussion panel, etc) help = "?", -- Opens a help popup for local keymaps when a relevant view is focused (popup, discussion panel, etc)
popup = { -- The popup for comment creation, editing, and replying popup = { -- The popup for comment creation, editing, and replying
exit = "<Esc>", exit = "<Esc>",

View File

@@ -9,6 +9,12 @@ local M = {
tabnr = nil, tabnr = nil,
} }
local all_git_manged_files_unmodified = function()
-- check local managed files are unmodified, matching the state in the MR
-- TODO: ensure correct CWD?
return vim.fn.trim(vim.fn.system({ "git", "status", "--short", "--untracked-files=no" })) == ""
end
M.open = function() M.open = function()
local diff_refs = state.INFO.diff_refs local diff_refs = state.INFO.diff_refs
if diff_refs == nil then if diff_refs == nil then
@@ -21,9 +27,25 @@ M.open = function()
return return
end end
vim.api.nvim_command(string.format("DiffviewOpen %s..%s", diff_refs.base_sha, diff_refs.head_sha)) local diffview_open_command = "DiffviewOpen"
local diffview_feature_imply_local = {
user_requested = state.settings.reviewer_settings.diffview.imply_local,
usable = all_git_manged_files_unmodified(),
}
if diffview_feature_imply_local.user_requested and diffview_feature_imply_local.usable then
diffview_open_command = diffview_open_command .. " --imply-local"
end
vim.api.nvim_command(string.format("%s %s..%s", diffview_open_command, diff_refs.base_sha, diff_refs.head_sha))
M.tabnr = vim.api.nvim_get_current_tabpage() M.tabnr = vim.api.nvim_get_current_tabpage()
if diffview_feature_imply_local.user_requested and not diffview_feature_imply_local.usable then
u.notify(
"There are uncommited changes in the working tree, cannot use 'imply_local' setting for gitlab reviews. Stash or commit all changes to use.",
vim.log.levels.WARN
)
end
if state.INFO.has_conflicts then if state.INFO.has_conflicts then
u.notify("This merge request has conflicts!", vim.log.levels.WARN) u.notify("This merge request has conflicts!", vim.log.levels.WARN)
end end

View File

@@ -13,6 +13,11 @@ M.settings = {
log_path = (vim.fn.stdpath("cache") .. "/gitlab.nvim.log"), log_path = (vim.fn.stdpath("cache") .. "/gitlab.nvim.log"),
config_path = nil, config_path = nil,
reviewer = "diffview", reviewer = "diffview",
reviewer_settings = {
diffview = {
imply_local = false,
},
},
attachment_dir = "", attachment_dir = "",
help = "?", help = "?",
popup = { popup = {