Documentation Index Fetch the complete documentation index at: https://mintlify.com/Microsoft/vscode/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The vscode.debug namespace provides functions to start and control debug sessions, register debug adapters, and track debugging state.
Starting Debug Sessions
startDebugging
Start a debugging session.
function startDebugging (
folder : WorkspaceFolder | undefined ,
nameOrConfiguration : string | DebugConfiguration ,
parentSessionOrOptions ?: DebugSession | DebugSessionOptions
) : Thenable < boolean >
Example:
import * as vscode from 'vscode' ;
// Start debugging using a launch.json configuration by name
await vscode . debug . startDebugging (
vscode . workspace . workspaceFolders ?.[ 0 ],
'Launch Program'
);
// Start debugging with inline configuration
await vscode . debug . startDebugging (
vscode . workspace . workspaceFolders ?.[ 0 ],
{
type: 'node' ,
request: 'launch' ,
name: 'Debug Current File' ,
program: '${file}'
}
);
stopDebugging
Stop a specific debug session or all sessions.
function stopDebugging ( session ?: DebugSession ) : Thenable < void >
Example:
// Stop current session
if ( vscode . debug . activeDebugSession ) {
await vscode . debug . stopDebugging ( vscode . debug . activeDebugSession );
}
// Stop all sessions
await vscode . debug . stopDebugging ();
Debug Adapters
registerDebugAdapterDescriptorFactory
Register a debug adapter descriptor factory.
function registerDebugAdapterDescriptorFactory (
debugType : string ,
factory : DebugAdapterDescriptorFactory
) : Disposable
Example:
class MyDebugAdapterFactory implements vscode . DebugAdapterDescriptorFactory {
createDebugAdapterDescriptor (
session : vscode . DebugSession ,
executable : vscode . DebugAdapterExecutable | undefined
) : vscode . ProviderResult < vscode . DebugAdapterDescriptor > {
// Return descriptor for debug adapter
return new vscode . DebugAdapterExecutable (
'node' ,
[ './out/debugAdapter.js' ]
);
}
}
vscode . debug . registerDebugAdapterDescriptorFactory (
'myDebugger' ,
new MyDebugAdapterFactory ()
);
registerDebugConfigurationProvider
Register a debug configuration provider.
function registerDebugConfigurationProvider (
debugType : string ,
provider : DebugConfigurationProvider ,
triggerKind ?: DebugConfigurationProviderTriggerKind
) : Disposable
Example:
class MyConfigProvider implements vscode . DebugConfigurationProvider {
resolveDebugConfiguration (
folder : vscode . WorkspaceFolder | undefined ,
config : vscode . DebugConfiguration ,
token ?: vscode . CancellationToken
) : vscode . ProviderResult < vscode . DebugConfiguration > {
// Modify or validate configuration
if ( ! config . program ) {
config . program = '${file}' ;
}
return config ;
}
}
vscode . debug . registerDebugConfigurationProvider (
'node' ,
new MyConfigProvider ()
);
Properties
activeDebugSession
The currently active debug session or undefined.
const activeDebugSession : DebugSession | undefined
Example:
if ( vscode . debug . activeDebugSession ) {
console . log ( `Debugging: ${ vscode . debug . activeDebugSession . name } ` );
}
activeDebugConsole
The currently active debug console.
const activeDebugConsole : DebugConsole
Example:
vscode . debug . activeDebugConsole . appendLine ( 'Debug message' );
vscode . debug . activeDebugConsole . append ( 'Inline message' );
breakpoints
All breakpoints.
const breakpoints : readonly Breakpoint []
Example:
const allBreakpoints = vscode . debug . breakpoints ;
console . log ( `Total breakpoints: ${ allBreakpoints . length } ` );
Events
onDidStartDebugSession
Fires when a debug session is started.
const onDidStartDebugSession : Event < DebugSession >
Example:
vscode . debug . onDidStartDebugSession ( session => {
console . log ( `Started debugging: ${ session . name } ` );
vscode . window . showInformationMessage ( `Debug session started: ${ session . name } ` );
});
onDidTerminateDebugSession
Fires when a debug session terminates.
const onDidTerminateDebugSession : Event < DebugSession >
onDidChangeActiveDebugSession
Fires when the active debug session changes.
const onDidChangeActiveDebugSession : Event < DebugSession | undefined >
onDidChangeBreakpoints
Fires when breakpoints are added, removed, or changed.
const onDidChangeBreakpoints : Event < BreakpointsChangeEvent >
Example:
vscode . debug . onDidChangeBreakpoints ( event => {
console . log ( `Added: ${ event . added . length } ` );
console . log ( `Removed: ${ event . removed . length } ` );
console . log ( `Changed: ${ event . changed . length } ` );
});
Breakpoint Management
addBreakpoints
Add breakpoints.
function addBreakpoints ( breakpoints : readonly Breakpoint []) : void
Example:
const uri = vscode . Uri . file ( '/path/to/file.ts' );
const breakpoint = new vscode . SourceBreakpoint (
new vscode . Location ( uri , new vscode . Position ( 10 , 0 )),
true
);
vscode . debug . addBreakpoints ([ breakpoint ]);
removeBreakpoints
Remove breakpoints.
function removeBreakpoints ( breakpoints : readonly Breakpoint []) : void
Complete Example
import * as vscode from 'vscode' ;
export function activate ( context : vscode . ExtensionContext ) {
// Register debug configuration provider
const configProvider = vscode . debug . registerDebugConfigurationProvider (
'node' ,
{
resolveDebugConfiguration (
folder : vscode . WorkspaceFolder | undefined ,
config : vscode . DebugConfiguration
) : vscode . ProviderResult < vscode . DebugConfiguration > {
if ( ! config . request ) {
vscode . window . showErrorMessage ( 'No debug configuration found' );
return undefined ;
}
return config ;
}
}
);
context . subscriptions . push ( configProvider );
// Monitor debug sessions
context . subscriptions . push (
vscode . debug . onDidStartDebugSession ( session => {
vscode . debug . activeDebugConsole . appendLine (
`Debug session started: ${ session . name } `
);
})
);
// Command to start debugging
const startDebug = vscode . commands . registerCommand (
'myExtension.startDebugging' ,
async () => {
const editor = vscode . window . activeTextEditor ;
if ( ! editor ) {
return ;
}
await vscode . debug . startDebugging (
vscode . workspace . getWorkspaceFolder ( editor . document . uri ),
{
type: 'node' ,
request: 'launch' ,
name: 'Debug File' ,
program: editor . document . uri . fsPath
}
);
}
);
context . subscriptions . push ( startDebug );
}
Debugging Feature Learn about VS Code’s debugging capabilities
Commands API Register and execute commands