feat(jetbrains): render all Mermaid diagram types in chat - #13569
Merged
Conversation
Extend the in-process Kotlin Mermaid engine to cover every diagram type Type can detect, not just flowcharts and sequence diagrams: class, state, ER, gantt, pie, user journey, quadrant, requirement, git graph, C4 (all five headers), mindmap, timeline, sankey, XY chart, block, packet, kanban, architecture, radar, and treemap. Each type gets its own parser + layout file under mermaid/, sharing a new Sheet (mark collection/normalization), Layered (deterministic graph layout for the class/state/er/requirement/C4 family), Scopes (composite/boundary edge re-anchoring), Axis (chart ticks), and Lex (bracket/quote-aware tokenizing) so the per-type files stay small. The Art model gains a Sector mark for pie wedges plus optional tone/soft fields for categorical chart colors, and Head gains UML/ER arrow variants (Triangle, Diamond, Crow, Bar, ...). Existing marks keep their prior toString() output when the new fields are unset, so flowchart/sequence snapshots are unchanged. Unsupported types (zenuml, venn, ...) keep the existing soft "unsupported" note over the source rather than an error.
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (9 files)
Previous Review Summary (commit 57b0d10)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 57b0d10)Status: 8 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)CRITICAL
WARNING
Files Reviewed (64 files)
Reviewed by grok-4.6 · Input: 225K · Output: 16.5K · Cached: 442.2K Review guidance: REVIEW.md from base branch |
Addresses PR review. Three of these were unrecoverable rather than
merely wrong: the loops run outside any suspend point, so the render
timeout could not break them, and a StackOverflowError is an Error
that Diagrams.draw's catch(Exception) never converts to Out.Err.
- Packet: bit indexes are parsed with toIntOrNull and capped, and row
splitting checks cancellation. A field ending at Int.MAX_VALUE used
to overflow the row arithmetic into an endless loop.
- Scopes.open rejects nesting a scope inside itself and returns a
syntax error; StateDg and C4Dg surface that instead of looping
(state) or recursing to a StackOverflowError (C4 boundary). C4 also
rejects duplicate element/boundary ids that caused double-draws.
- Layered lays an empty scope out as an empty frame instead of
throwing, so 'state Empty { }' renders.
- Layered iterates rows in rank order. They are keyed by rank but
filled in declaration order, so 'Circle --|> Shape' drew the child
above the parent.
- Sankey returns Fault.Limit when unique nodes exceed the cap instead
of a blank successful scene.
- Radar orders min/max before clamping, so all-negative curves no
longer hand coerceIn an empty range.
- ScenePainter resets to a solid stroke before drawing heads, so
outline heads on dashed edges (class realization, dashed ER) stop
rendering as broken glyphs.
Each fix has a regression test in EnginesTest.
lambertjosh
approved these changes
Aug 30, 2026
5 tasks
This was referenced Aug 31, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue
No issue filed. Follow-up to a chat request asking for JetBrains support of all Mermaid diagram types; this PR was scoped and implemented directly from that conversation.
Context
The JetBrains plugin's in-process Kotlin Mermaid engine (
packages/kilo-jetbrains/frontend/.../ui/diagram/) only rendered flowcharts and sequence diagrams. Every other diagram type — including onesTypealready detected (class, state, ER, gantt, pie) — fell back to a soft "unsupported diagram" note over the raw source. JCEF/webview rendering is off-limits for this plugin (breaks remote dev split mode), so this had to be native Swing/Kotlin.This PR extends the engine to draw all 22 Mermaid diagram types natively: class, state, ER, gantt, pie, user journey, quadrant, requirement, git graph, C4 (all five headers), mindmap, timeline, sankey, XY chart, block, packet, kanban, architecture, radar, and treemap.
Implementation
click,UpdateElementStyle, ...) or silently skipped otherwise — matching how the existingFlow/Seqparsers already behave.Art.kt): aMark.Sectorfor pie/radar wedges, and optionaltone/softfields on fill-bearing marks for categorical chart colors and translucent fills. Existing marks keep their oldtoString()when these are unset, so flowchart/sequence snapshot tests are untouched.Headgained UML/ER arrow variants (Triangle,Diamond,DiamondFilled,Crow,Bar,CircleOpen).mermaid/:Sheet(mark collection, origin normalization, text-fit/word-wrap),Layered(a small deterministic graph layout — longest-path ranks with cycle detection, one barycenter sweep each way — reused by class/state/ER/requirement/C4 instead of touchingFlowLayout, so flowchart geometry is guaranteed unchanged),Scopes(LCA-based edge re-anchoring for composite states and C4 boundaries),Axis(nice-number chart ticks),Lex(bracket/quote-aware arg splitting and tokenizing).Mermaid.kt. Notable tradeoffs: mindmap uses a tidy right-growing tree instead of mermaid's radial layout; treemap uses alternating slice/dice instead of squarified; sankey bands are smoothstep curves sampled into aPolyrather than a new curve primitive; gantt date math is pinned to UTC/Locale.ROOTfor determinism.C4Context/Container/Component/Dynamic/Deployment) through one renderer.ensureActivebetween phases/lines), and respects the existingSpec.limitsnode/edge caps.Screenshots / Video
How to Test
Manual/local verification
./gradlew typecheckfrompackages/kilo-jetbrains/— passes../gradlew testfrompackages/kilo-jetbrains/— full suite passes, including the extended diagram test suite (ConformanceTest,InvariantTest,TypeTest,SerializeTest,ScenePainterTest, the newEnginesTestwith ~30 targeted cases per diagram family, andMdViewDiagramTest)..mmdfile per new diagram type underfrontend/src/test/resources/diagram/, taken verbatim from Mermaid's documented examples, run throughConformanceTest's four contracts (non-empty finite scene, correct detected type, deterministic rendering, no empty text labels) andInvariantTest's bounds/no-overlap checks under both fake and real AWT font metrics.Reviewer test steps
packages/kilo-jetbrains/, run./gradlew runIde.```mermaidfences, one per diagram type (class, state, erDiagram, gantt, pie, journey, quadrantChart, requirementDiagram, gitGraph, C4Context, mindmap, timeline, sankey-beta, xychart-beta, block-beta, packet-beta, kanban, architecture-beta, radar-beta, treemap-beta).Blocked checks and substitute verification
runIde) myself in this environment — no display/VNC available in the dev container. Substitute verification: the full Gradle test suite (parse, layout, invariant, serialization, and scene-painter tests). A human reviewer ranrunIdelocally and captured the screenshot table above.Checklist
Get in Touch