1 import * as vscode from "vscode";
2 import { LLDBDapOptions } from "./types";
3 import { DisposableContext } from "./disposable-context";
4 import { LLDBDapDescriptorFactory } from "./debug-adapter-factory";
7 * This creates the configurations for this project if used as a standalone
10 function createDefaultLLDBDapOptions(): LLDBDapOptions {
12 debuggerType: "lldb-dap",
13 async createDapExecutableCommand(
14 session: vscode.DebugSession,
15 packageJSONExecutable: vscode.DebugAdapterExecutable | undefined,
16 ): Promise<vscode.DebugAdapterExecutable | undefined> {
17 const config = vscode.workspace.getConfiguration(
19 session.workspaceFolder,
21 const path = config.get<string>("executable-path");
22 const log_path = config.get<string>("log-path");
24 let env: { [key: string]: string } = {};
26 env["LLDBDAP_LOG"] = log_path;
28 const configEnvironment = config.get<{ [key: string]: string }>("environment") || {};
36 return new vscode.DebugAdapterExecutable(path, [], dbgOptions);
37 } else if (packageJSONExecutable) {
38 return new vscode.DebugAdapterExecutable(
39 packageJSONExecutable.command,
40 packageJSONExecutable.args,
42 ...packageJSONExecutable.options,
44 ...packageJSONExecutable.options?.env,
58 * This class represents the extension and manages its life cycle. Other extensions
59 * using it as as library should use this class as the main entry point.
61 export class LLDBDapExtension extends DisposableContext {
62 private lldbDapOptions: LLDBDapOptions;
64 constructor(lldbDapOptions: LLDBDapOptions) {
66 this.lldbDapOptions = lldbDapOptions;
68 this.pushSubscription(
69 vscode.debug.registerDebugAdapterDescriptorFactory(
70 this.lldbDapOptions.debuggerType,
71 new LLDBDapDescriptorFactory(this.lldbDapOptions),
75 this.pushSubscription(
76 vscode.workspace.onDidChangeConfiguration(async (event) => {
77 if (event.affectsConfiguration("lldb-dap.executable-path")) {
78 const dapPath = vscode.workspace
79 .getConfiguration("lldb-dap")
80 .get<string>("executable-path");
83 const fileUri = vscode.Uri.file(dapPath);
85 await LLDBDapDescriptorFactory.isValidDebugAdapterPath(fileUri)
90 LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(dapPath || "");
98 * This is the entry point when initialized by VS Code.
100 export function activate(context: vscode.ExtensionContext) {
101 context.subscriptions.push(
102 new LLDBDapExtension(createDefaultLLDBDapOptions()),