1 import * as vscode from "vscode";
2 import { LLDBDapOptions } from "./types";
5 * This class defines a factory used to find the lldb-dap binary to use
6 * depending on the session configuration.
8 export class LLDBDapDescriptorFactory
9 implements vscode.DebugAdapterDescriptorFactory
11 private lldbDapOptions: LLDBDapOptions;
13 constructor(lldbDapOptions: LLDBDapOptions) {
14 this.lldbDapOptions = lldbDapOptions;
17 static async isValidDebugAdapterPath(
21 const fileStats = await vscode.workspace.fs.stat(pathUri);
22 if (!(fileStats.type & vscode.FileType.File)) {
31 async createDebugAdapterDescriptor(
32 session: vscode.DebugSession,
33 executable: vscode.DebugAdapterExecutable | undefined,
34 ): Promise<vscode.DebugAdapterDescriptor | undefined> {
35 const config = vscode.workspace.getConfiguration(
37 session.workspaceFolder,
39 const customPath = config.get<string>("executable-path");
40 const path: string = customPath || executable!!.command;
42 const fileUri = vscode.Uri.file(path);
43 if (!(await LLDBDapDescriptorFactory.isValidDebugAdapterPath(fileUri))) {
44 LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(fileUri.path);
46 return this.lldbDapOptions.createDapExecutableCommand(session, executable);
50 * Shows a message box when the debug adapter's path is not found
52 static async showLLDBDapNotFoundMessage(path: string) {
53 const openSettingsAction = "Open Settings";
54 const callbackValue = await vscode.window.showErrorMessage(
55 `Debug adapter path: ${path} is not a valid file`,
59 if (openSettingsAction === callbackValue) {
60 vscode.commands.executeCommand(
61 "workbench.action.openSettings",
62 "lldb-dap.executable-path",