Skip to content

Commit

Permalink
added ${workspaceFolder} handling to rosSetupScript (#1275)
Browse files Browse the repository at this point in the history
* added ${workspaceFolder} handling to rosSetupScript

* replaced errorMessage with outputchannel
  • Loading branch information
PhilippPolterauer authored Feb 11, 2024
1 parent 0fe6e4c commit 814a8ef
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -322,8 +322,19 @@ async function sourceRosAndWorkspace(): Promise<void> {
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 {
outputChannel.appendLine(`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);

Expand All @@ -335,14 +346,13 @@ async function sourceRosAndWorkspace(): Promise<void> {
}
}
}

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) {
Expand All @@ -351,7 +361,7 @@ async function sourceRosAndWorkspace(): Promise<void> {
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];
Expand Down Expand Up @@ -420,7 +430,7 @@ async function sourceRosAndWorkspace(): Promise<void> {

if (await pfs.exists(wsSetupScript)) {
outputChannel.appendLine(`Workspace overlay path: ${wsSetupScript}`);

try {
newEnv = await ros_utils.sourceSetupFile(wsSetupScript, newEnv);
} catch (_err) {
Expand Down

0 comments on commit 814a8ef

Please sign in to comment.