Sequence Diagram Generator (sdg)
Sequence Diagram Generator (display name: Sequence-Diagram-Generator) is a Visual Studio Code extension that helps you generate PlantUML sequence diagrams from C++ source code.
It parses your workspace C++ files, extracts callable declarations, and generates a PlantUML (.puml
) diagram that is rendered to SVG. The extension also provides a live preview panel with pan/zoom and highlights participants when you select them in the editor.
Key features
- Generate a PlantUML sequence diagram for a selected function in a C++ file.
- Pre-render a base diagram and per-participant diagrams (SVG) into
docs/diagrams
.
- Interactive preview panel with zoom, pan and double-click-to-reset.
- Editor decorations that underline participant names and allow quick highlighting of participant-specific diagrams by selecting names in the code.
Commands
sdg.helloWorld
— "Generate Sequence Diagram"
- Run via the Command Palette (Ctrl+Shift+P) and choose "Generate Sequence Diagram". The command generates a diagram for the function at the top of your current selection.
Usage notes:
- Make a non-empty selection in a C++ file (the extension filters for languageId
cpp
) and run the command.
- If nothing is selected, the command will prompt you to select text.
How it works (implementation details)
The extension uses the customastparser
package to find callable declarations and generate PlantUML source via generatePlantUMLAsync
.
The generated .puml
file is written to docs/diagrams/diagram.puml
and the extension invokes PlantUML (bundled as lib/plantuml.jar
) to render SVGs using:
java -jar lib/plantuml.jar -tsvg docs/diagrams/diagram.puml
A preview webview renders the produced SVG (base.svg
by default) and the extension pre-renders one SVG per participant (naming: docs/diagrams/<participant>.svg
).
Requirements
- Java runtime available on PATH (required to run
plantuml.jar
).
lib/plantuml.jar
should exist in the extension folder (the extension expects it at lib/plantuml.jar
).
- A C/C++ compilation database (optional) if you use the helper that generates config for external tools — the extension includes
configSetupAlt.ts
which emits a YAML-style minimal config.
The extension lists the following extension dependency in package.json
:
vstirbu.vscode-mermaid-preview
(optional helper for rendering mermaid if you use that in your workflow).
Configuration and output
- Generated diagrams and intermediate files are written to
docs/diagrams
in the workspace root.
Troubleshooting
- "No text selected" or "Please select some text": ensure you have an active text editor, a non-empty selection, and the file language is set to C++ (
cpp
).
- PlantUML errors / no SVGs produced: verify
java
is on PATH and that lib/plantuml.jar
is present.
- If diagrams are not updating, check and clear
docs/diagrams
— the extension clears the folder before writing a new diagram.puml
.
Development
Install dependencies and build the extension:
# from the extension root
npm install
npm run compile
Run a TypeScript watcher during development:
npm run watch
Run tests (uses the VS Code test runner configured in package.json):
npm test
Linting:
npm run lint
To debug the extension in VS Code, press F5 to open a new Extension Development Host.
Project structure (relevant files)
src/extension.ts
— activation, command registration (sdg.helloWorld
), selection handling and wiring to the parser and preview.
src/presentation.ts
— creates the webview preview, pre-renders SVGs using PlantUML, and applies editor decorations.
src/functionExtractor.ts
— helper (currently minimal) for extracting selected text / functions.
src/configSetupAlt.ts
— helper to generate a minimal YAML config for diagram generation.
lib/plantuml.jar
— expected PlantUML JAR used to render .puml
to .svg
.
Contributing
If you'd like to contribute improvements or fixes, please fork the repository and open a pull request. Ensure TypeScript compiles and tests pass before opening a PR.
License
See package.json
for project metadata. Add a LICENSE file if you wish to specify a license.
If you want, I can also add a short example (sample C++ snippet and the generated PlantUML) or include a screenshot of the preview.