Suggest change to a single line in merge request diff comment
If someone is working on a merge request, suggesting a change can be done with a comment.
But it's much more powerful to suggest a change by making it, by making a merge request to the merge request. This is something that is getting more and more interesting as the editor of GitLab is becoming better and faster.
The downside of this is that a merge request to a branch that has a merge request is:
- clunky, they are not linked and both heavy pages
- this is not visualized in any way in the original merge request
The ability to suggest changes inline, would make this much easier.
GitLab should be making it easier for everyone to contribute. This lowers the barrier to contributing by making proposing a small code change as easy as leaving a comment.
Proposal
The ability to suggest a change within a line comment using a ```suggestion
code block
-
Add a button to insert a code block containing the line being commented.
This will allow the user to quickly modify the line to be what they think it should be. The user should be able to offer multiple suggestions in a single comment.
-
Update the markdown preview to verify the suggestion is being detected correctly.
The Apply suggestion button should be disabled
-
Add an Apply suggestion button to create a commit on the feature branch applying the change.
The
author
should be the user who proposed the change (incl date time) Thecommitter
should be the user who applied the change Commit message:Apply suggestion to <file-name>
Designs
Comment editor | Comment preview | Comment with suggestion | Suggestion applied |
---|---|---|---|
- Icon for comment editor toolbar - https://gitlab-org.gitlab.io/gitlab-svgs/?q=~doc-code. This icon should only appears when commenting on diffs.
- Clicking on this toolbar icon will insert the suggestion block with the selected line of code filled in.
- When clicking the toolbar icon, if any text is selected in the editor, the suggestion block is inserted at the start of the selection. The selected text should not be removed. This is the same behavior as the insert table toolbar button.
- The apply button does not appear in the comment preview and only appears after posting the comment.
Future enhancements:
-
Add an Open in Web IDE to open the merge request in the Web IDE and apply the change to the working copy.
The user can then review and make additional modifications. The updated line might impact other elements of the merge request that the author needs to resolve themselves.
-
Adding a custom commit message when applying a suggested change.
-
A checkbox to automatically resolve the discussion when applying a suggestion.