VS Code Apex + LWC Debug Helper
A Visual Studio Code extension that accelerates Salesforce Apex and Lightning Web Component (LWC) development workflows — instant debug log insertion, bulk log cleanup, smart selection, Salesforce CLI deploy, and Jest test execution, all from the editor context menu or keyboard shortcuts.
Features
1. Quick Debug Logging (Apex, JS/TS, Java)
Insert a TEMP_LOG debug statement on the line below the selected variable (or the word at the cursor when nothing is selected). Each inserted line embeds the file name and line number for easy log scanning.
| Language |
Output format |
| JS / TS |
console.log('TEMP_LOG[42] myFile> myVar:', myVar) |
Apex (.cls) |
System.debug('TEMP_LOG[42] myFile> myVar:' + myVar) |
Java (.java) |
System.out.println("[42] myFile> myVar :"+ myVar) |
- Add Log !!! — log label + variable value
- Add Log No Param !!! — log label only (no variable value printed)
- Add JSON Log !!! — pretty-print serialised log
- JS/TS:
JSON.stringify(myVar, null, 2)
- Apex:
JSON.serializePretty(myVar)
Multi-cursor support: all three commands work across multiple simultaneous selections. Insertions are applied bottom-to-top to keep line numbers stable. After insertion, the newly added lines are automatically highlighted and revealed in the editor.
Auto word detection: if no text is selected, the extension selects the word under the cursor before inserting the log.
Indentation-preserving: inserted lines match the leading whitespace of the source line.
2. Bulk Log Operations
- Add All Log !!! — uses the Babel AST pipeline to parse the entire active JS/TS file and inject a
console.log at the entry of every function — named functions, arrow functions, class methods, object methods, and getters. Handles JSX, TypeScript, decorators, class properties, and private class members. The inserted log includes the function name and source line number.
- Remove Log !!! — scans every line of the active file and deletes all lines containing
TEMP_LOG in one atomic edit, working bottom-to-top to avoid line-shift side effects.
3. Salesforce CLI Deploy
Deploy !!! opens (or reuses) a persistent terminal named DeployTerminal and runs:
sf project deploy start --ignore-conflicts --source-dir "<activeFile>"
Available in the context menu for: .js, .ts, .cls, .java, .xml, .html, .page, .css.
4. Jest Test Runner
Jest Test it !!! scans backwards from the cursor to find the nearest it('...') or describe('...') label, then runs:
node_modules/.bin/jest "<file>" -t "<testName>"
If no test block is found above the cursor, the entire test file is run. Uses the same shared DeployTerminal.
5. Dot-Chain Selection
Two commands for extending the current selection across dot-chained identifiers:
- Extend Forward Selection !!! — appends
.nextToken to the right edge of the selection
- Extend Backward Selection !!! — prepends
previousToken. to the left edge of the selection
If there is no active selection, the word at the cursor is selected first.
6. Smart Select
Smart Select performs intelligent, context-aware selection on the current line and copies the result to the clipboard:
| Cursor context |
Behaviour |
Right edge is an open bracket ( [ { < |
Expand forward to the matching close bracket, respecting nesting depth |
Left edge is a close bracket ) ] } > |
Expand backward to the matching open bracket |
Edge is a quote ' or " |
Select the content within the matching quote pair |
| Otherwise |
Extend right to the next word boundary: camelCase transition, _, -, space, ,, ., or bracket |
When the right edge reaches the end of the line, the algorithm falls back to smartExtendLeft, which walks backward using the same boundary rules. Each invocation copies the result to the clipboard and flashes the selected text in the VS Code status bar.
7. Copy File Path
Copy Filename !!! copies the full absolute path of the active file to the system clipboard and shows a confirmation notification.
Commands & Context Menu
All commands are available via the Command Palette (Cmd/Ctrl+Shift+P). Most also appear in the editor right-click context menu, filtered by file extension:
| Command |
Title |
Menu group |
File types |
insertLogExtension.runScript |
Add Log !!! |
0_LOG |
.js, .ts, .cls |
insertLogWithoutParamExtension.runScript |
Add Log No Param !!! |
0_LOG |
.js, .ts, .cls |
insertJSONLogExtension.runScript |
Add JSON Log !!! |
0_LOG |
.js, .ts, .cls |
extension.addAllConsoleLogs |
Add All Log !!! |
0_LOG |
.js, .ts |
extension.removeTempLogLines |
Remove Log !!! |
0_LOG |
.js, .ts, .cls |
deployExtension.runScript |
Deploy !!! |
navigation |
.js, .ts, .cls, .java, .xml, .html, .page, .css |
jestTestExtension.runScript |
Jest Test it !!! |
navigation |
.js, .ts |
extension.copyFileName |
Copy Filename !!! |
navigation |
all |
extension.highlightAndCopy |
Smart Select |
navigation |
all |
extension.extendSelectionWithWord |
Extend Forward Selection !!! |
— |
— |
extension.extendSelectionBackwardWithWord |
Extend Backward Selection !!! |
— |
— |
Tech Stack
| Layer |
Technology |
| Source language |
TypeScript 5.x |
| Compiled output |
JavaScript (ES2022) |
| Module system |
Node16 (CommonJS) |
| Runtime host |
Node.js (embedded in VS Code ≥ 1.75) |
Runtime dependencies
| Package |
Version |
Purpose |
@babel/parser |
7.24 |
Parse JS/TS/JSX/TSX source into AST |
@babel/traverse |
7.24 |
Walk and mutate AST nodes |
@babel/generator |
7.24 |
Serialise mutated AST back to source |
@babel/types |
7.24 |
AST node type guards and builders |
| Tool |
Purpose |
typescript / tsc |
Transpile .ts → out/*.js |
ESLint + @typescript-eslint |
Static analysis and style enforcement |
Mocha + @vscode/test-cli |
Integration tests inside VS Code Extension Host |
@vscode/vsce |
Package and publish the extension |
External CLI integrations
| Tool |
Integration |
Command |
Salesforce CLI (sf) |
VS Code Terminal API |
sf project deploy start --ignore-conflicts --source-dir <file> |
| Jest |
VS Code Terminal API |
node_modules/.bin/jest <file> [-t <testName>] |
Architecture
User Input (Command Palette / Context Menu / Keybinding)
|
v
VS Code Extension API (activation: onLanguage:apex, onCommand:*)
|
v
Command Dispatcher (src/extension.ts — activate())
|
+----------+--------------------+------------------+
| | | |
v v v v
Text Editor Babel AST Pipeline Terminal Manager Clipboard API
Operations (parser/traverse/ (sf CLI / Jest)
(multi- generator)
cursor)
| | |
v v v
Document Code Process
Edits Generation Output
Key design decisions
| Decision |
Rationale |
Single-file command hub (extension.ts) |
Keeps activation surface small; all commands co-located for easy discovery |
| Babel AST for bulk function logging |
Reliable parsing of complex JS/TS/JSX/TSX syntax; handles decorators, class properties, getters — no regex fragility |
| VS Code Terminal API for CLI tools |
Reuses existing Salesforce CLI and Jest installations; no subprocess management needed |
| Persistent shared terminal |
One DeployTerminal is reused across deploy and Jest invocations, keeping terminal noise low |
Lazy activation (onCommand, onLanguage:apex) |
Extension loads only when needed, minimising VS Code startup cost |
| Bottom-to-top multi-cursor insertion |
Inserting from the last selection upward keeps earlier line numbers stable across edits |
Module breakdown
src/extension.ts — central hub, exports activate() / deactivate(). Contains all command handlers: log insertion, log removal, bulk AST logging, deploy, Jest, selection helpers, Smart Select.
src/logger.ts — TypeScript compiler API utility for single-function log insertion (cursor-position based, used for targeted in-function logging).
For full design details see ARCHITECTURE.md.
Development
Prerequisites
- Node.js 18+
- VS Code 1.75+
Install dependencies
npm install
Compile
npm run compile # one-shot build → out/
npm run watch # incremental watch mode
Run in development
- Open this repo in VS Code.
- Press
F5 to launch an Extension Development Host window.
- Open an Apex (
.cls) or JS/TS file.
- Right-click in the editor or open the Command Palette (
Cmd/Ctrl+Shift+P) to run any command.
Run tests
npm test
Package as VSIX
npm run package
# outputs: apex-lwc-debug-helper-<version>.vsix
Install the generated .vsix locally via Extensions: Install from VSIX... in the Command Palette.
Publish to the Marketplace
npx vsce login <publisher> # one-time, requires an Azure DevOps Personal Access Token
npx vsce publish
See the VS Code publishing guide for creating a publisher and PAT.
Notes
- Best used in Salesforce projects containing Apex classes (
.cls) and LWC JS/TS files.
- Deploy and Jest commands require the relevant CLI tools installed and available in
PATH.
- The
TEMP_LOG marker is intentionally distinctive — use Remove Log !!! to strip all temporary logs before committing.
License
MIT