From 04d71ae53d38e936708380c775c5e0147c65136b Mon Sep 17 00:00:00 2001 From: Philipp Polterauer Date: Fri, 9 Feb 2024 22:13:46 +0100 Subject: [PATCH 1/2] added ${workspaceFolder} handling to rosSetupScript --- src/extension.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index a1e0d728..e127af8a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -240,7 +240,7 @@ async function activateEnvironment(context: vscode.ExtensionContext) { // http://www.ros.org/reps/rep-0149.html#environment-variables // Learn more about ROS_VERSION definition. selectROSApi(env.ROS_VERSION); - + // Do this again, after the build tool has been determined. await sourceRosAndWorkspace(); @@ -322,8 +322,19 @@ async function sourceRosAndWorkspace(): Promise { let attemptWorkspaceDiscovery = true; if (rosSetupScript) { + // Regular expression to match '${workspaceFolder}' + const regex = "\$\{workspaceFolder\}"; + if (rosSetupScript.includes(regex)) { + if (vscode.workspace.workspaceFolders.length === 1) { + // Replace all occurrences of '${workspaceFolder}' with the workspace string + rosSetupScript = rosSetupScript.replace(regex, vscode.workspace.workspaceFolders[0].uri.fsPath); + } else { + vscode.window.showErrorMessage(`Multiple or No workspaces found, but the ROS setup script setting \"ros.rosSetupScript\" is configured with '${rosSetupScript}'`); + } + } + // Try to support cases where the setup script doesn't make sense on different environments, such as host vs container. - if (await pfs.exists(rosSetupScript)){ + if (await pfs.exists(rosSetupScript)) { try { newEnv = await ros_utils.sourceSetupFile(rosSetupScript, newEnv); @@ -335,14 +346,13 @@ async function sourceRosAndWorkspace(): Promise { } } } - + if (attemptWorkspaceDiscovery) { let distro = config.get("distro", ""); // Is there a distro defined either by setting or environment? outputChannel.appendLine(`Current ROS_DISTRO environment variable: ${process.env.ROS_DISTRO}`); - if (!distro) - { + if (!distro) { // No? Try to find one. const installedDistros = await ros_utils.getDistros(); if (!installedDistros.length) { @@ -351,7 +361,7 @@ async function sourceRosAndWorkspace(): Promise { throw new Error("ROS has not been found on this system."); } else if (installedDistros.length === 1) { outputChannel.appendLine(`Only one distro, selecting ${installedDistros[0]}`); - + // if there is only one distro installed, directly choose it config.update("distro", installedDistros[0]); distro = installedDistros[0]; @@ -420,7 +430,7 @@ async function sourceRosAndWorkspace(): Promise { if (await pfs.exists(wsSetupScript)) { outputChannel.appendLine(`Workspace overlay path: ${wsSetupScript}`); - + try { newEnv = await ros_utils.sourceSetupFile(wsSetupScript, newEnv); } catch (_err) { From a7198a14bdc097e73b6f042f807444c6a19c60b1 Mon Sep 17 00:00:00 2001 From: Philipp Polterauer Date: Fri, 9 Feb 2024 22:56:11 +0100 Subject: [PATCH 2/2] replaced errorMessage with outputchannel --- src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index e127af8a..5c8bab48 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -329,7 +329,7 @@ async function sourceRosAndWorkspace(): Promise { // Replace all occurrences of '${workspaceFolder}' with the workspace string rosSetupScript = rosSetupScript.replace(regex, vscode.workspace.workspaceFolders[0].uri.fsPath); } else { - vscode.window.showErrorMessage(`Multiple or No workspaces found, but the ROS setup script setting \"ros.rosSetupScript\" is configured with '${rosSetupScript}'`); + outputChannel.appendLine(`Multiple or no workspaces found, but the ROS setup script setting \"ros.rosSetupScript\" is configured with '${rosSetupScript}'`); } }