-
Notifications
You must be signed in to change notification settings - Fork 43
Leaving Comments Does Not Work #25
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
Comments
For me, the problem is not unchanged lines, rather more specifically, lines in unchanged files. |
This is not a nil pointer error, but it looks like the same issue of not being able to comment on unchanged lines, perhaps with the improvements from #42? Full acknowledgement that the way the Gitlab API has you post comments is horrible. Edit: This also happens when trying to comment on a changed line. |
Yes, thanks for pointing this out. Fundamentally, the issue here is that Gitlab requires you to submit a different payload for a new discussion thread depending on whether or not the line you're commenting on has been deleted, updated, or unchanged. Right now this plugin has no built-in mechanism for viewing changes in an MR, which makes it impossible to know what type of line you're leaving a comment on. Has the line been deleted? Modified? Added? In the near future I'm going to make delta, a pager for Git, a dependency of this project, so that we can control the view when someone is leaving comments. It'd look something like this in Neovim: Delta shows all of the relevant changed lines in an easy-to-see view along with line numbers in the affected files. If we use this output as the "review" window we could then use the data to send the correct payload. This is going to require a relatively large refactor of the plugin and will change some fundamental behavior, but hopefully will give us both a scrollable view of the changes and fix these API issues. I'll drop a comment on this thread when this refactor is done, it's definitely going to be a breaking change. |
I don't know a ton about it, but I'm curious why something like |
Yes, I'm basically leaning toward using Delta because it provides a single unified diff view (which Diffview does not provide, see: sindrets/diffview.nvim#39) and line numbers within that view with very little customization required. The maintainer of DiffView specifically recommends this tool. Frankly this is a bit of a time/effort decision for me... Delta provides basically all of the functionality that we'll want in a "review" view out of the box, including the ability to show completely added and removed files and all of their content, and to show line numbers in a unified diff format (like Gitlab does) for every change in every modified file. It's probably possible to do this with the built in diffing provided by Neovim, but it's certainly not my area of expertise would require a lot of trial and error and research. At the moment not something I'm willing to sink many hours of time into figuring out. I'm aware that this will mean this plugin picks up an external dependency, but it's a well-known tool and I'm hopeful that it's quick and painless (brew install delta, e.g.) to install, and wouldn't require any additional configuration. |
That's all to say: You're not wrong and a native approach would be possible, and probably preferable, but I don't have the bandwidth for it right now. If someone wants to try and tackle this in the future though I'm more than happy to work with them to merge it. It sucks because this is 100 percent due to Gitlab's rough comments API. |
@levouh and @mnbroatch if you would be so kind as to try the feature branch mentioned above and let me know if it works for you, that'd be great. Please note that the setup function is slightly different now (breaking change). It changes the plugin to show you the diff of an MR, and you can comment on the changed/updated lines. Please let me know if it solves your issues, I think it gives us a better overall experience too since you can now see all of the MR changes in a single review buffer, which we can center the plugin around moving forward. |
A few notes @harrisoncramer:
(Note I did change the Appreciate the (quick) work, and will update here if I find anything else. |
I really like the idea of having separate reviewers, I think that's a great idea. Also, thank you so much for the catch on the delta options -- I've added your changes to the MR. I'm game to refactor this MR to be more abstract. I think getting everything working with Delta first (with perhaps an abstraction around the reviewer like you mentioned, I'm happy to take a crack at it if you'd like) is perhaps the best plan of attack, and then you can follow up with a subsequent MR working on a native approach using the same abstraction? To answer your questions: "When a user wants to leave a comment, the action from the "core" is to grab the current Review instance and ask it for the information that needs to be submitted to Gitlab. What file is this for? What line? Is it changed or unchanged or removed?" In M.add_reviewer = M.ensureState(M.ensureProjectMembers(assignees_and_reviewers.add_reviewer)) This will ensure that state is set that's required for those actions. In this case, the ensure functions call two different endpoints, the "/info" and "/members" endpoints, to set state on the These are the actions that would have to be tied to a "reviewer" abstraction: M.review = M.ensureState(review.open)
M.create_comment = M.ensureState(M.ensureRevisions(comment.create_comment))
M.edit_comment = M.ensureState(comment.edit_comment)
M.delete_comment = M.ensureState(comment.delete_comment) Your idea of breaking these into a separate Lua M.review = M.ensureState(reviewer.open)
M.create_comment = M.ensureState(M.ensureRevisions(reviewer.create_comment))
M.edit_comment = M.ensureState(reviewer.edit_comment)
M.delete_comment = M.ensureState(reviewer.delete_comment) The For instance right now the -- This function (settings.popup.perform_action) will send the comment to the Go server
M.confirm_create_comment = function(text)
local line_num = u.get_current_line_number()
local content = u.get_line_content(state.REVIEW_BUF, line_num)
local current_line_changes = discussions.get_change_nums(content)
local new_line = u.get_line_content(state.REVIEW_BUF, line_num + 1)
local next_line_changes = discussions.get_change_nums(new_line)
...
local file_name = discussions.get_file_from_review_buffer(line_num)
...
local revision = state.MR_REVISIONS[1]
local jsonTable = {
comment = text,
file_name = file_name,
old_line = current_line_changes.old_line,
new_line = current_line_changes.new_line,
base_commit_sha = revision.base_commit_sha,
start_commit_sha = revision.start_commit_sha,
head_commit_sha = revision.head_commit_sha,
}
local json = vim.json.encode(jsonTable)
job.run_job("comment", "POST", json, function(data)
vim.notify("Comment created")
discussions.refresh_tree()
end)
If the reviewer module was abstracted, it could be reused, something like this: M.confirm_create_comment = function(text)
local reviewer_data, reviewer_data_valid, err = reviewer.data()
if err then vim.notify(err.error(), vim.log.levels.ERROR) end
local revision = state.MR_REVISIONS[1]
local jsonTable = {
comment = text,
file_name = reviewer_data.file_name,
old_line = reviewer_data.current_line_changes.old_line,
new_line = reviewer_data.current_line_changes.new_line,
base_commit_sha = revision.base_commit_sha,
start_commit_sha = revision.start_commit_sha,
head_commit_sha = revision.head_commit_sha,
}
local json = vim.json.encode(jsonTable)
job.run_job("comment", "POST", json, function(data)
vim.notify("Comment created")
discussions.refresh_tree()
end)
end ** Regarding the errors that you're seeing right now -- have you pushed up your changes? I've noticed that the POST will fail if you have committed changes locally that don't match your remote repository. Additionally, if you make changes, commit, push, and then try to leave a comment without leaving Neovim then you'll probably see that error. In both cases, it's because the SHAs in your This feels like a separate bug. Please let me know if this is your problem or if it's something else... |
Hmm, I'm seeing some issues:
I think it expects me to have opened the review view instead of discussion list. If that's required it should be enforced
|
yea, actually commenting isn't working at all for me. I highlight a line in the side-by-side diff (I set side-by-side mode for delta in .gitconfig) and glc gives me
|
In the old diffview workflow, diffview gave me a browsable tree of changed files. Is that possible with the new workflow? edit: Oh I see all changed files are there in the diff one after the other. That's not quite as nice, huh |
I'll post something in this thread once I've made some progress on abstracting the reviewer module. |
A few messages out of sync now so pardon me - replying to this message
Absolutely agree. It will help define what the abstract version actually needs to implement to function, with a functional baseline using
Can certainly try.
These were more poking at what the abstract class might need to implement as "questions" asked of it by the "core engine", but either way, your notes certainly help provide some insight into what the code is doing.
This looks exactly like what I imagined and makes implementing different "reviewers" far simpler than the tight coupling that exists right now 👍.
My local state was actually just
Fully agree about the notion of "state mismatch" being a bug. I wonder if having a defined "pipeline" or some |
And now replying to this message -
Obviously turning this into a "git library" is not the goal, but some basic helpers might go a long way. E.g. the branch can be compared against a remote, say Just food-for-thought though - I think getting the core workflow nailed down a bit first makes infinitely more sense, then seeing how the more QOL features fit in after the fact. Obviously depending on how the early development goes, it might be easier/harder to implement features down the road, but foresight into "all possible features" is also impossible. |
Okay, pretty major refactor is complete, but the Delta reviewer code is now separated from the rest of the application. Additionally there was a major cleanup of the entire code-base, I think you'll find it much easier to read through. This is a breaking change so I'll make sure to make a note of that after merging it in, some of the settings have changed (and delta has been added as a requirement until we build another solution). Given the size of this MR it makes sense to do follow-up bug tracking/squashing in separate follow-up MRs. Please feel free to open up new, specific issues for anything you find. Please note that the setup function arguments have changed. |
Describe the bug
When you try to leave a comment on an unchanged/undeleted/unadded line, you'll get a nil pointer dereference:
Leaving comments is definitely the hardest part of this plugin. Right now we bulk attempt to send comments to three different APIs since it's not clear whether you're leaving a comment on a deleted, changed, or added line. There's probably a better way of doing this that would also potentially address this issue.
Expected behavior
We should handle this more gracefully.
The text was updated successfully, but these errors were encountered: