How microsoft/vscode-mermaid works
Project type and purpose
• This is a VS Code extension written in TypeScript.
File structure
Top-level directories and files:
• build/ → CI pipelines (Azure YAML files for pre-release, stable, autobaselining)
• src/ → extension source code
• / → logic for the outline-view webview
• commands.ts, extension.ts → VS Code activation, command registration
• codeLensProvider.ts → in-editor code lens hooks
• groqHandler.ts → optional groq API calls
• media/ → CSS/JS assets for webviews
• assets/ → demo GIFs used in README
• webpack.config.js, tsconfig.json → build configuration
• .config/, package.json, etc. → standard extension metadata and settings
README for additional insights
• There’s an experimental groq integration behind a setting and stored API key.
Main components and interactions
a. Components:
• VS Code Host
• Extension Host Process
– Activation & lifecycle (extension.ts)
– Command Handlers (commands.ts)
– Chat Participant Service (src/chat/*)
– Outline Service (src/outline/*)
– CodeLens Provider
– groq API Client
• GitHub Copilot Chat Service (external)
• groq API Service (external, optional)
• Webviews
– Outline View Panel
• File System & User Settings (for storing the groq key, extension settings)
b. Relationships & Data Flow:
1. User invokes a slash command or clicks the outline view refresh button.
2. The Extension Host routes the request to either the Chat Participant or Outline Service.
3. Chat Participant Service calls GitHub Copilot Chat API, passing the user prompt + context.
– Optionally the service invokes groqHandler to pre-process the code outline.
5. Extension processes the DSL (mermaidHelpers.ts), creates/updates a DiagramDocument.
8. Settings and secrets (groq key) are read from VS Code’s secret storage.
c. Architectural Patterns & Design Principles:
• Extension (Plugin) Architecture: clear separation between VS Code APIs and your services.
• Command Pattern: commands.ts registers named commands that delegate to handlers.
• MVC-like Webviews: DiagramDocument (model), webview panels (view), extension code (controller).
• Facade over External APIs: chatParticipant.ts abstracts the GitHub Copilot Chat Participant API; groqHandler.ts abstracts groq calls.
d. Key technologies/frameworks:
• VS Code Extension API (vscode module)
• GitHub Copilot Chat Participant API
• webview panels (HTML/CSS/JS)
• TypeScript, webpack