-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if |
||
} | ||
|
||
/** | ||
* Shows a message box when the debug adapter's path is not found | ||
*/ | ||
private static showErrorMessage(path: string) { | ||
da-viper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const openSettingsAction = "Open Settings"; | ||
vscode.window | ||
.showErrorMessage( | ||
`Debug adapter path: ${path} is not a valid file`, | ||
{ modal: false }, | ||
vogelsgesang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
openSettingsAction, | ||
) | ||
.then((callBackValue) => { | ||
if (openSettingsAction === callBackValue) { | ||
vscode.commands.executeCommand( | ||
"workbench.action.openSettings", | ||
"lldb-dap.executable-path", | ||
); | ||
} | ||
}); | ||
} | ||
da-viper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
da-viper marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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), | ||
); | ||
} | ||
} | ||
}), | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like 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.