-
Notifications
You must be signed in to change notification settings - Fork 47
Draft: Feat: Add suggestions functionality #504
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
Open
jakubbortlik
wants to merge
74
commits into
harrisoncramer:develop
Choose a base branch
from
jakubbortlik:feat-add-suggestions-functionality
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Draft: Feat: Add suggestions functionality #504
jakubbortlik
wants to merge
74
commits into
harrisoncramer:develop
from
jakubbortlik:feat-add-suggestions-functionality
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ponding start_quote
jakubbortlik
commented
Aug 7, 2025
Comment on lines
+623
to
+668
vim.api.nvim_cmd({ cmd = "tabnew", args = { original_buf_name } }, {}) | ||
local original_buf = vim.api.nvim_get_current_buf() | ||
local original_winid = vim.api.nvim_get_current_win() | ||
vim.api.nvim_buf_set_lines(original_buf, 0, -1, false, original_lines) | ||
vim.bo.bufhidden = "wipe" | ||
vim.bo.buflisted = false | ||
vim.bo.buftype = "nofile" | ||
vim.bo.modifiable = false | ||
vim.cmd.filetype("detect") | ||
local buf_filetype = vim.api.nvim_get_option_value("filetype", { buf = 0 }) | ||
|
||
local imply_local = determine_imply_local(opts) | ||
|
||
-- Create the suggestion buffer and show a diff with the original version | ||
local split_cmd = vim.o.columns > 240 and "vsplit" or "split" | ||
if imply_local then | ||
vim.api.nvim_cmd({ cmd = split_cmd, args = { opts.new_file_name } }, {}) | ||
else | ||
local sug_buf_name = get_temp_file_name("SUGGESTION", opts.note_node_id or "NEW_COMMENT", commented_file_name) | ||
vim.api.nvim_cmd({ cmd = split_cmd, args = { sug_buf_name } }, {}) | ||
vim.bo.bufhidden = "wipe" | ||
vim.bo.buflisted = false | ||
vim.bo.buftype = "nofile" | ||
vim.bo.filetype = buf_filetype | ||
end | ||
local suggestion_buf = vim.api.nvim_get_current_buf() | ||
local suggestion_winid = vim.api.nvim_get_current_win() | ||
set_buffer_lines(suggestion_buf, suggestions[1].full_text, imply_local) | ||
vim.cmd("1,2windo diffthis") | ||
|
||
-- Backup the suggestion buffer winbar to reset it when suggestion preview is closed. Despite the | ||
-- option being "window-local", it's carried over to the buffer even after closing the preview. | ||
-- See https://github.com/neovim/neovim/issues/11525 | ||
local suggestion_winbar = vim.api.nvim_get_option_value("winbar", { scope = "local", win = suggestion_winid }) | ||
|
||
-- Create the note window | ||
local note_buf = vim.api.nvim_create_buf(false, false) | ||
local note_winid = vim.fn.win_getid(3) | ||
local note_bufname = vim.fn.tempname() | ||
vim.api.nvim_buf_set_name(note_buf, note_bufname) | ||
vim.api.nvim_cmd({ cmd = "vnew", mods = { split = "botright" }, args = { note_bufname } }, {}) | ||
vim.api.nvim_buf_set_lines(note_buf, 0, -1, false, note_lines) | ||
vim.bo.bufhidden = "wipe" | ||
vim.bo.buflisted = false | ||
vim.bo.filetype = "markdown" | ||
vim.bo.modified = false |
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.
This part is pretty ugly and the buffer/tab/split creation should probably be handled in a cleaner and simpler way. Possibly by using something like Nui.Split.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @harrisoncramer, in this rather large PR, I would like to introduce suggestions functionality in the discussion tree and in the reviewer:
The suggestion preview has some useful features:
I've tried to make it so that the suggestion is previewed on the local file in as many cases as possible so the user can make use of LSP, running tests with the suggestion applied, etc.
Documentation in
doc/gitlab.nvim.txt
is largely missing yet (that's why the PR is in Draft mode), but the code is fairly well documented.I'd appreciate feedback, both on the code as well as on the functionality. I've been using this for some time and find it useful and worth the large amount of changes.
I believe some refactoring could be applied to the existing comment creation which would ultimately reduce the amount of code, like I've written a separate function for creating a suggestion, which is a little more universal than the existing build_suggestion.