https://github.com/Da-Viper updated https://github.com/llvm/llvm-project/pull/104711
>From 2cda519a06d46bd6a5ae02e8be8daacb39a49b3e Mon Sep 17 00:00:00 2001 From: Ezike Ebuka <yerimy...@gmail.com> Date: Thu, 22 Aug 2024 01:42:17 +0100 Subject: [PATCH 1/3] Rebase and add check dap path on config change --- .../lldb-dap/src-ts/debug-adapter-factory.ts | 42 ++++++++++++++++++ lldb/tools/lldb-dap/src-ts/extension.ts | 43 ++++++++++++++----- 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts index 01c671f41ff782..8a8f441581b29e 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -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); } + + /** + * Shows a message box when the debug adapter's path is not found + */ + private static showErrorMessage(path: string) { + const openSettingsAction = "Open Settings"; + vscode.window + .showErrorMessage( + `Debug adapter path: ${path} is not a valid file`, + { modal: false }, + openSettingsAction, + ) + .then((callBackValue) => { + if (openSettingsAction === callBackValue) { + vscode.commands.executeCommand( + "workbench.action.openSettings", + "lldb-dap.executable-path", + ); + } + }); + } } diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 7df09f7a29dad7..12565a8fbe9a0a 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -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), + ); + } + } + }), + ); } } >From 443c71a4af2fa03eb911deb9b086a2e7e6f1daf1 Mon Sep 17 00:00:00 2001 From: Ezike Ebuka <yerimy...@gmail.com> Date: Thu, 22 Aug 2024 18:54:03 +0100 Subject: [PATCH 2/3] Resolve review changes --- .../lldb-dap/src-ts/debug-adapter-factory.ts | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts index 8a8f441581b29e..c8cbca13b7446c 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -18,10 +18,10 @@ export class LLDBDapDescriptorFactory try { const fileStats = await vscode.workspace.fs.stat(pathUri); if (!(fileStats.type & vscode.FileType.File)) { - this.showErrorMessage(pathUri.path); + this.showLLDBDapNotFoundMessage(pathUri.path); } } catch (err) { - this.showErrorMessage(pathUri.path); + this.showLLDBDapNotFoundMessage(pathUri.path); } } @@ -45,21 +45,18 @@ export class LLDBDapDescriptorFactory /** * Shows a message box when the debug adapter's path is not found */ - private static showErrorMessage(path: string) { + private static async showLLDBDapNotFoundMessage(path: string) { const openSettingsAction = "Open Settings"; - vscode.window - .showErrorMessage( - `Debug adapter path: ${path} is not a valid file`, - { modal: false }, - openSettingsAction, - ) - .then((callBackValue) => { - if (openSettingsAction === callBackValue) { - vscode.commands.executeCommand( - "workbench.action.openSettings", - "lldb-dap.executable-path", - ); - } - }); + 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", + ); + } } } >From 2bdbcdee26a4b04302de900d46bef86bddbe1d54 Mon Sep 17 00:00:00 2001 From: Ezike Ebuka <yerimy...@gmail.com> Date: Fri, 23 Aug 2024 21:01:02 +0100 Subject: [PATCH 3/3] Resolve review changes --- .../lldb-dap/src-ts/debug-adapter-factory.ts | 20 +++++++++++-------- lldb/tools/lldb-dap/src-ts/extension.ts | 13 ++++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts index c8cbca13b7446c..2be21bfdf0dd69 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -14,15 +14,18 @@ export class LLDBDapDescriptorFactory this.lldbDapOptions = lldbDapOptions; } - public static async validateDebugAdapterPath(pathUri: vscode.Uri) { + static async isValidDebugAdapterPath( + pathUri: vscode.Uri, + ): Promise<Boolean> { try { const fileStats = await vscode.workspace.fs.stat(pathUri); if (!(fileStats.type & vscode.FileType.File)) { - this.showLLDBDapNotFoundMessage(pathUri.path); + return false; } } catch (err) { - this.showLLDBDapNotFoundMessage(pathUri.path); + return false; } + return true; } async createDebugAdapterDescriptor( @@ -34,18 +37,19 @@ export class LLDBDapDescriptorFactory session.workspaceFolder, ); const customPath = config.get<string>("executable-path"); - const path: string = customPath ? customPath : executable!!.command; + const path: string = customPath || executable!!.command; - await LLDBDapDescriptorFactory.validateDebugAdapterPath( - vscode.Uri.file(path), - ); + 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 */ - private static async showLLDBDapNotFoundMessage(path: string) { + static async showLLDBDapNotFoundMessage(path: string) { const openSettingsAction = "Open Settings"; const callbackValue = await vscode.window.showErrorMessage( `Debug adapter path: ${path} is not a valid file`, diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 12565a8fbe9a0a..fdc4f47b238b5a 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -66,16 +66,21 @@ export class LLDBDapExtension extends DisposableContext { ); this.pushSubscription( - vscode.workspace.onDidChangeConfiguration((event) => { + 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) { - LLDBDapDescriptorFactory.validateDebugAdapterPath( - vscode.Uri.file(dapPath), - ); + const fileUri = vscode.Uri.file(dapPath); + if ( + await LLDBDapDescriptorFactory.isValidDebugAdapterPath(fileUri) + ) { + return; + } } + LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(dapPath || ""); } }), ); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits