[Lldb-commits] [lldb] [lldb-dap] show dialog when executable is not found (PR #104711)

via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 21 17:43:41 PDT 2024


https://github.com/Da-Viper updated https://github.com/llvm/llvm-project/pull/104711

>From 2cda519a06d46bd6a5ae02e8be8daacb39a49b3e Mon Sep 17 00:00:00 2001
From: Ezike Ebuka <yerimyah1 at gmail.com>
Date: Thu, 22 Aug 2024 01:42:17 +0100
Subject: [PATCH] Rebase and add check dap path on config change

---
 .../lldb-dap/src-ts/debug-adapter-factory.ts  | 42 ++++++++++++++++++
 lldb/tools/lldb-dap/src-ts/extension.ts       | 43 ++++++++++++++-----
 2 files changed, 74 insertions(+), 11 deletions(-)

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 01c671f41ff782..8a8f441581b29e 100644
--- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
+++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
@@ -14,10 +14,52 @@ export class LLDBDapDescriptorFactory
     this.lldbDapOptions = lldbDapOptions;
   }
 
+  public static async validateDebugAdapterPath(pathUri: vscode.Uri) {
+    try {
+      const fileStats = await vscode.workspace.fs.stat(pathUri);
+      if (!(fileStats.type & vscode.FileType.File)) {
+        this.showErrorMessage(pathUri.path);
+      }
+    } catch (err) {
+      this.showErrorMessage(pathUri.path);
+    }
+  }
+
   async createDebugAdapterDescriptor(
     session: vscode.DebugSession,
     executable: vscode.DebugAdapterExecutable | undefined,
   ): Promise<vscode.DebugAdapterDescriptor | undefined> {
+    const config = vscode.workspace.getConfiguration(
+      "lldb-dap",
+      session.workspaceFolder,
+    );
+    const customPath = config.get<string>("executable-path");
+    const path: string = customPath ? customPath : executable!!.command;
+
+    await LLDBDapDescriptorFactory.validateDebugAdapterPath(
+      vscode.Uri.file(path),
+    );
     return this.lldbDapOptions.createDapExecutableCommand(session, executable);
   }
+
+  /**
+   * Shows a message box when the debug adapter's path is not found
+   */
+  private static showErrorMessage(path: string) {
+    const openSettingsAction = "Open Settings";
+    vscode.window
+      .showErrorMessage(
+        `Debug adapter path: ${path} is not a valid file`,
+        { modal: false },
+        openSettingsAction,
+      )
+      .then((callBackValue) => {
+        if (openSettingsAction === callBackValue) {
+          vscode.commands.executeCommand(
+            "workbench.action.openSettings",
+            "lldb-dap.executable-path",
+          );
+        }
+      });
+  }
 }
diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts
index 7df09f7a29dad7..12565a8fbe9a0a 100644
--- a/lldb/tools/lldb-dap/src-ts/extension.ts
+++ b/lldb/tools/lldb-dap/src-ts/extension.ts
@@ -14,26 +14,32 @@ function createDefaultLLDBDapOptions(): LLDBDapOptions {
       session: vscode.DebugSession,
       packageJSONExecutable: vscode.DebugAdapterExecutable | undefined,
     ): Promise<vscode.DebugAdapterExecutable | undefined> {
-      const config = vscode.workspace
-        .getConfiguration("lldb-dap", session.workspaceFolder);
+      const config = vscode.workspace.getConfiguration(
+        "lldb-dap",
+        session.workspaceFolder,
+      );
       const path = config.get<string>("executable-path");
       const log_path = config.get<string>("log-path");
 
-      let env : { [key: string]: string } = {};
+      let env: { [key: string]: string } = {};
       if (log_path) {
         env["LLDBDAP_LOG"] = log_path;
       }
 
       if (path) {
-        return new vscode.DebugAdapterExecutable(path, [], {env});
+        return new vscode.DebugAdapterExecutable(path, [], { env });
       } else if (packageJSONExecutable) {
-        return new vscode.DebugAdapterExecutable(packageJSONExecutable.command, packageJSONExecutable.args, {
-          ...packageJSONExecutable.options,
-          env: {
-            ...packageJSONExecutable.options?.env,
-            ...env
-          }
-        });
+        return new vscode.DebugAdapterExecutable(
+          packageJSONExecutable.command,
+          packageJSONExecutable.args,
+          {
+            ...packageJSONExecutable.options,
+            env: {
+              ...packageJSONExecutable.options?.env,
+              ...env,
+            },
+          },
+        );
       } else {
         return undefined;
       }
@@ -58,6 +64,21 @@ export class LLDBDapExtension extends DisposableContext {
         new LLDBDapDescriptorFactory(this.lldbDapOptions),
       ),
     );
+
+    this.pushSubscription(
+      vscode.workspace.onDidChangeConfiguration((event) => {
+        if (event.affectsConfiguration("lldb-dap.executable-path")) {
+          const dapPath = vscode.workspace
+            .getConfiguration("lldb-dap")
+            .get<string>("executable-path");
+          if (dapPath) {
+            LLDBDapDescriptorFactory.validateDebugAdapterPath(
+              vscode.Uri.file(dapPath),
+            );
+          }
+        }
+      }),
+    );
   }
 }
 



More information about the lldb-commits mailing list