From 6b7e67b3250d49a312fcb1cdaad34dd7052583f1 Mon Sep 17 00:00:00 2001 From: "Harrison (Harry) Cramer" <32515581+harrisoncramer@users.noreply.github.com> Date: Tue, 31 Oct 2023 18:46:18 -0400 Subject: [PATCH] Fixes #71 (#75) This MR fixes the check for The `diffview` reviewer. Rather than checking for the presence of the command, we check for the module itself. --- README.md | 7 ++++--- lua/gitlab/utils/init.lua | 17 ++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 97b64afc..b6ca227e 100644 --- a/README.md +++ b/README.md @@ -158,12 +158,13 @@ The upper part of the popup contains the title, which can also be edited and sen ### Reviewing Diffs -The `review` action will open a diff of the changes. You can leave comments using the `create_comment` action or for multiline comments use `create_multiline_comment` in visual mode. +The `review` action will open a diff of the changes. You can leave comments using the `create_comment` action. In visual mode, add multiline comments with the `create_multiline_comment` command, and add suggested changes with the `create_comment_suggestion` command. ```lua require("gitlab").review() require("gitlab").create_comment() -require("gitlab").create_multiline_comment() +require("gitlab").create_multiline_comment() -- Only supported for diffview reviewer +require("gitlab").create_comment_suggestion() -- Only supported for diffview reviewer ``` For suggesting changes you can use `create_comment_suggestion` in visual mode which works similar to `create_multiline_comment` but prefills the comment window with gitlab [suggest changes](https://docs.gitlab.com/ee/user/project/merge_requests/reviews/suggestions.html) code block with prefilled code from visual selection. @@ -267,7 +268,7 @@ vim.keymap.set("n", "glo", gitlab.open_in_browser) This plugin uses a Golang server to reach out to Gitlab. It's possible that something is going wrong when starting that server or connecting with Gitlab. The Golang server runs outside of Neovim, and can be interacted with directly in order to troubleshoot. To start the server, check out your feature branch and run these commands: -``` +```lua :lua require("gitlab.server").build(true) :lua require("gitlab.server").start(function() print("Server started") end) ``` diff --git a/lua/gitlab/utils/init.lua b/lua/gitlab/utils/init.lua index a750745a..8fbc4dfe 100644 --- a/lua/gitlab/utils/init.lua +++ b/lua/gitlab/utils/init.lua @@ -6,18 +6,17 @@ M.get_current_line_number = function() end M.has_reviewer = function(reviewer) - local has_reviewer if reviewer == "diffview" then - has_reviewer = vim.fn.exists(":DiffviewOpen") ~= 0 + local diffview_ok, _ = pcall(require, "diffview") + if not diffview_ok then + error("Please install diffview or change your reviewer") + end else - has_reviewer = vim.fn.executable("delta") == 1 - end - - if not has_reviewer then - error(string.format("Please install %s or change your reviewer", reviewer)) + local has_reviewer = vim.fn.executable("delta") == 1 + if not has_reviewer then + error(string.format("Please install delta or change your reviewer", reviewer)) + end end - - return has_reviewer end M.is_windows = function()