Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"contribCommentPeekContext",
"contribCommentThreadAdditionalMenu",
"codiconDecoration",
"diffCommand"
"diffCommand",
"contribCommentEditorActionsMenu"
],
"version": "0.56.0",
"publisher": "GitHub",
Expand Down Expand Up @@ -759,6 +760,11 @@
"category": "%command.pull.request.category%",
"enablement": "!commentIsEmpty"
},
{
"command": "pr.makeSuggestion",
"title": "%command.pr.makeSuggestion.title%",
"category": "%command.pull.request.category%"
},
{
"command": "pr.startReview",
"title": "%command.pr.startReview.title%",
Expand Down Expand Up @@ -1241,6 +1247,10 @@
"command": "pr.createSingleComment",
"when": "false"
},
{
"command": "pr.makeSuggestion",
"when": "false"
},
{
"command": "pr.startReview",
"when": "false"
Expand Down Expand Up @@ -1722,6 +1732,13 @@
"when": "commentController =~ /^github-review/ && !reviewInDraftMode"
}
],
"comments/comment/editorActions": [
{
"command": "pr.makeSuggestion",
"group": "inline@3",
"when": "commentController =~ /^github-review/"
}
],
"comments/commentThread/additionalActions": [
{
"command": "pr.resolveReviewThread",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"command.pr.deleteLocalBranchesNRemotes.title": "Delete local branches and remotes",
"command.pr.createComment.title": "Add Review Comment",
"command.pr.createSingleComment.title": "Add Comment",
"command.pr.makeSuggestion.title": "Make a Suggestion",
"command.pr.startReview.title": "Start Review",
"command.pr.editComment.title": "Edit Comment",
"command.pr.cancelEditComment.title": "Cancel",
Expand Down
20 changes: 20 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,26 @@ export function registerCommands(
}),
);

context.subscriptions.push(
vscode.commands.registerCommand('pr.makeSuggestion', async (reply: CommentReply | GHPRComment) => {
const thread = reply instanceof GHPRComment ? reply.parent : reply.thread;
const commentEditor = vscode.window.activeTextEditor?.document.uri.scheme === Schemes.Comment ? vscode.window.activeTextEditor
: vscode.window.visibleTextEditors.find(visible => visible.document.uri.scheme === Schemes.Comment);
if (!commentEditor) {
Logger.appendLine('No comment editor visible for making a suggestion.');
vscode.window.showErrorMessage(vscode.l10n.t('No available comment editor to make a suggestion in.'));
return;
}
const editor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === thread.uri.toString());
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));
return commentEditor.edit((editBuilder) => {
editBuilder.insert(new vscode.Position(commentEditor.document.lineCount, 0), `\`\`\`suggestion
${contents}
\`\`\``);
});
})
);

context.subscriptions.push(
vscode.commands.registerCommand('pr.editComment', async (comment: GHPRComment | TemporaryComment) => {
/* __GDPR__
Expand Down
2 changes: 1 addition & 1 deletion src/github/prComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class TemporaryComment extends CommentBase {
}
}

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

export class GHPRComment extends CommentBase {
public commentId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/view/reviewCommentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ export class ReviewCommentController
throw new Error('Cannot find the editor to apply the suggestion to.');
}
await editor.edit(builder => {
builder.replace(range, suggestion);
builder.replace(range.with(undefined, new vscode.Position(range.end.line + 1, 0)), suggestion);
});
}

Expand Down