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

via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 19 13:02:39 PDT 2024


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

>From 0b84d36d320a58a13ca98bd1b1c186c72bbe63e2 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka <yerimyah1 at gmail.com>
Date: Sun, 18 Aug 2024 15:26:11 +0100
Subject: [PATCH 1/3] [lldb-dap] vscode now shows a dialog when the
 dab-executable is not found

---
 lldb/tools/lldb-dap/src-ts/extension.ts | 29 ++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts
index 791175f7b46224..c7802eed2a513b 100644
--- a/lldb/tools/lldb-dap/src-ts/extension.ts
+++ b/lldb/tools/lldb-dap/src-ts/extension.ts
@@ -1,4 +1,5 @@
 import * as vscode from "vscode";
+import * as fs from "node:fs/promises";
 import { LLDBDapOptions } from "./types";
 import { DisposableContext } from "./disposable-context";
 import { LLDBDapDescriptorFactory } from "./debug-adapter-factory";
@@ -17,10 +18,32 @@ function createDefaultLLDBDapOptions(): LLDBDapOptions {
       const path = vscode.workspace
         .getConfiguration("lldb-dap", session.workspaceFolder)
         .get<string>("executable-path");
-      if (path) {
-        return new vscode.DebugAdapterExecutable(path, []);
+
+      if (!path) {
+        return packageJSONExecutable;
+      }
+
+      try {
+        const fileStats = await fs.stat(path);
+        if (!fileStats.isFile()) {
+          throw new Error(`Error: ${path} is not a file`);
+        }
+      } catch (err) {
+        const error: Error = err as Error;
+        const openSettingsAction = "Open Settings";
+        const callBackValue = await vscode.window.showErrorMessage(
+          error.message,
+          { modal: true },
+          openSettingsAction,
+        );
+        if (openSettingsAction === callBackValue) {
+          vscode.commands.executeCommand(
+            "workbench.action.openSettings",
+            "lldb-dap.executable-path",
+          );
+        }
       }
-      return packageJSONExecutable;
+      return new vscode.DebugAdapterExecutable(path, []);
     },
   };
 }

>From 2eca3822a8ba5f1a329e459176003a30de40c683 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka <yerimyah1 at gmail.com>
Date: Sun, 18 Aug 2024 23:25:00 +0100
Subject: [PATCH 2/3] [lldb-dap] handle symbolic link

---
 lldb/tools/lldb-dap/src-ts/extension.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts
index c7802eed2a513b..7bc380a73bd443 100644
--- a/lldb/tools/lldb-dap/src-ts/extension.ts
+++ b/lldb/tools/lldb-dap/src-ts/extension.ts
@@ -25,7 +25,7 @@ function createDefaultLLDBDapOptions(): LLDBDapOptions {
 
       try {
         const fileStats = await fs.stat(path);
-        if (!fileStats.isFile()) {
+        if (!fileStats.isFile() && !fileStats.isSymbolicLink()) {
           throw new Error(`Error: ${path} is not a file`);
         }
       } catch (err) {

>From 6b436602cd5bae4926bd7d06d9bf9047697547f5 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka <yerimyah1 at gmail.com>
Date: Mon, 19 Aug 2024 21:01:25 +0100
Subject: [PATCH 3/3] Resolve review changes

---
 lldb/tools/lldb-dap/src-ts/extension.ts | 51 +++++++++++++++----------
 1 file changed, 30 insertions(+), 21 deletions(-)

diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts
index 7bc380a73bd443..d4f8fb1599a3d1 100644
--- a/lldb/tools/lldb-dap/src-ts/extension.ts
+++ b/lldb/tools/lldb-dap/src-ts/extension.ts
@@ -1,5 +1,4 @@
 import * as vscode from "vscode";
-import * as fs from "node:fs/promises";
 import { LLDBDapOptions } from "./types";
 import { DisposableContext } from "./disposable-context";
 import { LLDBDapDescriptorFactory } from "./debug-adapter-factory";
@@ -23,31 +22,41 @@ function createDefaultLLDBDapOptions(): LLDBDapOptions {
         return packageJSONExecutable;
       }
 
-      try {
-        const fileStats = await fs.stat(path);
-        if (!fileStats.isFile() && !fileStats.isSymbolicLink()) {
-          throw new Error(`Error: ${path} is not a file`);
-        }
-      } catch (err) {
-        const error: Error = err as Error;
-        const openSettingsAction = "Open Settings";
-        const callBackValue = await vscode.window.showErrorMessage(
-          error.message,
-          { modal: true },
-          openSettingsAction,
-        );
-        if (openSettingsAction === callBackValue) {
-          vscode.commands.executeCommand(
-            "workbench.action.openSettings",
-            "lldb-dap.executable-path",
-          );
-        }
-      }
+      vscode.workspace.fs.stat(vscode.Uri.file(path)).then(
+        (fileStats) => {
+          if (!(fileStats.type & vscode.FileType.File)) {
+            showErrorMessage(path);
+          }
+        },
+        (_) => {
+          showErrorMessage(path);
+        },
+      );
       return new vscode.DebugAdapterExecutable(path, []);
     },
   };
 }
 
+/**
+ * Shows a message box when the debug adapter's path is not found
+ */
+function showErrorMessage(path: string) {
+  const openSettingsAction = "Open Settings";
+  vscode.window
+    .showErrorMessage(
+      `Debug adapter path: ${path} is not a vaild file`,
+      { modal: false },
+      openSettingsAction,
+    )
+    .then((callBackValue) => {
+      if (openSettingsAction === callBackValue) {
+        vscode.commands.executeCommand(
+          "workbench.action.openSettings",
+          "lldb-dap.executable-path",
+        );
+      }
+    });
+}
 /**
  * This class represents the extension and manages its life cycle. Other extensions
  * using it as as library should use this class as the main entry point.



More information about the lldb-commits mailing list