feat(jetbrains): render Mermaid diagrams in chat - #13396
Conversation
Code Review SummaryStatus: 8 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (22 files)
Fix these issues in Kilo Cloud Previous Review Summaries (4 snapshots, latest commit 4801e43)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 4801e43)Status: 7 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (22 files)
Fix these issues in Kilo Cloud Previous review (commit dedd439)Status: 4 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (37 files)
Fix these issues in Kilo Cloud Previous review (commit 83ec1b3)Status: 4 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (39 files)
Fix these issues in Kilo Cloud Previous review (commit ccfd17e)Status: 6 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (31 files)
Reviewed by grok-4.6 · Input: 266.3K · Output: 29.8K · Cached: 1.1M Review guidance: REVIEW.md from base branch |
Add a scene painter, palette, async render service, and Swing panel so closed mermaid fences show a real diagram in the transcript instead of source text. Streaming fences and render errors keep the code block visible, and a source toggle reveals the fence text on demand. Ship behind the kilo.diagram.inline.enabled registry key since this changes default rendering.
The hover overlay on a rendered mermaid diagram only offered copy. Expose the shared copy toolbar with an extra standard open action that puts the mermaid source in a scratch editor tab, so the diagram keeps the affordances of the code block it replaces and the source can be edited or previewed with IDE tooling.
Two bugs hid the diagram affordances. The hover resolver always handed the message-level toolbar to nested targets, so the diagram's copy and open buttons never appeared, and Stack ignores add() indexes, so the toggle row rendered above the diagram instead of below it. Let the deepest target win when it brings its own toolbar, and make the diagram block a stable Stack whose children keep a fixed order and switch between diagram and source by visibility. The block, not the painted panel, is now the hover target so the toolbar stays put while the pointer moves within the block.
Addresses PR review on the mermaid diagram engine:
- Share AwtMeasure safely. The engine service holds one instance and draws
off the EDT on the default dispatcher, so the font cache is now a
ConcurrentHashMap. The Graphics2D that had no dispose() is already gone.
- Refuse pathological sources earlier. A character cap is checked before any
preprocessing, node and link caps are enforced while the model is built so
`A & B & ... --> ...` cannot expand first, and both parsers check
cancellation per line. The `%%{...}%%` mask is a linear scan instead of a
lazy regex that rescanned to end-of-text per unterminated opener, and the
message regex can no longer backtrack over a colon-free line.
- Assign subgraph membership on re-mention. `Client --> Gateway` followed by
`subgraph core` / `Gateway --> Auth` now puts Gateway inside the frame,
which is how mermaid reads it.
- Report sequence scene size from glyph extents, not anchors, so a
left-anchored self-message label is inside the bounds a renderer clips to.
- Close activations left open at the end of a script, so `A->>+B: hi` with no
matching deactivate still draws its bar.
- Parse participant ids through unquote and match ` as ` case-insensitively
outside quotes, so `participant "Alice"` and `PARTICIPANT C AS Client`
resolve to one column.
assertInBounds now checks text extents rather than anchors, so this class of
overflow fails in tests instead of clipping at paint time.
|
All six review findings addressed in 83ec1b3; individual threads have detailed replies and are resolved.
Verified with |
Diagram rendering degraded to the mermaid source correctly for engine
refusals, but three paths could not recover and none of them left a trace
in the log.
Log every failure. An engine crash was converted to a Fault.Internal
carrying only err.message, discarding the throwable, so a parser or layout
bug reached the user as an unactionable red label and left nothing to
report. It now logs with the stack trace, as does a failing completion
callback and a failed image allocation.
Close the fallback holes. The completion callback ran unguarded inside the
render coroutine, so a failure in it was reported as a plugin error and
left the block pending forever. Painters.of used first {}, turning a future
art type without a painter into an exception in both paint and sizing.
Painting itself was unguarded, and by the time it runs the source pane is
already hidden, so a failure left a blank surface with no way back; paint
failures now hand a fallback to the owner, which restores the source.
diagramImage allocated 2x the scene with no ceiling, and Limits caps the
model rather than the geometry, so a legal diagram could ask for a
multi-gigabyte raster on the EDT the moment someone pressed copy.
Bound the work that limits did not cover. Cancellation is only checked
between lines, so one line needed its own cap, and per-index open/quote
scanning is replaced by a single pass because it made a long line
quadratic. FlowMarks was the only phase with no cancellation point at all
and resolved frame members by recursing per cluster, rescanning every node
each time; it now resolves bounds and depth in one reverse pass. The
remaining FlowLayout phases gained per-iteration checks, and a wall clock
ceiling ends a render that outlasts its cooperative checks as a limit
fault instead of an endless "rendering" state.
Unsupported diagram types now read as a muted note rather than an error.
classDiagram, stateDiagram and friends are valid mermaid this engine does
not draw, and marking each one red reported working markdown as broken.
What
mermaidandmmd).Screenshot
Why
JetBrains users can now read Mermaid diagrams directly in Kilo conversations without copying code fences into external tools. Keeping the renderer in the frontend avoids CLI/server coupling and lets the plugin support diagrams in split-mode remote development without JCEF.
Notes