Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
3bad682
Fix: Jumping to renamed files (#484)
jakubbortlik Mar 1, 2025
870b55d
Fix: Store reviewer data before creating comment popup (#476)
jakubbortlik Mar 1, 2025
1cbd7ec
Fix: Make publishing drafts more robust (#483)
jakubbortlik Mar 1, 2025
4fc1bbd
Fix: Swap file_name and old_file_name in reviewer data (#485)
jakubbortlik Apr 9, 2025
aac1ebc
Feat: Enable toggling date format between relative and absolute (#491)
jakubbortlik Jun 19, 2025
cd06875
Fix: Add opts to help popup (#492)
jakubbortlik Jun 19, 2025
a4b9859
Fix: Force start_line for jumping to diagnostic to be inside buffer (…
jakubbortlik Jun 19, 2025
f5fbab4
fix: redefine colors after reloading colorscheme (#500)
jakubbortlik Jun 19, 2025
e9141cf
Fix: Use path instead of oldpath as fallback for unrenamed files (#496)
jakubbortlik Jun 19, 2025
72af0d0
Fix: Use file_name when old_file_name is not set (#495)
jakubbortlik Jun 19, 2025
25aada3
fix(ci): fix lua tests (#501)
harrisoncramer Jun 19, 2025
b12236f
Proxy Support (#499)
duckbrain Jun 25, 2025
f66fbdb
feat(ci): Cancel obsolete after a new commit is pushed in an open PR …
kitsiosk Jul 12, 2025
9c2265f
feat: add first draft of suggestion preview
jakubbortlik May 30, 2025
a2b7651
fix: don't attempt placing diagnostics on diffview NULL buffer
jakubbortlik May 30, 2025
09314cf
docs: mark parameter as optional
jakubbortlik May 30, 2025
214068a
fix: go to note in existing tab
jakubbortlik May 30, 2025
17a69d7
refactor: don't use plain tabnew as it creates empty buffer
jakubbortlik May 31, 2025
6049705
refactor: make functions local
jakubbortlik May 31, 2025
3cbdf51
docs: add some docstrings
jakubbortlik May 31, 2025
282899f
fix: add base_sha to draft comments
jakubbortlik Jun 2, 2025
9547446
fix: use old path when comment is on OLD_SHA
jakubbortlik Jun 2, 2025
5b11f20
docs: add TODO
jakubbortlik Jun 2, 2025
6d9f83a
docs: update comment
jakubbortlik Jun 2, 2025
394d5f7
fix: improve checking whether local file should be used for suggestions
jakubbortlik Jun 2, 2025
f056e0c
refactor: simplify imply_local usage
jakubbortlik Jun 3, 2025
bc3ee7f
docs: update docs
jakubbortlik Jun 3, 2025
b586f1b
feat: enable updating suggestion comments from the preview
jakubbortlik Jun 3, 2025
478baa4
refactor: move more keymap definitions to set_keymaps function
jakubbortlik Jun 3, 2025
844fffa
style: format file
jakubbortlik Jun 3, 2025
01dcfc0
refactor: create autocommands in a separate function
jakubbortlik Jun 4, 2025
9e1bdf5
fix: make note buffer nomodified when discarding changes
jakubbortlik Jun 4, 2025
69b884a
fix: validate buffer number before accessing it
jakubbortlik Jun 5, 2025
c14ea7e
fix: split horizontally on narrow screen
jakubbortlik Jun 5, 2025
3d41624
fix: move virtual lines left (and up)
jakubbortlik Jun 5, 2025
f02c608
refactor: pass only tree to show_preview()
jakubbortlik Jun 5, 2025
02e3522
fix: check if suggestion preview already exists for given note
jakubbortlik Jun 6, 2025
078236f
docs: update function annotations
jakubbortlik Jun 6, 2025
db0ef39
refactor: add full text to suggestions
jakubbortlik Jun 6, 2025
5734b10
fix: make imply_local local
jakubbortlik Jun 6, 2025
926ae2e
feat: edit suggestions for comments without suggestions
jakubbortlik Jun 7, 2025
10e1467
refactor: determine imply_local in separate function
jakubbortlik Jun 7, 2025
833c741
fix: prevent error when there are multiple endquotes without a corres…
jakubbortlik Jun 7, 2025
33e0b02
refactor: get original lines in seprate function
jakubbortlik Jun 7, 2025
a661059
fix: show error when suggestion start is before first line of file
jakubbortlik Jun 7, 2025
5b38506
fix: convert string to number when editing root node
jakubbortlik Jun 7, 2025
2475ce3
refactor rename preview suggestion to edit suggestion
jakubbortlik Jun 7, 2025
3c48880
fix: unify keymap setting pattern with popups
jakubbortlik Jun 7, 2025
3992cef
docs: remove outdated comment
jakubbortlik Jun 7, 2025
5d8f792
feat: add keymap for pasting default suggestion
jakubbortlik Jun 7, 2025
6fccdbf
fix: update suggestions on CursorMoved and CursorMovedI
jakubbortlik Jun 7, 2025
17cc275
docs: update comment about winbar
jakubbortlik Jun 7, 2025
fba0395
docs: add TODOs
jakubbortlik Jun 8, 2025
98f692f
feat: enable replying to comments in the suggestion preview
jakubbortlik Jun 9, 2025
21bde2d
feat: show draft mode in note header
jakubbortlik Jun 9, 2025
7bb39ac
fix: enable updating draft replies
jakubbortlik Jun 9, 2025
0add185
feat: add possibility to create suggestions with preview from the rev…
jakubbortlik Jun 10, 2025
63306b5
docs: fix info about using feature branch
jakubbortlik Jun 11, 2025
79c8caf
docs: use simpler info messages
jakubbortlik Jun 13, 2025
3795201
fix: check is_reply first
jakubbortlik Jun 13, 2025
983eb59
refactor: simplify variable names
jakubbortlik Jun 13, 2025
3f778f0
refactor: use ShowPreviewOpts
jakubbortlik Jun 13, 2025
6ed9e3f
feat: add mapping for previewing suggestion with head_sha revision
jakubbortlik Jun 18, 2025
9dbc478
fix: add head_sha to root_node of draft notes
jakubbortlik Jun 20, 2025
13a9fd2
feat: replace extmarks by winbar
jakubbortlik Jun 20, 2025
1ad7e7d
feat: add winbar to suggestion window
jakubbortlik Jun 20, 2025
3813732
feat: add winbar to orignial buffer
jakubbortlik Jun 20, 2025
8264286
style: apply stylua
jakubbortlik Jun 20, 2025
821791f
fix: refresh LSP diagnostics in suggestion buffer hen settings buffer…
jakubbortlik Jul 11, 2025
8e487a8
docs: make error message more informative
jakubbortlik Jul 11, 2025
6a68922
docs: add note why changing modified option
jakubbortlik Jul 11, 2025
675bc54
fix: reset suggestion buffer before closing
jakubbortlik Jul 11, 2025
97be236
style: apply stylua
jakubbortlik Jul 11, 2025
9f67c58
fix: automatically choose head_sha if file has changed
jakubbortlik Jul 12, 2025
b753bb1
fix: remove unnecessary check
jakubbortlik Jul 12, 2025
8120680
fix: don't reset temporary suggestion buffer before closing preview
jakubbortlik Jul 12, 2025
2964a00
fix: recompute folds in suggestion buffer on TextChangedI
jakubbortlik Jul 12, 2025
01d1e23
docs: improve messages to user
jakubbortlik Jul 14, 2025
0b1c55b
refactor: rename var
jakubbortlik Jul 14, 2025
2b27933
feat: add ability to apply suggestion to local file
jakubbortlik Jul 15, 2025
53c3bb3
docs: use better mapping description
jakubbortlik Jul 17, 2025
e9cbed1
docs: add help keymap
jakubbortlik Jul 17, 2025
2136a0e
fix: use mappings in all preview windows
jakubbortlik Jul 17, 2025
e2872e4
feat: add attach_file keybinding
jakubbortlik Jul 17, 2025
cceebc8
fix: don't create directories for temp files
jakubbortlik Jul 17, 2025
ef7da2e
docs: fix keybinding
jakubbortlik Aug 6, 2025
3dec6ee
docs: add keybinding description
jakubbortlik Aug 6, 2025
e6931e0
fix: don't update suggestion buffer if the text doesn't change
jakubbortlik Sep 23, 2025
efdf5b7
refactor: simplify checking if suggestion has changed
jakubbortlik Sep 23, 2025
7f4f61f
feat: apply suggestion with new commit and resolve thread
jakubbortlik Oct 6, 2025
8ac996e
fix: add check that there are no staged changes
jakubbortlik Oct 6, 2025
feed65f
docs: improve suggestion keymaps descriptions
jakubbortlik Oct 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
- 'cmd/**' # Ignore changes to the Lua code
- 'go.sum'
- 'go.mod'

concurrency:
group: pr-${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
go_lint:
name: Lint Go 💅
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/lua.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ jobs:
with:
neovim: true
version: ${{ matrix.nvim_version }}
- name: Install luajit
uses: leafo/gh-actions-lua@v10
- uses: leafo/gh-actions-lua@v11
with:
luaVersion: "luajit-openresty"
- name: Install luarocks
uses: leafo/gh-actions-luarocks@v4
- uses: hishamhm/gh-actions-luarocks@master
with:
luaRocksVersion: "3.12.0"
- name: build
run: |
luarocks install busted
- name: Run tests
shell: bash
run: |
Expand Down
5 changes: 3 additions & 2 deletions after/syntax/gitlab.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ endif
let expanders = '^\s*\%(' . g:gitlab_discussion_tree_expander_open . '\|' . g:gitlab_discussion_tree_expander_closed . '\)'
let username = '@[a-zA-Z0-9.]\+'

" Covers times like '14 days ago', 'just now', as well as 'October 3, 2024'
" Covers times like '14 days ago', 'just now', as well as 'October 3, 2024', and '02/28/2025 at 00:50'
let time_ago = '\d\+ \w\+ ago'
let formatted_date = '\w\+ \{1,2}\d\{1,2}, \d\{4}'
let date = '\%(' . time_ago . '\|' . formatted_date . '\|just now\)'
let absolute_time = '\d\{2}/\d\{2}/\d\{4} at \d\{2}:\d\{2}'
let date = '\%(' . time_ago . '\|' . formatted_date . '\|' . absolute_time . '\|just now\)'

let published = date . ' \%(' . g:gitlab_discussion_tree_resolved . '\|' . g:gitlab_discussion_tree_unresolved . '\|' . g:gitlab_discussion_tree_unlinked . '\)\?'
let state = ' \%(' . published . '\|' . g:gitlab_discussion_tree_draft . '\)'
Expand Down
15 changes: 12 additions & 3 deletions cmd/app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net/http"
"net/url"

"github.com/harrisoncramer/gitlab.nvim/cmd/app/git"
"github.com/hashicorp/go-retryablehttp"
Expand Down Expand Up @@ -66,10 +67,18 @@ func NewClient() (*Client, error) {
},
}

if proxy := pluginOptions.ConnectionSettings.Proxy; proxy != "" {
u, err := url.Parse(proxy)
if err != nil {
return nil, fmt.Errorf("parse proxy url: %w", err)
}
tr.Proxy = http.ProxyURL(u)
}

retryClient := retryablehttp.NewClient()
retryClient.HTTPClient.Transport = tr
retryClient.RetryMax = 0
gitlabOptions = append(gitlabOptions, gitlab.WithHTTPClient(retryClient.HTTPClient))
gitlabOptions = append(gitlabOptions, gitlab.WithoutRetries())

client, err := gitlab.NewClient(pluginOptions.AuthToken, gitlabOptions...)

Expand Down Expand Up @@ -99,11 +108,11 @@ func InitProjectSettings(c *Client, gitInfo git.GitData) (*ProjectInfo, error) {
project, _, err := c.GetProject(gitInfo.ProjectPath(), &opt)

if err != nil {
return nil, fmt.Errorf(fmt.Sprintf("Error getting project at %s", gitInfo.RemoteUrl), err)
return nil, fmt.Errorf("error getting project at %s: %w", gitInfo.RemoteUrl, err)
}

if project == nil {
return nil, fmt.Errorf(fmt.Sprintf("Could not find project at %s", gitInfo.RemoteUrl), err)
return nil, fmt.Errorf("could not find project at %s", gitInfo.RemoteUrl)
}

projectId := fmt.Sprint(project.ID)
Expand Down
8 changes: 7 additions & 1 deletion cmd/app/comment_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ type RequestWithPosition interface {
func buildCommentPosition(commentWithPositionData RequestWithPosition) *gitlab.PositionOptions {
positionData := commentWithPositionData.GetPositionData()

// If the file has been renamed, then this is a relevant part of the payload
oldFileName := positionData.OldFileName
if oldFileName == "" {
oldFileName = positionData.FileName
}

opt := &gitlab.PositionOptions{
PositionType: &positionData.Type,
StartSHA: &positionData.StartCommitSHA,
HeadSHA: &positionData.HeadCommitSHA,
BaseSHA: &positionData.BaseCommitSHA,
NewPath: &positionData.FileName,
OldPath: &positionData.OldFileName,
OldPath: &oldFileName,
NewLine: positionData.NewLine,
OldLine: positionData.OldLine,
}
Expand Down
1 change: 1 addition & 0 deletions cmd/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type PluginOptions struct {
} `json:"debug"`
ChosenMrIID int `json:"chosen_mr_iid"`
ConnectionSettings struct {
Proxy string `json:"proxy"`
Insecure bool `json:"insecure"`
Remote string `json:"remote"`
} `json:"connection_settings"`
Expand Down
22 changes: 19 additions & 3 deletions doc/gitlab.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ you call this function with no values the defaults will be used:
},
},
connection_settings = {
proxy = "", -- Configure a proxy URL to use when connecting to GitLab. Supports URL schemes: http, https, socks5
insecure = false, -- Like curl's --insecure option, ignore bad x509 certificates on connection
remote = "origin", -- The default remote that your MRs target
},
Expand Down Expand Up @@ -213,6 +214,7 @@ you call this function with no values the defaults will be used:
switch_view = "c", -- Toggle between the notes and discussions views
toggle_tree_type = "i", -- Toggle type of discussion tree - "simple", or "by_file_name"
publish_draft = "P", -- Publish the currently focused note/comment
toggle_date_format = "dt", -- Toggle between date formats: relative (e.g., "5 days ago", "just now", "October 13, 2024" for dates more than a month ago) and absolute (e.g., "03/01/2024 at 11:43")
toggle_draft_mode = "D", -- Toggle between draft mode (comments posted as drafts) and live mode (comments are posted immediately)
toggle_sort_method = "st", -- Toggle whether discussions are sorted by the "latest_reply", or by "original_comment", see `:h gitlab.nvim.toggle_sort_method`
toggle_node = "t", -- Open or close the discussion
Expand All @@ -221,11 +223,22 @@ you call this function with no values the defaults will be used:
toggle_unresolved_discussions = "U", -- Open or close all unresolved discussions
refresh_data = "<C-R>", -- Refresh the data in the view by hitting Gitlab's APIs again
print_node = "<leader>p", -- Print the current node (for debugging)
edit_suggestion = "se", -- Edit comment with suggestion preview in a new tab
reply_with_suggestion = "sr", -- Reply to comment with a suggestion preview in a new tab
apply_suggestion = "sa", -- Apply the suggestion to the local file with a preview in a new tab
},
suggestion_preview = {
apply_changes = "ZZ", -- Close suggestion preview tab, and post comment to Gitlab (discarding changes to local file). In "apply mode", accept suggestion, commit changes, then push to remote and resolve thread
discard_changes = "ZQ", -- Close suggestion preview tab and discard changes in local file
attach_file = "ZA", -- Attach a file from the `settings.attachment_dir`
apply_changes_locally = "Zz", -- Only in "apply mode", close suggestion preview tab and write suggestion buffer to local file (no changes posted to Gitlab)
paste_default_suggestion = "glS", -- Paste the default suggestion below the cursor (overrides default "glS" (start review) keybinding for the "Note" buffer)
},
reviewer = {
disable_all = false, -- Disable all default mappings for the reviewer windows
create_comment = "c", -- Create a comment for the lines that the following {motion} moves over. Repeat the key(s) for creating comment for the current line
create_suggestion = "s", -- Create a suggestion for the lines that the following {motion} moves over. Repeat the key(s) for creating comment for the current line
create_suggestion_with_preview = "S", -- In a new tab create a suggestion with a diff preview for the lines that the following {motion} moves over. Repeat the key(s) for creating comment for the current line
move_to_discussion_tree = "a", -- Jump to the comment in the discussion tree
},
},
Expand Down Expand Up @@ -267,6 +280,7 @@ you call this function with no values the defaults will be used:
draft = "✎", -- Symbol to show next to draft comments/notes
tree_type = "simple", -- Type of discussion tree - "simple" means just list of discussions, "by_file_name" means file tree with discussions under file
draft_mode = false, -- Whether comments are posted as drafts as part of a review
relative_date = true, -- Whether to show relative time like "5 days ago" or absolute time like "03/01/2025 at 01:43"
winbar = nil, -- Custom function to return winbar title, should return a string. Provided with WinbarTable (defined in annotations.lua)
-- If using lualine, please add "gitlab" to disabled file types, otherwise you will not see the winbar.
},
Expand Down Expand Up @@ -536,9 +550,11 @@ emojis that you have responded with.
UPLOADING FILES *gitlab.nvim.uploading-files*

To attach a file to an MR description, reply, comment, and so forth use the
`keymaps.popup.perform_linewise_action` keybinding when the popup is open.
This will open a picker that will look for files in the directory you specify
in the `settings.attachment_dir` folder (this must be an absolute path).
`keymaps.popup.perform_linewise_action` keybinding when the popup is open (or
the `keymaps.suggestion_preview.attach_file` in the comment buffer of the
suggestion preview). This will open a picker that will look for files in the
directory you specify in the `settings.attachment_dir` folder (this must be an
absolute path).

When you have picked the file, it will be added to the current buffer at the
current line.
Expand Down
65 changes: 25 additions & 40 deletions lua-test.sh
Original file line number Diff line number Diff line change
@@ -1,59 +1,44 @@
#!/usr/bin/env bash
#
# Setup and run tests for lua part of gitlab.nvim.
#
# In order to run tests you need to have `luarocks` and `git` installed. This script will check if
# environment is already setup, if not it will initialize current directory with `luarocks`,
# install `busted` framework and download plugin dependencies.
#
# Requires `luarocks`, `git`, and `nvim` installed.
#
set -e

LUA_VERSION="5.1"
set -euo pipefail

PLUGINS_FOLDER="tests/plugins"
PLUGINS=(
"https://github.com/MunifTanjim/nui.nvim"
"https://github.com/nvim-lua/plenary.nvim"
"https://github.com/sindrets/diffview.nvim"
"https://github.com/MunifTanjim/nui.nvim"
"https://github.com/nvim-lua/plenary.nvim"
"https://github.com/sindrets/diffview.nvim"
)

if ! command -v luarocks > /dev/null 2>&1; then
echo "You need to have luarocks installed in order to run tests."
exit 1
fi

if ! command -v git > /dev/null 2>&1; then
echo "You need to have git installed in order to run tests."
exit 1
if ! command -v luarocks >/dev/null 2>&1; then
echo "Error: luarocks not found. Please install LuaRocks." >&2
exit 1
fi

if ! luarocks --lua-version=$LUA_VERSION which busted > /dev/null 2>&1; then
echo "Installing busted."
luarocks init
luarocks config --scope project lua_version "$LUA_VERSION"
luarocks install --lua-version="$LUA_VERSION" busted
if ! command -v git >/dev/null 2>&1; then
echo "Error: git not found. Please install Git." >&2
exit 1
fi

for arg in "$@"; do
if [[ $arg =~ "--coverage" ]] && ! luarocks --lua-version=$LUA_VERSION which luacov > /dev/null 2>&1; then
luarocks install --lua-version="$LUA_VERSION" luacov
# lcov reporter for luacov - lcov format is supported by `nvim-coverage`
luarocks install --lua-version="$LUA_VERSION" luacov-reporter-lcov
if ! command -v nvim >/dev/null 2>&1; then
echo "Error: nvim not found. Please install Neovim." >&2
exit 1
fi
done

# Clone test plugin dependencies
mkdir -p "$PLUGINS_FOLDER"
for plugin in "${PLUGINS[@]}"; do
plugin_name=${plugin##*/}
plugin_folder="$PLUGINS_FOLDER/$plugin_name"

# Check if plugin was already downloaded
if [[ -d "$plugin_folder/.git" ]]; then
# We could also try to pull here but I am not sure if that wouldn't slow down tests too much.
continue
fi

plugin_name="${plugin##*/}"
plugin_folder="$PLUGINS_FOLDER/$plugin_name"
if [[ ! -d "$plugin_folder/.git" ]]; then
echo "Cloning $plugin..."
git clone --depth 1 "$plugin" "$plugin_folder"

fi
done

nvim -u NONE -U NONE -N -i NONE -l tests/init.lua "$@"
# Run tests
echo "Running tests with Neovim..."
nvim -u NONE -U NONE -N -i NONE -l tests/init.lua "$@"
48 changes: 41 additions & 7 deletions lua/gitlab/actions/comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@ local M = {
comment_popup = nil,
}

---Decide if the comment is a draft based on the draft popup field.
---@return boolean|nil is_draft True if the draft popup exists and the string it contains converts to `true`.
local get_draft_value_from_popup = function()
local buf_is_valid = M.draft_popup and M.draft_popup.bufnr and vim.api.nvim_buf_is_valid(M.draft_popup.bufnr)
return buf_is_valid and u.string_to_bool(u.get_buffer_text(M.draft_popup.bufnr))
end

---Fires the API that sends the comment data to the Go server, called when you "confirm" creation
---via the M.settings.keymaps.popup.perform_action keybinding
---@param text string comment text
---@param unlinked boolean if true, the comment is not linked to a line
---@param discussion_id string | nil The ID of the discussion to which the reply is responding, nil if not a reply
local confirm_create_comment = function(text, unlinked, discussion_id)
M.confirm_create_comment = function(text, unlinked, discussion_id)
if text == nil then
u.notify("Reviewer did not provide text of change", vim.log.levels.ERROR)
return
end

local is_draft = M.draft_popup and u.string_to_bool(u.get_buffer_text(M.draft_popup.bufnr))
local is_draft = get_draft_value_from_popup() or state.settings.discussion_tree.draft_mode

-- Creating a normal reply to a discussion
if discussion_id ~= nil and not is_draft then
Expand Down Expand Up @@ -153,9 +160,9 @@ M.create_comment_layout = function(opts)
title = "Note"
user_settings = popup_settings.note
else
-- TODO: investigate why `old_file_name` is in fact the new name for renamed files!
local file_name = M.location.reviewer_data.old_file_name ~= "" and M.location.reviewer_data.old_file_name
or M.location.reviewer_data.file_name
local file_name = (M.location.reviewer_data.new_sha_focused or M.location.reviewer_data.old_file_name == "")
and M.location.reviewer_data.file_name
or M.location.reviewer_data.old_file_name
title =
popup.create_title("Comment", file_name, M.location.visual_range.start_line, M.location.visual_range.end_line)
user_settings = popup_settings.comment
Expand Down Expand Up @@ -188,13 +195,13 @@ M.create_comment_layout = function(opts)
---Keybinding for focus on draft section
popup.set_popup_keymaps(M.draft_popup, function()
local text = u.get_buffer_text(M.comment_popup.bufnr)
confirm_create_comment(text, unlinked, opts.discussion_id)
M.confirm_create_comment(text, unlinked, opts.discussion_id)
vim.api.nvim_set_current_win(current_win)
end, miscellaneous.toggle_bool, popup.non_editable_popup_opts)

---Keybinding for focus on text section
popup.set_popup_keymaps(M.comment_popup, function(text)
confirm_create_comment(text, unlinked, opts.discussion_id)
M.confirm_create_comment(text, unlinked, opts.discussion_id)
vim.api.nvim_set_current_win(current_win)
end, miscellaneous.attach_file, popup.editable_popup_opts)

Expand Down Expand Up @@ -295,6 +302,33 @@ M.create_comment_suggestion = function()
end)
end

--- This function will create a new tab with a suggestion preview for the changed/updated line in
--- the current MR.
M.create_comment_with_suggestion = function()
M.location = Location.new()
if not M.can_create_comment(true) then
u.press_escape()
return
end

local old_file_name = M.location.reviewer_data.old_file_name ~= "" and M.location.reviewer_data.old_file_name
or M.location.reviewer_data.file_name
local is_new_sha = M.location.reviewer_data.new_sha_focused

---@type ShowPreviewOpts
local opts = {
old_file_name = old_file_name,
new_file_name = M.location.reviewer_data.file_name,
start_line = M.location.visual_range.start_line,
end_line = M.location.visual_range.end_line,
is_new_sha = is_new_sha,
revision = is_new_sha and "HEAD" or require("gitlab.state").INFO.target_branch,
note_header = "comment",
comment_type = "new",
}
require("gitlab.actions.suggestions").show_preview(opts)
end

---Returns true if it's possible to create an Inline Comment
---@param must_be_visual boolean True if current mode must be visual
---@return boolean
Expand Down
Loading
Loading