-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(vscode): render submitted review comments across chat surfaces #11173
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": patch | ||
| --- | ||
|
|
||
| Show submitted review comments as interactive message cards instead of raw markdown. |
3 changes: 3 additions & 0 deletions
3
...o-vscode/visual-regression/chat/user-message-review-comments-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| export interface ReviewCommentData { | ||
| id: string | ||
| file: string | ||
| side: "additions" | "deletions" | ||
| line: number | ||
| comment: string | ||
| selectedText: string | ||
| } | ||
|
|
||
| export interface ReviewMessageData { | ||
| version: 1 | ||
| comments: ReviewCommentData[] | ||
| } | ||
|
|
||
| interface ReviewMessageView { | ||
| data: ReviewMessageData | ||
| body: string | ||
| } | ||
|
|
||
| const LIMIT = 100 | ||
| const TOTAL_LIMIT = 1_000_000 | ||
| const TEXT_LIMIT = 100_000 | ||
| const SELECTION_LIMIT = 200_000 | ||
|
|
||
| function escapeInline(value: string): string { | ||
| return value.replace(/([\\`*_\[\]{}()#+\-!|])/g, "\\$1") | ||
| } | ||
|
|
||
| export function formatReviewCommentMarkdown(comment: ReviewCommentData): string { | ||
| const lines = [`**${escapeInline(comment.file)}** (line ${comment.line}):`] | ||
| if (comment.selectedText) { | ||
| const matches = comment.selectedText.match(/`+/g) ?? [] | ||
| const longest = matches.reduce((max, item) => Math.max(max, item.length), 0) | ||
| const fence = "`".repeat(Math.max(3, longest + 1)) | ||
| lines.push(fence, comment.selectedText, fence) | ||
| } | ||
| lines.push(comment.comment) | ||
| return lines.join("\n") | ||
| } | ||
|
|
||
| export function formatReviewCommentsMarkdown(comments: ReviewCommentData[]): string { | ||
| const lines = ["## Review Comments", ""] | ||
| for (const item of comments) { | ||
| lines.push(formatReviewCommentMarkdown(item), "") | ||
| } | ||
| return lines.join("\n").trimEnd() | ||
| } | ||
|
|
||
| function record(value: unknown): Record<string, unknown> | undefined { | ||
| if (!value || typeof value !== "object" || Array.isArray(value)) return undefined | ||
| return value as Record<string, unknown> | ||
| } | ||
|
|
||
| function text(value: unknown, limit: number): string | undefined { | ||
| if (typeof value !== "string" || value.length > limit) return undefined | ||
| return value | ||
| } | ||
|
|
||
| function parseComment(value: unknown): ReviewCommentData | undefined { | ||
| const item = record(value) | ||
| if (!item) return undefined | ||
|
|
||
| const id = text(item.id, 512) | ||
| const file = text(item.file, 4_096) | ||
| const comment = text(item.comment, TEXT_LIMIT) | ||
| const selectedText = text(item.selectedText, SELECTION_LIMIT) | ||
| const side = item.side | ||
| const line = item.line | ||
| if (!id || !file || comment === undefined || selectedText === undefined) return undefined | ||
| const absolute = file.startsWith("/") || file.startsWith("\\") || /^[A-Za-z]:[\\/]/.test(file) | ||
| const traversal = file.split(/[\\/]/).includes("..") | ||
| if (absolute || traversal || file.includes("\0")) return undefined | ||
| if (side !== "additions" && side !== "deletions") return undefined | ||
| if (typeof line !== "number" || !Number.isInteger(line) || line < 1) return undefined | ||
|
|
||
| return { id, file, side, line, comment, selectedText } | ||
| } | ||
|
|
||
| function view(value: unknown, content: string): ReviewMessageView | undefined { | ||
| const data = record(value) | ||
| if (!data || data.version !== 1 || !Array.isArray(data.comments)) return undefined | ||
| if (data.comments.length === 0 || data.comments.length > LIMIT) return undefined | ||
|
|
||
| const comments: ReviewCommentData[] = [] | ||
| for (const value of data.comments) { | ||
| const item = parseComment(value) | ||
| if (!item) return undefined | ||
| comments.push(item) | ||
| } | ||
| const size = comments.reduce( | ||
| (total, item) => total + item.id.length + item.file.length + item.comment.length + item.selectedText.length, | ||
| 0, | ||
| ) | ||
| if (size > TOTAL_LIMIT) return undefined | ||
|
|
||
| const prefix = formatReviewCommentsMarkdown(comments) | ||
| if (content === prefix) return { data: { version: 1, comments }, body: "" } | ||
| if (!content.startsWith(`${prefix}\n\n`)) return undefined | ||
| return { data: { version: 1, comments }, body: content.slice(prefix.length + 2) } | ||
| } | ||
|
|
||
| export function parseReview(value: unknown, content: string): ReviewMessageData | undefined { | ||
| return view(value, content)?.data | ||
| } | ||
|
|
||
| export function reviewMetadata(review: ReviewMessageData): Record<string, unknown> { | ||
| return { kilo: { review } } | ||
| } | ||
|
|
||
| export function reviewBody(review: ReviewMessageData, content: string): string | undefined { | ||
| return view(review, content)?.body | ||
| } | ||
|
|
||
| export function partReview(metadata: unknown, content: string): ReviewMessageView | undefined { | ||
| const root = record(metadata) | ||
| const kilo = record(root?.kilo) | ||
| return view(kilo?.review, content) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SUGGESTION: Variable
valuein theforloop shadows the outervalueparameter of theviewfunction.The outer
valueis no longer needed past line 80, so this isn't a functional bug, but it's a style guideline violation (no-shadow) and could confuse readers. Consider using a different name likeentryorraw.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.