VSCode extension development uses an integrated debugging environment
started via F5. Two configuration files work together:
launch.json defines the debugger parameters, while
tasks.json controls build processes. This configuration
functionally corresponds to Run Configurations in Eclipse.
When pressing F5, VSCode starts a new instance — the Extension Development Host. This process:
The Development Host simulates a productive VSCode installation with the installed extension.
launch.json)The .vscode/launch.json file defines debugging scenarios
analogous to Eclipse Run Configurations:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${workspaceFolder}/npm: watch"
}
]
}type: "extensionHost" specifies the
VSCode extension debugger
"node", "chrome" for
different debugging scenariosrequest: "launch" starts a new
Extension Host instance
"attach" for debugging running
processesargs: Command line parameters for the Extension Host
--extensionDevelopmentPath: directory of the
extension--disable-extensions: disables other extensions for
isolated testingoutFiles: source map paths for TypeScript debugging
outDirpreLaunchTask: build task before debugging start
tasks.json{
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--disable-extensions"
],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "${workspaceFolder}/npm: watch",
"sourceMaps": true,
"smartStep": true,
"skipFiles": ["<node_internals>/**"]
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "${workspaceFolder}/npm: watch"
}
]
}tasks.json)The .vscode/tasks.json file defines build processes
executed before or during debugging:
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "compile",
"problemMatcher": "$tsc",
"group": "build"
}
]
}type: task provider
"npm": executes npm scripts from
package.json"shell": runs shell commands"typescript": direct TypeScript compilationscript: reference to npm script in
package.json
{
"scripts": {
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./"
}
}problemMatcher: parser for compiler output
"$tsc": TypeScript compiler errors"$tsc-watch": TypeScript watch mode"$eslint-stylish": ESLint outputisBackground: task runs continuously in background
presentation: terminal display control
"reveal": "never": terminal stays hidden"reveal": "always": terminal always shown"clear": true: clears terminal before task startThe debugging workflow works as follows:
out/The watch task enables automatic recompilation on code changes:
{
"type": "npm",
"script": "watch",
"isBackground": true,
"problemMatcher": {
"base": "$tsc-watch",
"background": {
"activeOnStart": true,
"beginsPattern": "^\\s*(?:message TS6032:|\\[?\\d{1,2}:\\d{1,2}:\\d{1,2}(?:\\.\\d+)?\\]?) File change detected\\. Starting incremental compilation\\.\\.\\.",
"endsPattern": "^\\s*(?:message TS6042:|\\[?\\d{1,2}:\\d{1,2}:\\d{1,2}(?:\\.\\d+)?\\]?) (?:Compilation complete\\.|Found \\d+ errors?\\.) Watching for file changes\\."
}
}
}VSCode uses source maps for TypeScript debugging:
tsconfig.json
Configuration{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"outDir": "out",
"sourceMap": true,
"strict": true
}
}sourceMap: generates .js.map files for
debugging outDir: target directory for compiled code
target: JavaScript version for Extension Host
Breakpoints can be set in both TypeScript and JavaScript files:
src/extension.tsCtrl+R (Reload Window):
Extension Host Restart:
{
"name": "Run Extension (Multi-root)",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/test-workspace.code-workspace"
]
}{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index",
"${workspaceFolder}/test-fixtures"
],
"env": {
"NODE_ENV": "test"
}
}Breakpoint is grayed out or not hit:
outFiles paths in
launch.jsonoutDir in tsconfig.json// Incorrect: relative paths without workspace root
"outFiles": ["out/**/*.js"]
// Correct: absolute paths with workspace variable
"outFiles": ["${workspaceFolder}/out/**/*.js"]Source maps not available:
sourceMap: false in
tsconfig.json"sourceMap": true{
"dependsOn": ["compile"],
"dependsOrder": "sequence"
}Selective Source Maps:
{
"compilerOptions": {
"sourceMap": true,
"inlineSourceMap": false,
"sourceRoot": "../src"
}
}Incremental Compilation:
{
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": ".tsbuildinfo"
}
}