Skip to content

Commit 2cda519

Browse files
committed
Rebase and add check dap path on config change
1 parent 8a677c1 commit 2cda519

File tree

2 files changed

+74
-11
lines changed

2 files changed

+74
-11
lines changed

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

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

17+
public static async validateDebugAdapterPath(pathUri: vscode.Uri) {
18+
try {
19+
const fileStats = await vscode.workspace.fs.stat(pathUri);
20+
if (!(fileStats.type & vscode.FileType.File)) {
21+
this.showErrorMessage(pathUri.path);
22+
}
23+
} catch (err) {
24+
this.showErrorMessage(pathUri.path);
25+
}
26+
}
27+
1728
async createDebugAdapterDescriptor(
1829
session: vscode.DebugSession,
1930
executable: vscode.DebugAdapterExecutable | undefined,
2031
): Promise<vscode.DebugAdapterDescriptor | undefined> {
32+
const config = vscode.workspace.getConfiguration(
33+
"lldb-dap",
34+
session.workspaceFolder,
35+
);
36+
const customPath = config.get<string>("executable-path");
37+
const path: string = customPath ? customPath : executable!!.command;
38+
39+
await LLDBDapDescriptorFactory.validateDebugAdapterPath(
40+
vscode.Uri.file(path),
41+
);
2142
return this.lldbDapOptions.createDapExecutableCommand(session, executable);
2243
}
44+
45+
/**
46+
* Shows a message box when the debug adapter's path is not found
47+
*/
48+
private static showErrorMessage(path: string) {
49+
const openSettingsAction = "Open Settings";
50+
vscode.window
51+
.showErrorMessage(
52+
`Debug adapter path: ${path} is not a valid file`,
53+
{ modal: false },
54+
openSettingsAction,
55+
)
56+
.then((callBackValue) => {
57+
if (openSettingsAction === callBackValue) {
58+
vscode.commands.executeCommand(
59+
"workbench.action.openSettings",
60+
"lldb-dap.executable-path",
61+
);
62+
}
63+
});
64+
}
2365
}

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

Lines changed: 32 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,21 @@ export class LLDBDapExtension extends DisposableContext {
5864
new LLDBDapDescriptorFactory(this.lldbDapOptions),
5965
),
6066
);
67+
68+
this.pushSubscription(
69+
vscode.workspace.onDidChangeConfiguration((event) => {
70+
if (event.affectsConfiguration("lldb-dap.executable-path")) {
71+
const dapPath = vscode.workspace
72+
.getConfiguration("lldb-dap")
73+
.get<string>("executable-path");
74+
if (dapPath) {
75+
LLDBDapDescriptorFactory.validateDebugAdapterPath(
76+
vscode.Uri.file(dapPath),
77+
);
78+
}
79+
}
80+
}),
81+
);
6182
}
6283
}
6384

0 commit comments

Comments
 (0)