Skip to content

Commit 984fca5

Browse files
authored
[lldb-dap] show dialog when executable is not found (#104711)
1 parent 5c0d61e commit 984fca5

File tree

2 files changed

+80
-11
lines changed

2 files changed

+80
-11
lines changed

lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,53 @@ export class LLDBDapDescriptorFactory
1414
this.lldbDapOptions = lldbDapOptions;
1515
}
1616

17+
static async isValidDebugAdapterPath(
18+
pathUri: vscode.Uri,
19+
): Promise<Boolean> {
20+
try {
21+
const fileStats = await vscode.workspace.fs.stat(pathUri);
22+
if (!(fileStats.type & vscode.FileType.File)) {
23+
return false;
24+
}
25+
} catch (err) {
26+
return false;
27+
}
28+
return true;
29+
}
30+
1731
async createDebugAdapterDescriptor(
1832
session: vscode.DebugSession,
1933
executable: vscode.DebugAdapterExecutable | undefined,
2034
): Promise<vscode.DebugAdapterDescriptor | undefined> {
35+
const config = vscode.workspace.getConfiguration(
36+
"lldb-dap",
37+
session.workspaceFolder,
38+
);
39+
const customPath = config.get<string>("executable-path");
40+
const path: string = customPath || executable!!.command;
41+
42+
const fileUri = vscode.Uri.file(path);
43+
if (!(await LLDBDapDescriptorFactory.isValidDebugAdapterPath(fileUri))) {
44+
LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(fileUri.path);
45+
}
2146
return this.lldbDapOptions.createDapExecutableCommand(session, executable);
2247
}
48+
49+
/**
50+
* Shows a message box when the debug adapter's path is not found
51+
*/
52+
static async showLLDBDapNotFoundMessage(path: string) {
53+
const openSettingsAction = "Open Settings";
54+
const callbackValue = await vscode.window.showErrorMessage(
55+
`Debug adapter path: ${path} is not a valid file`,
56+
openSettingsAction,
57+
);
58+
59+
if (openSettingsAction === callbackValue) {
60+
vscode.commands.executeCommand(
61+
"workbench.action.openSettings",
62+
"lldb-dap.executable-path",
63+
);
64+
}
65+
}
2366
}

lldb/tools/lldb-dap/src-ts/extension.ts

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,32 @@ function createDefaultLLDBDapOptions(): LLDBDapOptions {
1414
session: vscode.DebugSession,
1515
packageJSONExecutable: vscode.DebugAdapterExecutable | undefined,
1616
): Promise<vscode.DebugAdapterExecutable | undefined> {
17-
const config = vscode.workspace
18-
.getConfiguration("lldb-dap", session.workspaceFolder);
17+
const config = vscode.workspace.getConfiguration(
18+
"lldb-dap",
19+
session.workspaceFolder,
20+
);
1921
const path = config.get<string>("executable-path");
2022
const log_path = config.get<string>("log-path");
2123

22-
let env : { [key: string]: string } = {};
24+
let env: { [key: string]: string } = {};
2325
if (log_path) {
2426
env["LLDBDAP_LOG"] = log_path;
2527
}
2628

2729
if (path) {
28-
return new vscode.DebugAdapterExecutable(path, [], {env});
30+
return new vscode.DebugAdapterExecutable(path, [], { env });
2931
} else if (packageJSONExecutable) {
30-
return new vscode.DebugAdapterExecutable(packageJSONExecutable.command, packageJSONExecutable.args, {
31-
...packageJSONExecutable.options,
32-
env: {
33-
...packageJSONExecutable.options?.env,
34-
...env
35-
}
36-
});
32+
return new vscode.DebugAdapterExecutable(
33+
packageJSONExecutable.command,
34+
packageJSONExecutable.args,
35+
{
36+
...packageJSONExecutable.options,
37+
env: {
38+
...packageJSONExecutable.options?.env,
39+
...env,
40+
},
41+
},
42+
);
3743
} else {
3844
return undefined;
3945
}
@@ -58,6 +64,26 @@ export class LLDBDapExtension extends DisposableContext {
5864
new LLDBDapDescriptorFactory(this.lldbDapOptions),
5965
),
6066
);
67+
68+
this.pushSubscription(
69+
vscode.workspace.onDidChangeConfiguration(async (event) => {
70+
if (event.affectsConfiguration("lldb-dap.executable-path")) {
71+
const dapPath = vscode.workspace
72+
.getConfiguration("lldb-dap")
73+
.get<string>("executable-path");
74+
75+
if (dapPath) {
76+
const fileUri = vscode.Uri.file(dapPath);
77+
if (
78+
await LLDBDapDescriptorFactory.isValidDebugAdapterPath(fileUri)
79+
) {
80+
return;
81+
}
82+
}
83+
LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(dapPath || "");
84+
}
85+
}),
86+
);
6187
}
6288
}
6389

0 commit comments

Comments
 (0)