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
5 changes: 5 additions & 0 deletions .changeset/send-inline-review-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Support sending inline review draft comments directly from the diff without first saving them as pending comments.
15 changes: 15 additions & 0 deletions packages/kilo-vscode/webview-ui/agent-manager/DiffPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
reviewComposerEdit,
reviewDraftSpeechKey,
reviewEditSpeechKey,
sendReviewComments,
type AnnotationLabels,
type AnnotationMeta,
type ReviewComposer,
Expand Down Expand Up @@ -104,6 +105,7 @@ export const DiffPanel: Component<DiffPanelProps> = (props) => {
placeholder: t("agentManager.review.commentPlaceholder"),
cancel: t("common.cancel"),
comment: t("agentManager.review.commentAction"),
send: t("prompt.action.send"),
save: t("common.save"),
sendToChat: t("agentManager.review.sendToChat"),
edit: t("common.edit"),
Expand Down Expand Up @@ -289,6 +291,18 @@ export const DiffPanel: Component<DiffPanelProps> = (props) => {
focusRoot()
}

const sendComment = (file: string, side: AnnotationSide, line: number, text: string, selectedText: string) => {
const comment = { id: `c-${++nextId}-${Date.now()}`, file, side, line, comment: text, selectedText }
sendReviewComments([comment], props.activeTerminalId)
preserveScroll(() => {
setDraft(null)
draftMeta = null
composer().draft = null
})
props.onSendClick?.()
focusRoot()
}

const updateComment = (id: string, text: string) => {
preserveScroll(() => {
updateComments((prev) => prev.map((c) => (c.id === id ? { ...c, comment: text } : c)))
Expand Down Expand Up @@ -400,6 +414,7 @@ export const DiffPanel: Component<DiffPanelProps> = (props) => {
editing: editing(),
setEditing: setEditState,
addComment,
sendComment,
updateComment,
deleteComment,
cancelDraft,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2297,18 +2297,23 @@ body.am-wt-dragging-active * {
color: var(--text-base);
}

.am-annotation-btn:hover {
.am-annotation-btn:hover:not(:disabled) {
background: var(--surface-interactive-base);
}

.am-annotation-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}

.am-annotation-btn-submit {
background: var(--surface-interactive-strong, var(--vscode-button-background, #0078d4));
color: var(--text-on-fill, var(--vscode-button-foreground, #fff));
border-color: transparent;
font-weight: 500;
}

.am-annotation-btn-submit:hover {
.am-annotation-btn-submit:hover:not(:disabled) {
background: var(--surface-interactive-strong-hover, var(--vscode-button-hoverBackground, #0066b8));
}

Expand Down
15 changes: 15 additions & 0 deletions packages/kilo-vscode/webview-ui/diff-viewer/FullScreenDiffView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
reviewComposerEdit,
reviewDraftSpeechKey,
reviewEditSpeechKey,
sendReviewComments,
type AnnotationLabels,
type AnnotationMeta,
type ReviewComposer,
Expand Down Expand Up @@ -108,6 +109,7 @@ export const FullScreenDiffView: Component<FullScreenDiffViewProps> = (props) =>
placeholder: t("agentManager.review.commentPlaceholder"),
cancel: t("common.cancel"),
comment: t("agentManager.review.commentAction"),
send: t("prompt.action.send"),
save: t("common.save"),
sendToChat: t("agentManager.review.sendToChat"),
edit: t("common.edit"),
Expand Down Expand Up @@ -295,6 +297,18 @@ export const FullScreenDiffView: Component<FullScreenDiffViewProps> = (props) =>
focusRoot()
}

const sendComment = (file: string, side: AnnotationSide, line: number, text: string, selectedText: string) => {
const comment = { id: `c-${++nextId}-${Date.now()}`, file, side, line, comment: text, selectedText }
sendReviewComments([comment], props.activeTerminalId)
preserveScroll(() => {
setDraft(null)
draftMeta = null
composer().draft = null
})
props.onSendClick?.()
focusRoot()
}

const updateComment = (id: string, text: string) => {
preserveScroll(() => {
updateComments((prev) => prev.map((c) => (c.id === id ? { ...c, comment: text } : c)))
Expand Down Expand Up @@ -411,6 +425,7 @@ export const FullScreenDiffView: Component<FullScreenDiffViewProps> = (props) =>
editing: editing(),
setEditing: setEditState,
addComment,
sendComment,
updateComment,
deleteComment,
cancelDraft,
Expand Down
55 changes: 45 additions & 10 deletions packages/kilo-vscode/webview-ui/diff-viewer/review-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface AnnotationLabels {
placeholder: string
cancel: string
comment: string
send: string
save: string
sendToChat: string
edit: string
Expand Down Expand Up @@ -76,6 +77,7 @@ interface AnnotationHandlers {
editing: string | null
setEditing: (id: string | null) => void
addComment: (file: string, side: AnnotationSide, line: number, text: string, selectedText: string) => void
sendComment: (file: string, side: AnnotationSide, line: number, text: string, selectedText: string) => void
updateComment: (id: string, text: string) => void
deleteComment: (id: string) => void
cancelDraft: () => void
Expand Down Expand Up @@ -133,6 +135,19 @@ function makeActionButton(title: string, icon: SVGSVGElement, action: () => void
return button
}

export function sendReviewComments(comments: ReviewComment[], activeTerminalId?: string): void {
window.dispatchEvent(
new MessageEvent("message", {
data: {
type: activeTerminalId ? "appendReviewCommentsToTerminal" : "appendReviewComments",
comments,
autoSend: true,
targetTerminalId: activeTerminalId,
},
}),
)
}

export function buildFileAnnotations(
file: string,
fileComments: ReviewComment[],
Expand Down Expand Up @@ -235,15 +250,28 @@ export function buildReviewAnnotation(
submitButton.className = "am-annotation-btn am-annotation-btn-submit"
submitButton.textContent = handlers.labels.comment

const sendButton = document.createElement("button")
sendButton.className = "am-annotation-btn am-annotation-btn-submit"
sendButton.textContent = handlers.labels.send
sendButton.title = handlers.labels.sendToChat

const update = () => {
const disabled = textarea.value.trim().length === 0
submitButton.disabled = disabled
sendButton.disabled = disabled
}

const speech = handlers.speech?.render(meta, textarea)
if (speech) actions.appendChild(speech)
actions.appendChild(cancelButton)
actions.appendChild(submitButton)
actions.appendChild(sendButton)
wrapper.appendChild(header)
wrapper.appendChild(textarea)
wrapper.appendChild(actions)

focusWhenConnected(textarea)
update()

const submit = () => {
if (handlers.speech?.active()) return
Expand All @@ -255,6 +283,16 @@ export function buildReviewAnnotation(
handlers.addComment(meta.file, meta.side, meta.line, text, selected)
}

const send = () => {
if (handlers.speech?.active()) return
const text = textarea.value.trim()
if (!text) return
const diff = handlers.diffs.find((item) => item.file === meta.file)
const content = meta.side === "deletions" ? (diff?.before ?? "") : (diff?.after ?? "")
const selected = extractLines(content, meta.line, meta.endLine ?? meta.line)
handlers.sendComment(meta.file, meta.side, meta.line, text, selected)
}

cancelButton.addEventListener("click", (event) => {
event.stopPropagation()
handlers.cancelDraft()
Expand All @@ -265,6 +303,11 @@ export function buildReviewAnnotation(
submit()
})

sendButton.addEventListener("click", (event) => {
event.stopPropagation()
send()
})

textarea.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
event.preventDefault()
Expand All @@ -276,6 +319,7 @@ export function buildReviewAnnotation(
submit()
}
})
textarea.addEventListener("input", update)

return wrapper
}
Expand Down Expand Up @@ -360,16 +404,7 @@ export function buildReviewAnnotation(

actions.appendChild(
makeActionButton(handlers.labels.sendToChat, makeIcon("M1 1l14 7-14 7V9l10-1L1 7z"), () => {
window.dispatchEvent(
new MessageEvent("message", {
data: {
type: handlers.activeTerminalId ? "appendReviewCommentsToTerminal" : "appendReviewComments",
comments: [comment],
autoSend: true,
targetTerminalId: handlers.activeTerminalId,
},
}),
)
sendReviewComments([comment], handlers.activeTerminalId)
handlers.deleteComment(comment.id)
}),
)
Expand Down
Loading