From b8bb508ce5e48e1d3cb286f20ddc9733e4edd9da Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Tue, 14 May 2024 16:16:26 -0700 Subject: [PATCH] vscode-extension: resolve asconfigPath for multi-root workspaces where activated launch configuration is defined in the .code-workspace file Previously, asconfigPath worked only for sub-projects in a single root workspace. Now, it detects if no workspaceFolder is specified, which means that it came from the .code-workspace file instead of launch.json. --- .../ts/utils/SWFDebugConfigurationProvider.ts | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/vscode-extension/src/main/ts/utils/SWFDebugConfigurationProvider.ts b/vscode-extension/src/main/ts/utils/SWFDebugConfigurationProvider.ts index 80ba4e1..e2d55c3 100644 --- a/vscode-extension/src/main/ts/utils/SWFDebugConfigurationProvider.ts +++ b/vscode-extension/src/main/ts/utils/SWFDebugConfigurationProvider.ts @@ -92,11 +92,41 @@ export default class SWFDebugConfigurationProvider throw new Error("SWF debugger launch failed. Java path not found."); } + let asconfigPath = debugConfiguration.asconfigPath; + + if ( + workspaceFolder === undefined && + vscode.workspace.workspaceFolders !== undefined + ) { + // special case: launch configuration is defined in .code-workspace file + if (asconfigPath === undefined) { + vscode.window.showErrorMessage( + `Failed to debug SWF. Launch configurations in workspace files must specify asconfigPath field.` + ); + return; + } + let asconfigPathParts = debugConfiguration.asconfigPath.split(/[\\\/]/g); + if (asconfigPathParts.length < 2) { + vscode.window.showErrorMessage( + `Failed to debug SWF. Launch configurations in workspace files must specify asconfigPath starting with workspace folder name.` + ); + return; + } + let workspaceNameToFind = asconfigPathParts[0]; + workspaceFolder = vscode.workspace.workspaceFolders.find( + (workspaceFolder) => workspaceFolder.name == workspaceNameToFind + ); + if (!workspaceFolder) { + vscode.window.showErrorMessage( + `Failed to debug SWF. Workspace folder not found for file: ${asconfigPath}` + ); + return; + } + asconfigPath = asconfigPathParts.slice(1).join(path.sep); + } let asconfigJSON: any = null; if (workspaceFolder !== undefined) { - var asconfigPath = debugConfiguration.asconfigPath - ? debugConfiguration.asconfigPath - : FILE_NAME_ASCONFIG_JSON; + asconfigPath ??= FILE_NAME_ASCONFIG_JSON; if (!path.isAbsolute(asconfigPath)) { asconfigPath = path.resolve(workspaceFolder.uri.fsPath, asconfigPath); }