-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(jetbrains): improve session diff rendering #12862
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
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b2f0bb0
fix(jetbrains): sharpen copy icon
kirillk d5e19d5
fix(jetbrains): update reasoning icon
kirillk c47cfec
fix(jetbrains): align reverted diff action
kirillk 9b4738e
fix(jetbrains): load reverted session diffs
kirillk 6eba817
fix(jetbrains): show absolute reverted file tooltips
kirillk 4cdbe9d
fix(jetbrains): reconcile session layout cache
kirillk 6414e64
fix(jetbrains): render multi-hunk diffs
kirillk bfab19c
fix(jetbrains): resolve revert tooltip fallback
kirillk 0983e07
feat(jetbrains): full-file diff detail for editor tabs
kirillk a90a242
Merge remote-tracking branch 'origin/main' into jetbrains-pixel-icons
kirillk 8650fdd
refactor(jetbrains): reconstruct full-file diffs locally
kirillk ebebad0
feat(jetbrains): authoritative full-file editor diffs with local fall…
kirillk 41e2bf5
fix(jetbrains): correct gutter line numbers in hunk-fallback diff editor
kirillk f09e628
fix(cli): give DiffFull.detail a single return shape
kirillk 324291c
Merge remote-tracking branch 'origin/main' into jetbrains-pixel-icons
kirillk 9a4410f
fix(jetbrains): route full diffs to session directory and scope singl…
kirillk 967126c
chore(jetbrains): fix repo-CLI dev build after upstream merge
kirillk 4c6bcf5
fix(jetbrains): support pinned and repo CLI revert models
kirillk 450b8a2
chore: sync bun.lock kilo-jetbrains version with package.json
kirillk a3160d7
fix(jetbrains): harden diff fallback handling
kirillk 61ffa57
Merge branch 'main' into jetbrains-pixel-icons
kirillk 7571619
Merge branch 'main' into jetbrains-pixel-icons
kirillk 1d35159
Merge branch 'main' into jetbrains-pixel-icons
kirillk 2e9312e
Merge remote-tracking branch 'origin/main' into jetbrains-pixel-icons
kirillk abfdaad
Merge remote-tracking branch 'origin/jetbrains-pixel-icons' into jetb…
kirillk 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 @@ | ||
| --- | ||
| "@kilocode/kilo-jetbrains": patch | ||
| --- | ||
|
|
||
| Improve JetBrains session transcript layout, icons, reverted-change summaries, and multi-hunk diff rendering. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
86 changes: 86 additions & 0 deletions
86
...es/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/diff/DiffFullReconstruct.kt
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,86 @@ | ||
| package ai.kilocode.backend.diff | ||
|
|
||
| /** | ||
| * Rebuilds the full "before" content of a modified file by reverse-applying a unified diff hunk | ||
| * patch to the current working-tree content. This lets the JetBrains diff editor show a whole-file | ||
| * diff (with collapsible unchanged regions) from the limited-context patch the CLI already returns — | ||
| * no CLI change required. | ||
| * | ||
| * Added and deleted files are intentionally rejected: their patches already carry every line, so the | ||
| * frontend reconstructs those full sides directly. Binary patches and any drift between the patch's | ||
| * after side and the real file (a stale/historical turn) also return null so the caller can fall back | ||
| * to the hunk-only view instead of rendering a wrong diff. | ||
| * | ||
| * Known limitation: `\ No newline at end of file` markers are dropped rather than tracked per side, so | ||
| * the reconstructed `before` inherits the after side's trailing-newline state. When exactly one side | ||
| * lacks a trailing newline, the whole-file fallback view will not surface that EOF-newline change. This | ||
| * is cosmetic and rare (the scoped hunk view still shows the marker); tracking it per side would require | ||
| * remembering which side the marker followed. | ||
| */ | ||
| internal object DiffFullReconstruct { | ||
| private val HUNK = Regex("^@@ -\\d+(?:,\\d+)? \\+(\\d+)(?:,(\\d+))? @@") | ||
|
|
||
| fun before(after: String, patch: String?): String? { | ||
| if (patch.isNullOrBlank() || binary(patch) || added(patch) || deleted(patch)) return null | ||
|
|
||
| val lines = if (after.isEmpty()) emptyList() else after.split("\n") | ||
| val out = ArrayList<String>(lines.size) | ||
| var cursor = 0 // next after-line index still to emit (0-based) | ||
| var open = false | ||
| var start = 0 // 0-based after index where the current hunk begins | ||
| val afterBody = ArrayList<String>() | ||
| val beforeBody = ArrayList<String>() | ||
|
|
||
| fun flush(): Boolean { | ||
| if (!open) return true | ||
| if (start < cursor) return false // overlapping or out-of-order hunks | ||
| while (cursor < start) { | ||
| if (cursor >= lines.size) return false | ||
| out.add(lines[cursor]); cursor++ | ||
| } | ||
| for (i in afterBody.indices) { | ||
| val idx = start + i | ||
| if (idx >= lines.size || lines[idx] != afterBody[i]) return false // working tree drifted | ||
| } | ||
| out.addAll(beforeBody) | ||
| cursor = start + afterBody.size | ||
| afterBody.clear(); beforeBody.clear() | ||
| open = false | ||
| return true | ||
| } | ||
|
|
||
| // git patches are newline-terminated; drop the trailing split artifact so it is not read as a | ||
| // blank context line. Real blank context lines are " " (space-prefixed), never "". | ||
| for (raw in patch.split("\n").dropLastWhile { it.isEmpty() }) { | ||
| if (raw.startsWith("@@")) { | ||
| if (!flush()) return null | ||
| val match = HUNK.find(raw) ?: return null | ||
| val newStart = match.groupValues[1].toIntOrNull() ?: return null | ||
| val newLen = match.groupValues[2].ifEmpty { "1" }.toInt() | ||
| // For a zero-length new range git reports the line preceding the removed block, so the | ||
| // removed lines are reinserted at `newStart`; otherwise the region starts at newStart-1. | ||
| start = if (newLen == 0) newStart else newStart - 1 | ||
| open = true | ||
| continue | ||
| } | ||
| if (!open) continue // skip file headers (diff/index/---/+++) | ||
| if (raw.startsWith("\\")) continue // "\ No newline at end of file" | ||
| when (raw.firstOrNull()) { | ||
| ' ' -> { val body = raw.substring(1); afterBody.add(body); beforeBody.add(body) } | ||
| '+' -> afterBody.add(raw.substring(1)) | ||
| '-' -> beforeBody.add(raw.substring(1)) | ||
| null -> { afterBody.add(""); beforeBody.add("") } | ||
| else -> return null | ||
| } | ||
| } | ||
| if (!flush()) return null | ||
| while (cursor < lines.size) { out.add(lines[cursor]); cursor++ } | ||
| return out.joinToString("\n") | ||
| } | ||
|
|
||
| fun added(patch: String): Boolean = patch.lineSequence().any { it == "--- /dev/null" } | ||
|
|
||
| fun deleted(patch: String): Boolean = patch.lineSequence().any { it == "+++ /dev/null" } | ||
|
|
||
| private fun binary(patch: String): Boolean = patch.lineSequence().any { it.startsWith("Binary files ") } | ||
| } | ||
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
55 changes: 55 additions & 0 deletions
55
...ilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/diff/DiffFullReconstructTest.kt
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,55 @@ | ||
| package ai.kilocode.backend.diff | ||
|
|
||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertNull | ||
|
|
||
| class DiffFullReconstructTest { | ||
|
|
||
| @Test | ||
| fun `reconstructs before across multiple hunks keeping unchanged regions`() { | ||
| // Ten-line file; two separated single-line edits. The patch only carries 3-context hunks, so | ||
| // the unchanged gap between them must come from the working-tree content. | ||
| val after = (1..10).joinToString("\n") { if (it == 2) "TWO" else if (it == 9) "NINE" else "l$it" } + "\n" | ||
| val patch = buildString { | ||
| append("--- a/f\n+++ b/f\n") | ||
| append("@@ -1,4 +1,4 @@\n l1\n-l2\n+TWO\n l3\n l4\n") | ||
| append("@@ -7,4 +7,4 @@\n l7\n l8\n-l9\n+NINE\n l10\n") | ||
| } | ||
|
|
||
| val before = DiffFullReconstruct.before(after, patch) | ||
|
|
||
| assertEquals((1..10).joinToString("\n") { "l$it" } + "\n", before) | ||
| } | ||
|
|
||
| @Test | ||
| fun `reconstructs before for a deletion-only hunk`() { | ||
| val after = "a\nc\n" | ||
| val patch = "--- a/f\n+++ b/f\n@@ -1,3 +1,2 @@\n a\n-b\n c\n" | ||
|
|
||
| assertEquals("a\nb\nc\n", DiffFullReconstruct.before(after, patch)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `preserves files without a trailing newline`() { | ||
| val after = "a\nB" | ||
| val patch = "--- a/f\n+++ b/f\n@@ -1,2 +1,2 @@\n a\n-b\n+B\n\\ No newline at end of file\n" | ||
|
|
||
| assertEquals("a\nb", DiffFullReconstruct.before(after, patch)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `returns null when context does not match the working tree`() { | ||
| val patch = "--- a/f\n+++ b/f\n@@ -1,2 +1,2 @@\n a\n-b\n+B\n" | ||
|
|
||
| assertNull(DiffFullReconstruct.before("x\nB\n", patch)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `returns null for added deleted binary and blank patches`() { | ||
| assertNull(DiffFullReconstruct.before("hello\n", "--- /dev/null\n+++ b/f\n@@ -0,0 +1 @@\n+hello\n")) | ||
| assertNull(DiffFullReconstruct.before("", "--- a/f\n+++ /dev/null\n@@ -1 +0,0 @@\n-gone\n")) | ||
| assertNull(DiffFullReconstruct.before("x", "Binary files a/f and b/f differ\n")) | ||
| assertNull(DiffFullReconstruct.before("x", "")) | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.