Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ${workspaceFolder} handling to rosSetupScript #1275

Merged
merged 2 commits into from
Feb 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading