Development Guide
March 17, 2026 · View on GitHub
This guide is for developers who want to contribute to the Virgil extension.
Development Setup
Prerequisites
- Node.js (v18 or later)
- npm
- VS Code or Cursor (for testing)
Initial Setup
For Contributors (Fork-Based Workflow)
-
Fork the repository on GitHub (click the "Fork" button)
-
Clone your fork:
git clone https://github.com/YOUR_USERNAME/virgil.git cd virgil -
Add upstream remote (to sync with the main repository):
git remote add upstream https://github.com/ealt/virgil.git
For Maintainers (Direct Access)
-
Clone the repository:
git clone https://github.com/ealt/virgil.git cd virgil -
Install dependencies:
npm install -
Compile the extension:
npm run compile
Development Workflow
-
Watch mode: Run the TypeScript compiler in watch mode to automatically recompile on changes:
npm run watch -
Testing:
- Open the
virgilfolder in VS Code/Cursor - Press
F5to launch a new Extension Development Host window - In the new window, open a workspace with a walkthrough file (
.walkthrough.jsonat root or any.jsoninwalkthroughs/directory) to test
- Open the
-
Packaging: Create a
.vsixfile for distribution:npx vsce package --allow-missing-repository
Project Structure
virgil/
├── package.json # Extension manifest (activation, commands, views)
├── tsconfig.json # TypeScript configuration
├── README.md # User-facing overview and usage
├── docs/
│ ├── schema.md # Walkthrough JSON schema documentation
│ └── development.md # This file
├── media/
│ └── panel.css # Webview styles
├── scripts/
│ ├── refresh-extension.sh # Rebuild + install helper
│ └── setup-git-hooks.js # Git hook setup
├── walkthroughs/ # Example walkthrough JSON files
├── src/
│ ├── extension.ts # Entry point, activation, command registration
│ ├── types.ts # Walkthrough interfaces and tree utilities
│ ├── WalkthroughProvider.ts # Tree view provider and step navigation
│ ├── StepDetailPanel.ts # Webview panel for step details
│ ├── HighlightManager.ts # Code highlighting/decorations
│ ├── DiffContentProvider.ts # virgil-git:// virtual document provider
│ ├── MarkdownHighlightProvider.ts # virgil-md-preview:// provider
│ ├── DiffResolver.ts # Base commit resolution for diffs
│ └── markdownParser.ts # Markdown walkthrough conversion
└── out/ # Compiled JavaScript (generated)
Architecture Overview
Virgil is a VS Code extension that provides interactive code walkthroughs. The extension activates when it detects .walkthrough.json files in the workspace root, and discovers walkthroughs from both the root (.walkthrough.json) and the walkthroughs/ directory (any .json files). It provides a tree view, webview panel, and code highlighting.
Key Components
extension.ts
The main entry point that:
- Activates when
*.walkthrough.jsonfiles are detected at workspace root - Discovers walkthroughs from both root (
.walkthrough.json) andwalkthroughs/directory (any.jsonfiles) - Initializes core components (HighlightManager, WalkthroughProvider)
- Registers commands (start, next, prev, refresh, select, etc.)
- Sets up file watching for walkthrough files in both locations
- Coordinates navigation and UI updates
- Handles Markdown to JSON conversion via file picker
WalkthroughProvider.ts
Implements TreeDataProvider to:
- Load and parse walkthrough JSON files
- Discover walkthroughs from root (
.walkthrough.json) andwalkthroughs/directory (any.jsonfiles) - Manage current step state
- Build the sidebar tree view
- Handle Git operations (commit checking, checkout)
- Manage comments (add, edit, delete, save to file)
StepDetailPanel.ts
Creates and manages the webview panel that:
- Displays step title, body (with Markdown rendering), and location
- Shows metadata on the first step
- Renders comments with Markdown support
- Provides Previous/Next navigation buttons
- Handles comment actions and submission
- Communicates with extension via
postMessage
HighlightManager.ts
Manages code decorations to:
- Highlight line ranges in editors
- Track active decorations per file
- Clear decorations when navigating
- Use VS Code's decoration API with custom styling
types.ts
Defines TypeScript interfaces:
Walkthrough,WalkthroughStep,Comment,Repository- Utility functions:
parseLocation(),normalizeRemoteUrl()
How It Works
Activation Flow
- Extension activates on
workspaceContains:*.walkthrough.json(detects root.walkthrough.jsonfiles) extension.tsfinds walkthrough files in two locations:.walkthrough.jsonat workspace root- Any
.jsonfiles inwalkthroughs/directory
WalkthroughProviderloads the first available walkthrough- Tree view is registered and displayed in sidebar
- If walkthrough exists, first step is automatically shown
- Users can select different walkthroughs via "Select Walkthrough" command, which also allows selecting Markdown files for conversion
Navigation Flow
- User clicks step in sidebar OR uses keyboard shortcut OR clicks panel button
- Command handler calls
WalkthroughProvider.goToStep(index) showCurrentStep()function:- Clears previous highlights
- Parses step location
- Opens file in editor
- Applies highlights via
HighlightManager - Updates
StepDetailPanelwith step content
File Watching
FileSystemWatchermonitors both:.walkthrough.jsonat workspace rootwalkthroughs/*.jsonfiles
- On create: Shows notification, refreshes provider
- On change: Refreshes provider
- On delete: Clears highlights, updates context
Comment System
- User adds, edits, or deletes a comment in the webview
- Webview sends the matching comment command via
postMessage - Extension command handler calls the corresponding
WalkthroughProvidermethod - The step's
commentsarray is updated in memory - Walkthrough JSON is saved to disk
- Panel is refreshed to show the latest comment state
Walkthrough Discovery
- Walkthroughs are discovered from two locations:
.walkthrough.jsonat workspace root- Any
.jsonfiles inwalkthroughs/directory
getAvailableWalkthroughs()returns all discovered walkthroughs- Users can select walkthroughs via the "Select Walkthrough" command
- The selection command also allows picking Markdown files, which are converted to JSON and saved to
walkthroughs/directory
Commit Mismatch Detection
- Walkthroughs can specify
repository.commit - Extension compares current HEAD to walkthrough commit
- Shows warning dialog if mismatch detected
- User can checkout the commit or continue anyway
Building and Packaging
Compile
npm run compile
Compiles TypeScript to JavaScript in the out/ directory.
Package
npx vsce package --allow-missing-repository
Creates a .vsix file that can be installed in VS Code/Cursor.
Watch Mode
npm run watch
Continuously compiles TypeScript on file changes. Useful during development.
Testing
Currently, testing is manual:
- Run
npm run watchin terminal - Press
F5in VS Code to launch Extension Development Host - In the new window, open a workspace with a walkthrough file (
.walkthrough.jsonat root or any.jsoninwalkthroughs/directory) - Test features: navigation, highlighting, comments, walkthrough selection, Markdown conversion, etc.
For automated testing, consider adding:
- Unit tests for utility functions (
parseLocation,normalizeRemoteUrl) - Integration tests for walkthrough loading and parsing
- E2E tests for UI interactions
Code Organization
Type Safety
- All walkthrough data structures are typed via
types.ts - JSON parsing uses type assertions with interfaces
- Location strings are parsed and validated
Error Handling
- File operations wrapped in try/catch
- JSON parsing errors show user-friendly messages
- Git operations handle non-Git workspaces gracefully
State Management
WalkthroughProvidermaintains current step indexHighlightManagertracks decorations per fileStepDetailPanelis a singleton (one panel instance)
Webview Communication
- Extension → Webview: HTML content with data embedded
- Webview → Extension:
postMessagewith command objects - Commands:
next,prev,openLocation,submitComment,editComment,deleteComment
Contributing Guidelines
Code Style
- TypeScript with strict mode enabled
- Use async/await for asynchronous operations
- Follow VS Code extension patterns
- Use VS Code API types (
vscodenamespace)
Adding Features
- New Commands: Add to
package.jsoncontributes.commands, register inextension.ts - New UI: Consider tree view items or webview enhancements
- Schema Changes: Update
types.tsanddocs/schema.md - New Files: Follow existing patterns, add to appropriate component
Pull Request Process
For Contributors (Fork-Based)
-
Sync your fork with upstream (before starting):
git checkout main git fetch upstream git merge upstream/main git push origin main -
Create a feature branch in your fork:
git checkout -b feature/my-feature -
Make changes with clear commits (pre-commit hooks will run automatically after
npm install) -
Test thoroughly in Extension Development Host
-
Update documentation if needed
-
Push to your fork:
git push origin feature/my-feature -
Create Pull Request from your fork to the main repository
- Use the PR template
- Describe your changes clearly
- Reference any related issues
-
Address review feedback by pushing more commits to your branch
For Maintainers
- Create a feature branch:
git checkout -b feature/my-feature - Make changes with clear commits
- Test thoroughly in Extension Development Host
- Update documentation if needed
- Push branch and create PR:
git push origin feature/my-feature - Submit PR with description of changes
Areas for Improvement
- Automated testing
- Better error messages
- Walkthrough validation (schema checking)
- Support for multiple walkthroughs simultaneously
- Export/import walkthroughs
- Walkthrough templates
- Better Markdown rendering options
Dependencies
Runtime Dependencies
highlight.js- Syntax highlighting in Markdown code blocksmarked- Markdown parsing and renderingmarked-highlight- Integration of highlight.js with marked
Dev Dependencies
typescript- TypeScript compiler@types/node- Node.js type definitions@types/vscode- VS Code API type definitionseslint- Linting@typescript-eslint/*- TypeScript ESLint plugins