| 1 |
import * as vscode from "vscode"; |
| 2 |
import { LLDBDapOptions } from "./types"; |
| 3 |
import { DisposableContext } from "./disposable-context"; |
| 4 |
import { LLDBDapDescriptorFactory } from "./debug-adapter-factory"; |
| 5 |
|
| 6 |
/** |
| 7 |
* This creates the configurations for this project if used as a standalone |
| 8 |
* extension. |
| 9 |
*/ |
| 10 |
function createDefaultLLDBDapOptions(): LLDBDapOptions { |
| 11 |
return { |
| 12 |
debuggerType: "lldb-dap", |
| 13 |
async createDapExecutableCommand( |
| 14 |
session: vscode.DebugSession, |
| 15 |
packageJSONExecutable: vscode.DebugAdapterExecutable | undefined, |
| 16 |
): Promise<vscode.DebugAdapterExecutable | undefined> { |
| 17 |
const path = vscode.workspace |
| 18 |
.getConfiguration("lldb-dap", session.workspaceFolder) |
| 19 |
.get<string>("executable-path"); |
| 20 |
if (path) { |
| 21 |
return new vscode.DebugAdapterExecutable(path, []); |
| 22 |
} |
| 23 |
return packageJSONExecutable; |
| 24 |
}, |
| 25 |
}; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* This class represents the extension and manages its life cycle. Other extensions |
| 30 |
* using it as as library should use this class as the main entry point. |
| 31 |
*/ |
| 32 |
export class LLDBDapExtension extends DisposableContext { |
| 33 |
private lldbDapOptions: LLDBDapOptions; |
| 34 |
|
| 35 |
constructor(lldbDapOptions: LLDBDapOptions) { |
| 36 |
super(); |
| 37 |
this.lldbDapOptions = lldbDapOptions; |
| 38 |
|
| 39 |
this.pushSubscription( |
| 40 |
vscode.debug.registerDebugAdapterDescriptorFactory( |
| 41 |
this.lldbDapOptions.debuggerType, |
| 42 |
new LLDBDapDescriptorFactory(this.lldbDapOptions), |
| 43 |
), |
| 44 |
); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* This is the entry point when initialized by VS Code. |
| 50 |
*/ |
| 51 |
export function activate(context: vscode.ExtensionContext) { |
| 52 |
context.subscriptions.push( |
| 53 |
new LLDBDapExtension(createDefaultLLDBDapOptions()), |
| 54 |
); |
| 55 |
} |