How furudean/vscode-renpy-warp works
Project type and purpose
• This is a Visual Studio Code extension (“Ren’Py Launch and Sync”) written in TypeScript whose purpose is to let you launch, warp, and sync a Ren’Py visual-novel game from inside VS Code. It registers commands, spawns a Ren’Py process, and keeps the editor and game in sync via an IPC/RPE protocol.
Main components
A. VS Code UI & API
– Command Palette, Editor Context Menu, Explorer Context Menu, Status Bar, Gutter Decorations
– VS Code Extension Host (the runtime for your extension)
B. Extension Modules (inside the Extension Host)
– Activation (extension.ts)
– Commands Registry (lib/commands.ts)
– Configuration (lib/config.ts)
– Handlers (lib/handlers.ts)
– Process Management (lib/process/manager.ts, lib/process/index.ts, lib/sh.ts)
– Launch Logic (lib/launch.ts)
– RPE Protocol Adapter (renpy_warp.rpe.py, lib/rpe.ts)
– Socket Communication (lib/socket.ts)
– Follow-Cursor Logic (lib/follow_cursor.ts)
– Decorations & Status Bar (lib/decoration.ts, lib/status_bar.ts)
– Label Navigation (lib/label.ts)
– Logging (lib/log.ts)
– Onboarding Prompt (lib/onboard.ts)
– Path Utilities (lib/path.ts)
– Window-Focus Utilities (lib/window.ts)
C. External Ren’Py Process
– Ren’Py SDK launch (stdin/stdout or IPC)
– RPE‐injected Python helper (renpy_warp.rpe.py)
Relationships and data flows
1. User triggers a command via VS Code UI → VS Code API calls your Command Registry
2. Command Registry → dispatches to Handlers → consults Config → decides strategy
3. Handler calls Launch or Process Manager → spawns Ren’Py process (shell/sh.ts)
4. If using “Update Window” or “Follow Cursor,” extension opens a socket to the RPE helper in the game process
5. Socket ↔ RPE adapter exchange JSON messages (“warp_to_line”, “current_line”)
6. Incoming updates flow back to Handlers → update Editor via VS Code API (move cursor, decorate gutter, update status bar)
7. Logging and onboarding may run in parallel whenever needed
Architectural patterns & design principles
• Command–Handler pattern: each VS Code command is wired to a handler that encapsulates logic.
• Modular layering: configuration → command dispatch → process management → IPC → UI update.
• Single responsibility: each module focuses on one concern (e.g., socket.ts only manages the socket, rpe.ts only formats protocol messages).
• Event-driven IPC: the RPE protocol uses a socket, with callbacks registered on lib/socket.ts.