Skip to content

Commit

Permalink
[lldb-dap] show dialog when executable is not found (llvm#104711)
Browse files Browse the repository at this point in the history
  • Loading branch information
Da-Viper authored Sep 1, 2024
1 parent 5c0d61e commit 984fca5
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 11 deletions.
43 changes: 43 additions & 0 deletions lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,53 @@ export class LLDBDapDescriptorFactory
this.lldbDapOptions = lldbDapOptions;
}

static async isValidDebugAdapterPath(
pathUri: vscode.Uri,
): Promise<Boolean> {
try {
const fileStats = await vscode.workspace.fs.stat(pathUri);
if (!(fileStats.type & vscode.FileType.File)) {
return false;
}
} catch (err) {
return false;
}
return true;
}

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 || executable!!.command;

const fileUri = vscode.Uri.file(path);
if (!(await LLDBDapDescriptorFactory.isValidDebugAdapterPath(fileUri))) {
LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(fileUri.path);
}
return this.lldbDapOptions.createDapExecutableCommand(session, executable);
}

/**
* Shows a message box when the debug adapter's path is not found
*/
static async showLLDBDapNotFoundMessage(path: string) {
const openSettingsAction = "Open Settings";
const callbackValue = await vscode.window.showErrorMessage(
`Debug adapter path: ${path} is not a valid file`,
openSettingsAction,
);

if (openSettingsAction === callbackValue) {
vscode.commands.executeCommand(
"workbench.action.openSettings",
"lldb-dap.executable-path",
);
}
}
}
48 changes: 37 additions & 11 deletions lldb/tools/lldb-dap/src-ts/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -58,6 +64,26 @@ export class LLDBDapExtension extends DisposableContext {
new LLDBDapDescriptorFactory(this.lldbDapOptions),
),
);

this.pushSubscription(
vscode.workspace.onDidChangeConfiguration(async (event) => {
if (event.affectsConfiguration("lldb-dap.executable-path")) {
const dapPath = vscode.workspace
.getConfiguration("lldb-dap")
.get<string>("executable-path");

if (dapPath) {
const fileUri = vscode.Uri.file(dapPath);
if (
await LLDBDapDescriptorFactory.isValidDebugAdapterPath(fileUri)
) {
return;
}
}
LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(dapPath || "");
}
}),
);
}
}

Expand Down

0 comments on commit 984fca5

Please sign in to comment.