Skip to content

[mpp-idea] Refactor IdeaSketchRenderer to reuse LangSketch business logic from core module #25

@phodal

Description

@phodal

Overview

Refactor IdeaSketchRenderer in mpp-idea module to reuse business logic from core module's LangSketch components while keeping the Compose UI implementation.

Background

  • mpp-idea: Uses Compose for Desktop (Jewel) - currently only static rendering
  • core: Uses Swing (JComponent) - full functionality (Apply/Reject/Repair/View Diff, etc.)

Approach: Solution B

Reimplement UI in Compose while reusing core's business logic to avoid SwingPanel z-index issues.

LangSketch Components to Migrate

Core Module

Component Language Priority
CodeHighlightSketch All code P0
DiffLangSketch diff, patch P0
SingleFileDiffSketch - P0
PlanLangSketch plan P1
HtmlHighlightSketch html P1
WebpageLangSketch html (full page) P2
MarkdownPreviewHighlightSketch markdown P2
OpenAPISketch yaml, yml P3

Extension Modules

Component Module Language Priority
TerminalLangSketch ext-terminal bash, shell P1
MermaidSketch ext-mermaid mermaid P2
PlantUmlSketch ext-plantuml plantuml, puml P3
GraphvizSketch ext-diagram dot, graphviz P3
GoLangPlaygroundSketch goland go P3

Reusable Business Logic

Logic Location Method
Diff parsing mpp-core DiffParser.parse()
Patch apply core PatchProcessor.applyPatch()
Patch repair core DiffRepair.applyDiffRepairSuggestion()
Diff dialog core showSingleDiff()
Plan parsing core MarkdownPlanParser.parse()
Shell safety core ShellSafetyCheck.checkDangerousCommand()

Implementation Phases

Phase 1: IdeaDiffActions (P0) ✅ COMPLETED

  • Create IdeaDiffActions.kt with accept/reject/viewDiff/repair methods
  • Update IdeaDiffRenderer.kt with action buttons
  • Reuse PatchProcessor, DiffRepair, showSingleDiff()

Files created/modified:

  • mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/renderer/sketch/actions/IdeaDiffActions.kt
  • mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/renderer/sketch/IdeaDiffRenderer.kt
  • mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/renderer/sketch/IdeaSketchRenderer.kt

Phase 2: IdeaCodeActions (P1)

  • Create IdeaCodeActions.kt with copy/insert/newFile methods
  • Update IdeaCodeBlockRenderer.kt with toolbar

Phase 3: IdeaPlanRenderer (P1)

  • Create IdeaPlanRenderer.kt
  • Reuse MarkdownPlanParser.parse()
  • Support Pin/Compress features

Phase 4: IdeaTerminalRenderer (P2)

  • Create IdeaTerminalRenderer.kt
  • Reuse ShellSafetyCheck
  • Depends on ext-terminal module

Phase 5: Diagram Enhancements (P3)

  • Enhance existing IdeaMermaidRenderer
  • Add PlantUML/Graphviz support (optional)

Architecture

mpp-idea (Compose UI)
  ├── IdeaSketchRenderer
  │   ├── IdeaDiffRenderer → IdeaDiffActions ✅
  │   ├── IdeaCodeBlockRenderer → IdeaCodeActions
  │   ├── IdeaPlanRenderer → IdeaPlanActions
  │   └── IdeaTerminalRenderer → IdeaTerminalActions
  ↓
core (Business Logic)
  ├── PatchProcessor
  ├── DiffRepair
  ├── MarkdownPlanParser
  └── ShellSafetyCheck
  ↓
mpp-core (Cross-platform)
  ├── DiffParser
  └── DiffUtils

Notes

  1. Use DialogWrapper for complex Swing components to avoid z-index issues
  2. Use Jewel's IconButton for action buttons
  3. Maintain feature parity with core module Sketches

Related Files

  • mpp-idea/src/main/kotlin/cc/unitmesh/devins/idea/renderer/sketch/IdeaSketchRenderer.kt
  • core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/LangSketch.kt
  • core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/patch/DiffLangSketch.kt
  • core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/PlanLangSketch.kt
  • docs/refactor-idea-sketch-renderer.md

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions