Development Guide
Prerequisites
- Node.js 16+ and npm
- Visual Studio Code 1.94.0+
- Prometheus instance running locally (for testing)
Setup
1. Clone and Install
bash
git clone https://github.com/theaniketraj/vitals.git
cd vitals
npm install2. Start Prometheus (Optional)
For full development experience, run Prometheus locally:
bash
docker run -p 9090:9090 prom/prometheus3. Build
bash
npm run buildBuilds both extension and webview bundles.
4. Watch Mode
bash
npm run watchStarts webpack in watch mode for hot reloading during development.
Project Structure
bash
vitals/
├── src/ # Extension source
│ ├── extension.ts # Entry point
│ ├── vitalsView.ts # Webview management
│ ├── api.ts # Prometheus API client
│ ├── data/ # Data processing
│ ├── utils/ # Utilities
│ └── test/ # Unit tests
├── webview/ # React frontend
│ ├── src/
│ │ ├── App.tsx
│ │ ├── components/
│ │ ├── hooks/
│ │ └── index.tsx
│ └── tsconfig.json
├── webpack.config.js # Extension webpack config
├── webpack.config.webview.js # Webview webpack config
├── package.json
└── Docs/ # DocumentationDevelopment Workflow
Running the Extension
- Open project in VS Code
- Press
F5to launch Extension Development Host - Extension loads in new window
- Open Command Palette (Ctrl+Shift+P) and run "Open Vitals"
Hot Reload
When using npm run watch:
- Extension changes: Reload extension (Ctrl+R in extension host)
- Webview changes: Auto-reload in panel
Debugging
Extension Debugging
VS Code has built-in debugging for extension code. Set breakpoints in src/*.ts files.
Webview Debugging
- In webview panel, right-click and select "Inspect"
- DevTools opens for webview debugging
Adding Features
New Prometheus Query
- Add query handler in
vitalsView.ts:
typescript
case 'fetchNewData':
const api = new PrometheusApi(prometheusUrl);
const data = await api.query(message.query);
this._panel.webview.postMessage({ command: 'updateNewData', data });
break;- Add webview message sender in React hook:
typescript
vscode.postMessage({ command: "fetchNewData", query: "your_query" });- Handle response in component
New UI Component
- Create component in
webview/src/components/ - Import in parent component
- Pass data via props
Testing
bash
npm run testRuns Jest test suite.
Writing Tests
Tests located in src/test/:
typescript
// api.test.ts
describe("PrometheusApi", () => {
it("should fetch alerts", async () => {
const api = new PrometheusApi("http://localhost:9090");
const alerts = await api.getAlerts();
expect(alerts.status).toBe("success");
});
});Configuration
VS Code Settings
Add to workspace .vscode/settings.json:
json
{
"vitals.prometheusUrl": "http://localhost:9090"
}Webpack Config
webpack.config.js- Extension bundlewebpack.config.webview.js- React webview bundle
Both use TypeScript loader and handle CSS/SCSS.
Logging
Use console.log() for extension debugging:
typescript
console.log("🚀 Vitals extension activated");
console.error("Error message", error);View logs in:
- Extension: Debug Console in VS Code
- Webview: DevTools console
Publishing
Prerequisites for Publishing
- VSCode Marketplace account
- Personal Access Token (PAT)
Build for Release
bash
npm run vscode:prepublishOptimizes bundles for production.
Publish to Marketplace
bash
vsce publishor
bash
vsce publish 0.3.0For manual publishing, see Publishing Extensions.
Automated GitHub Release
We use GitHub Actions to automate releases. To create a new release with an attached .vsix file:
- Update the version in
package.json. - Push a new tag starting with
v(e.g.,git tag v0.3.0 && git push origin v0.3.0). - The workflow will automatically build the extension and create a release on GitHub.
Common Issues
Build Failures
Clear cache and reinstall:
bash
rm -rf node_modules dist webview/build
npm install
npm run buildWebview Blank
Check:
- Prometheus URL is correct in settings
- Prometheus is running
- Webview DevTools for errors
Metrics Not Showing
- Verify Prometheus is reachable
- Check PromQL query syntax
- View extension debug logs
Performance Tips
- Lazy load components in webview
- Memoize expensive computations in React
- Debounce metric queries
- Use React DevTools for profiling
Architecture Decisions
- VS Code Webview: Built-in, no additional dependencies
- React: Rich UI components and state management
- Axios: Simple HTTP client for Prometheus
- Webpack: Industry standard bundler
- TypeScript: Type safety and better DX
See System Architecture for details.