-
Notifications
You must be signed in to change notification settings - Fork 14.1k
[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
[lldb-dap] show dialog when executable is not found #104711
Conversation
@llvm/pr-subscribers-lldb Author: None (Da-Viper) ChangesFixes #103043 Full diff: https://github.com/llvm/llvm-project/pull/104711.diff 1 Files Affected:
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, []);
},
};
}
|
There was a problem hiding this 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.
There was a problem hiding this 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!
@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 |
6b43660
to
2cda519
Compare
There was a problem hiding this 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
Done |
There was a problem hiding this 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const path: string = customPath ? customPath : executable!!.command; | |
const path: string = customPath || executable!!.command; |
await LLDBDapDescriptorFactory.validateDebugAdapterPath( | ||
vscode.Uri.file(path), | ||
); | ||
return this.lldbDapOptions.createDapExecutableCommand(session, executable); |
There was a problem hiding this comment.
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
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), | ||
); | ||
} | ||
} | ||
}), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this!
Looks good to me! Thanks again for fixing this! |
There was a problem hiding this 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!
Looks like this is ready to go. @da-viper do you need someone to merge this for you? |
Does the version number in package.json need to be updated, to automatically publish the change to the marketplace? |
Yes, As I do not have write permission to the repository |
(cherry picked from commit 984fca5)
Fixes #103043