Skip to content

[lldb-dap] show dialog when executable is not found #104711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

da-viper
Copy link
Contributor

Fixes #103043

@da-viper da-viper requested a review from JDevlieghere as a code owner August 18, 2024 14:29
@llvmbot llvmbot added the lldb label Aug 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 18, 2024

@llvm/pr-subscribers-lldb

Author: None (Da-Viper)

Changes

Fixes #103043


Full diff: https://github.com/llvm/llvm-project/pull/104711.diff

1 Files Affected:

  • (modified) lldb/tools/lldb-dap/src-ts/extension.ts (+26-3)
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, []);
     },
   };
 }

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a TS expert but functionally this is a great improvement. LGTM.

Copy link
Member

@vogelsgesang vogelsgesang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this! The patch already looks very good!

@walter-erquinigo
Copy link
Member

@da-viper , a better way to do this is that, instead of checking for the path upon initialization, you add this checking logic in the createDebugAdapterDescriptor function, which only gets triggered when you launch the debugger. This will be less annoying to users who have the extension but rarely use it.

@da-viper da-viper force-pushed the lldb_dap-missing-feedback-if-exec-not-found-#103043 branch from 6b43660 to 2cda519 Compare August 22, 2024 00:43
Copy link
Member

@walter-erquinigo walter-erquinigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

Don't forget to run npm run format before landing this

@da-viper
Copy link
Contributor Author

cool

Don't forget to run npm run format before landing this

Done

Copy link
Member

@vogelsgesang vogelsgesang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!
Thanks for this amazing usability improvement!
If this would have existed the first time I tried this extension, it would have saved me a lot of time

session.workspaceFolder,
);
const customPath = config.get<string>("executable-path");
const path: string = customPath ? customPath : executable!!.command;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const path: string = customPath ? customPath : executable!!.command;
const path: string = customPath || executable!!.command;

Comment on lines 39 to 42
await LLDBDapDescriptorFactory.validateDebugAdapterPath(
vscode.Uri.file(path),
);
return this.lldbDapOptions.createDapExecutableCommand(session, executable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if validateDebugAdapterPath returns a boolean, and then, in the case of success, you return createDapExecutableCommand, and otherwise you throw an exception?
I have the impression that that would be managed better by the IDE, otherwise you could be launching a session with a missing binary

Comment on lines 68 to 81
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),
);
}
}
}),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this!

@vogelsgesang
Copy link
Member

Looks good to me! Thanks again for fixing this!

@da-viper
Copy link
Contributor Author

Screenshot from 2024-08-23 20-16-35

This is what is shown when I return undefined from the createDebugAdapterDescriptor function

If I also throw vscode.FileSystemError.FileExists(`Debug path: ${path} is not vaild`)
It shows the same as above but with the file path as a description

Copy link
Member

@walter-erquinigo walter-erquinigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the screenshot, man!

@JDevlieghere
Copy link
Member

Looks like this is ready to go. @da-viper do you need someone to merge this for you?

@tedwoodward
Copy link

Does the version number in package.json need to be updated, to automatically publish the change to the marketplace?

@da-viper
Copy link
Contributor Author

da-viper commented Sep 1, 2024

Looks like this is ready to go. @da-viper do you need someone to merge this for you?

Yes, As I do not have write permission to the repository

@JDevlieghere JDevlieghere merged commit 984fca5 into llvm:main Sep 1, 2024
7 checks passed
JDevlieghere pushed a commit to swiftlang/llvm-project that referenced this pull request Oct 16, 2024
@da-viper da-viper deleted the lldb_dap-missing-feedback-if-exec-not-found-#103043 branch March 16, 2025 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[lldb-dap] Missing feedback if lldb-dap executable is not found
6 participants