This guide explains how to debug both the VS Code extension and UI package with breakpoints in VS Code.
- VS Code installed
- Node.js and npm installed
- All dependencies installed (
npm installin root directory) - Initial build completed (
npm run buildin root directory)
This method runs UI components in a Node.js environment, allowing you to set breakpoints in VS Code:
-
Use "Debug UI in Node + Extension" compound configuration
- This starts three processes:
- UI debug server (Node.js with debugging)
- UI dev server (for the webview)
- VS Code extension (with debugging)
- This starts three processes:
-
Set breakpoints in UI code
- Open any
.tsxfile inpackages/ui/src/ - Click in the gutter to set breakpoints
- Breakpoints will hit when the debug entry point runs your components
- Open any
-
Debug entry point
- The debug configuration uses
src/debug-entry.tsx - This file runs your UI components in Node.js
- Modify this file to test different components/scenarios
- The debug configuration uses
For debugging UI in its actual webview environment:
-
Use "Debug Both (Separate Terminals)" configuration
- Starts UI dev server (without Node debugging)
- Starts VS Code extension with debugging
-
Debug using Chrome DevTools
- Right-click in webview → Inspect
- Use Sources tab for breakpoints
- Console for logs
- Select "Debug UI in Node + Extension" from debug dropdown
- Press F5
- Three terminals will open:
- Terminal 1: UI debug server (Node.js)
- Terminal 2: UI dev server (http://localhost:3000)
- Terminal 3: VS Code extension host
- Set breakpoints:
- Extension code: Any
.tsfile inpackages/vscode/src/ - UI code: Any
.tsxfile inpackages/ui/src/
- Extension code: Any
- In the debug VS Code window:
- Run "Code Charter: Generate Diagram"
- Extension breakpoints hit immediately
- UI breakpoints hit when components render
- Select "Debug Both (Separate Terminals)"
- Press F5
- Debug extension with breakpoints
- Debug UI with Chrome DevTools
The UI debug configuration:
- Runs
tsx --inspectto execute TypeScript directly - Uses
debug-entry.tsxto render components in Node - Allows VS Code debugger to attach
- Supports hot reload with
tsx watch
The extension debug configuration:
- Launches new VS Code instance
- Automatically enables dev mode
- Loads UI from dev server
Edit packages/ui/src/debug-entry.tsx to test specific scenarios:
// Test a specific component
import { YourComponent } from './components/your_component';
// Add test data
const testProps = {
// your props here
};
// Render and debug
const html = renderToString(<YourComponent {...testProps} />);-
UI debugging in Node.js:
- Great for testing component logic
- Can't test browser-specific features (DOM events, etc.)
- Use for algorithmic debugging
-
Webview debugging:
- Tests actual runtime environment
- Use for UI interaction debugging
- Chrome DevTools provides full debugging
-
Hot reload:
- Both methods support hot reload
- Changes appear instantly
-
Console output:
- Node debugging: Output in VS Code terminal
- Webview: Output in Chrome DevTools console
Normal - the debugger is attaching. Wait a moment.
- Ensure you're using "Debug UI in Node + Extension"
- Check that
debug-entry.tsximports your component - Verify breakpoint is in code that executes
lsof -ti:3000 | xargs kill -9Run npm install in the packages/ui directory to install tsx.
- Open
packages/ui/src/components/code_charter_ui.tsx - Set breakpoint in the
CodeCharterUIcomponent - Run "Debug UI in Node + Extension" (F5)
- Watch breakpoint hit in the Node debug terminal
- Open debug VS Code window
- Run "Code Charter: Generate Diagram"
- See UI render with your debugging insights!
This setup provides full debugging capabilities for both the extension and UI code with breakpoints directly in VS Code.