Skip to content

Commit 81480e2

Browse files
Copilotalexr00
andauthored
Add file path and line context to "Apply suggestion using AI" prompt (#8629)
* Initial plan * Initial plan for adding file/line context to AI suggestion prompt Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/eee01273-3d0c-403d-8bf7-8fbf1a909169 Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add file path and line number context to AI suggestion prompt Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/eee01273-3d0c-403d-8bf7-8fbf1a909169 Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Refactor: consolidate GHPRComment type checks for file path and body extraction Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/eee01273-3d0c-403d-8bf7-8fbf1a909169 Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent b4f97f2 commit 81480e2

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/commands.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,8 +1850,29 @@ ${contents}
18501850
const commentThread = isThread ? comment : comment.parent;
18511851
const firstComment = isThread ? comment.comments[0] : comment;
18521852
commentThread.collapsibleState = vscode.CommentThreadCollapsibleState.Collapsed;
1853-
const message = firstComment instanceof GHPRComment ? firstComment.rawComment.body
1854-
: (firstComment.body instanceof vscode.MarkdownString ? firstComment.body.value : firstComment.body);
1853+
let commentBody: string;
1854+
let filePath: string | undefined;
1855+
if (firstComment instanceof GHPRComment) {
1856+
commentBody = firstComment.rawComment.body;
1857+
filePath = firstComment.rawComment.path;
1858+
} else {
1859+
commentBody = firstComment.body instanceof vscode.MarkdownString ? firstComment.body.value : firstComment.body;
1860+
filePath = undefined;
1861+
}
1862+
const range = commentThread.range;
1863+
let message: string;
1864+
if (filePath && range) {
1865+
const startLine = range.start.line + 1;
1866+
const endLine = range.end.line + 1;
1867+
const lineRef = startLine === endLine
1868+
? vscode.l10n.t('line {0}', startLine)
1869+
: vscode.l10n.t('lines {0}-{1}', startLine, endLine);
1870+
message = vscode.l10n.t('There is a code review comment for file {0} at {1}:\n{2}', filePath, lineRef, commentBody);
1871+
} else if (filePath) {
1872+
message = vscode.l10n.t('There is a code review comment for file {0}:\n{1}', filePath, commentBody);
1873+
} else {
1874+
message = commentBody;
1875+
}
18551876

18561877
if (isThread) {
18571878
// For threads, open the Chat view instead of inline chat

0 commit comments

Comments
 (0)