Skip to content

Commit 786b62b

Browse files
authored
Add "Make a suggestion button" (#4356)
Fixes #603
1 parent 12954ea commit 786b62b

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

package.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"contribCommentPeekContext",
1919
"contribCommentThreadAdditionalMenu",
2020
"codiconDecoration",
21-
"diffCommand"
21+
"diffCommand",
22+
"contribCommentEditorActionsMenu"
2223
],
2324
"version": "0.56.0",
2425
"publisher": "GitHub",
@@ -759,6 +760,11 @@
759760
"category": "%command.pull.request.category%",
760761
"enablement": "!commentIsEmpty"
761762
},
763+
{
764+
"command": "pr.makeSuggestion",
765+
"title": "%command.pr.makeSuggestion.title%",
766+
"category": "%command.pull.request.category%"
767+
},
762768
{
763769
"command": "pr.startReview",
764770
"title": "%command.pr.startReview.title%",
@@ -1241,6 +1247,10 @@
12411247
"command": "pr.createSingleComment",
12421248
"when": "false"
12431249
},
1250+
{
1251+
"command": "pr.makeSuggestion",
1252+
"when": "false"
1253+
},
12441254
{
12451255
"command": "pr.startReview",
12461256
"when": "false"
@@ -1722,6 +1732,13 @@
17221732
"when": "commentController =~ /^github-review/ && !reviewInDraftMode"
17231733
}
17241734
],
1735+
"comments/comment/editorActions": [
1736+
{
1737+
"command": "pr.makeSuggestion",
1738+
"group": "inline@3",
1739+
"when": "commentController =~ /^github-review/"
1740+
}
1741+
],
17251742
"comments/commentThread/additionalActions": [
17261743
{
17271744
"command": "pr.resolveReviewThread",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
"command.pr.deleteLocalBranchesNRemotes.title": "Delete local branches and remotes",
144144
"command.pr.createComment.title": "Add Review Comment",
145145
"command.pr.createSingleComment.title": "Add Comment",
146+
"command.pr.makeSuggestion.title": "Make a Suggestion",
146147
"command.pr.startReview.title": "Start Review",
147148
"command.pr.editComment.title": "Edit Comment",
148149
"command.pr.cancelEditComment.title": "Cancel",

src/commands.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,26 @@ export function registerCommands(
866866
}),
867867
);
868868

869+
context.subscriptions.push(
870+
vscode.commands.registerCommand('pr.makeSuggestion', async (reply: CommentReply | GHPRComment) => {
871+
const thread = reply instanceof GHPRComment ? reply.parent : reply.thread;
872+
const commentEditor = vscode.window.activeTextEditor?.document.uri.scheme === Schemes.Comment ? vscode.window.activeTextEditor
873+
: vscode.window.visibleTextEditors.find(visible => visible.document.uri.scheme === Schemes.Comment);
874+
if (!commentEditor) {
875+
Logger.appendLine('No comment editor visible for making a suggestion.');
876+
vscode.window.showErrorMessage(vscode.l10n.t('No available comment editor to make a suggestion in.'));
877+
return;
878+
}
879+
const editor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === thread.uri.toString());
880+
const contents = editor?.document.getText(new vscode.Range(thread.range.start.line, 0, thread.range.end.line, editor.document.lineAt(thread.range.end.line).text.length));
881+
return commentEditor.edit((editBuilder) => {
882+
editBuilder.insert(new vscode.Position(commentEditor.document.lineCount, 0), `\`\`\`suggestion
883+
${contents}
884+
\`\`\``);
885+
});
886+
})
887+
);
888+
869889
context.subscriptions.push(
870890
vscode.commands.registerCommand('pr.editComment', async (comment: GHPRComment | TemporaryComment) => {
871891
/* __GDPR__

src/github/prComment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export class TemporaryComment extends CommentBase {
182182
}
183183
}
184184

185-
const SUGGESTION_EXPRESSION = /```suggestion(\n|\r\n)([\s\S]*)(\n|\r\n)```/;
185+
const SUGGESTION_EXPRESSION = /```suggestion(\r\n|\n)([\s\S]*)(\r\n|\n)```/;
186186

187187
export class GHPRComment extends CommentBase {
188188
public commentId: string;

src/view/reviewCommentController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ export class ReviewCommentController
868868
throw new Error('Cannot find the editor to apply the suggestion to.');
869869
}
870870
await editor.edit(builder => {
871-
builder.replace(range, suggestion);
871+
builder.replace(range.with(undefined, new vscode.Position(range.end.line + 1, 0)), suggestion);
872872
});
873873
}
874874

0 commit comments

Comments
 (0)