diff --git a/lldb/docs/resources/lldbdap.md b/lldb/docs/resources/lldbdap.md index 955713dd1b59..3838c82ab5df 100644 --- a/lldb/docs/resources/lldbdap.md +++ b/lldb/docs/resources/lldbdap.md @@ -170,3 +170,26 @@ This is also very simple, just run: ```bash npm run format ``` + +## Working with the VS Code extension from another extension + +The VS Code extension exposes the following [VS Code +commands](https://code.visualstudio.com/api/extension-guides/command), +which can be invoked by other debugger extensions to leverage this extension's +settings and logic. The commands help resolve configuration, create adapter +descriptor, and get the lldb-dap process for state tracking, additional +interaction, and telemetry. + +``` +// Resolve debug configuration +const resolvedConfiguration = await vscode.commands.executeCommand("lldb-dap.resolveDebugConfiguration", folder, configuration, token); + +// Resolve debug configuration with substituted variables +const resolvedConfigurationWithSubstitutedVariables = await vscode.commands.executeCommand("lldb-dap.resolveDebugConfigurationWithSubstitutedVariables", folder, configuration, token); + +// Create debug adapter descriptor +const adapterDescriptor = await vscode.commands.executeCommand("lldb-dap.createDebugAdapterDescriptor", session, executable); + +// Get DAP server process +const process = await vscode.commands.executeCommand("lldb-dap.getServerProcess"); +``` diff --git a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts index 6e94400b0915..157aa2ac76a1 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -217,7 +217,15 @@ export class LLDBDapDescriptorFactory constructor( private readonly logger: vscode.LogOutputChannel, private logFilePath: LogFilePathProvider, - ) {} + ) { + vscode.commands.registerCommand( + "lldb-dap.createDebugAdapterDescriptor", + ( + session: vscode.DebugSession, + executable: vscode.DebugAdapterExecutable | undefined, + ) => this.createDebugAdapterDescriptor(session, executable), + ); + } async createDebugAdapterDescriptor( session: vscode.DebugSession, diff --git a/lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts b/lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts index 8c04ec2bdc9d..1e16dac03112 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts @@ -76,7 +76,29 @@ export class LLDBDapConfigurationProvider private readonly server: LLDBDapServer, private readonly logger: vscode.LogOutputChannel, private readonly logFilePath: LogFilePathProvider, - ) {} + ) { + vscode.commands.registerCommand( + "lldb-dap.resolveDebugConfiguration", + ( + folder: vscode.WorkspaceFolder | undefined, + debugConfiguration: vscode.DebugConfiguration, + token?: vscode.CancellationToken, + ) => this.resolveDebugConfiguration(folder, debugConfiguration, token), + ); + vscode.commands.registerCommand( + "lldb-dap.resolveDebugConfigurationWithSubstitutedVariables", + ( + folder: vscode.WorkspaceFolder | undefined, + debugConfiguration: vscode.DebugConfiguration, + token?: vscode.CancellationToken, + ) => + this.resolveDebugConfigurationWithSubstitutedVariables( + folder, + debugConfiguration, + token, + ), + ); + } async resolveDebugConfiguration( folder: vscode.WorkspaceFolder | undefined, diff --git a/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts b/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts index f360fa3adfa8..5f9d8efdcb3a 100644 --- a/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts +++ b/lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts @@ -12,6 +12,13 @@ export class LLDBDapServer implements vscode.Disposable { private serverProcess?: child_process.ChildProcessWithoutNullStreams; private serverInfo?: Promise<{ host: string; port: number }>; + constructor() { + vscode.commands.registerCommand( + "lldb-dap.getServerProcess", + () => this.serverProcess, + ); + } + /** * Starts the server with the provided options. The server will be restarted or reused as * necessary.