Skip to content

Commit

Permalink
Fix default paths for rvm-auto-ruby
Browse files Browse the repository at this point in the history
This commit not only checks the path:

`/home/user/.rvm/bin` (done before)

It also checks if it is in the PATH already and in:
`/usr/local/rvm/bin`

It additionally adds some output if the initialization fails
  • Loading branch information
joennlae committed Apr 2, 2024
1 parent e95abde commit fb0366b
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions vscode/src/ruby/rvm.ts
Expand Up @@ -19,13 +19,53 @@ export class Rvm extends VersionManager {
".to_json)",
].join("");

const result = await asyncExec(
`${path.join(os.homedir(), ".rvm", "bin", "rvm-auto-ruby")} -W0 -rjson -e '${activationScript}'`,
{
cwd: this.bundleUri.fsPath,
},
);
const basePaths = [
path.join(os.homedir(), ".rvm", "bin"),
"/usr/local/rvm/bin",
"/usr/share/rvm/bin",
];
// check if rvm-auto-ruby is in the PATH
try {
const pathCheck = await asyncExec("which rvm-auto-ruby");
this.outputChannel.info(`Output check: ${pathCheck.stdout}`);
if (pathCheck.stdout.includes("rvm-auto-ruby")) {
// rvm-auto-ruby is in the PATH variable
basePaths.unshift("");
}
} catch (error) {
const pathOutput = await asyncExec("echo $PATH");
this.outputChannel.info(
`Could not find rvm-auto-ruby on PATH: ${error}, current PATH: ${pathOutput.stdout}`,
);
}

let result = { stderr: "" };
for (const basePath of basePaths) {
try {
const resultOfPath = await asyncExec(
`${path.join(basePath, "rvm-auto-ruby")} -W0 -rjson -e '${activationScript}'`,
{
cwd: this.bundleUri.fsPath,
},
);
result = resultOfPath;
this.outputChannel.info(
`Activated rvm env with this path: ${path.join(basePath, "rvm-auto-ruby")}`,
);
break;
} catch (error) {
this.outputChannel.info(
`Checking if we can activate rvm env with this path: ${path.join(basePath, "rvm-auto-ruby")}`,
);
}
}

if (result.stderr === "") {
this.outputChannel.error(
`Could not activate rvm based environment with these paths: ${basePaths.join(", ")}`,
);
return { error: true };
}
const parsedResult = JSON.parse(result.stderr);

// Invoking `rvm-auto-ruby` doesn't actually inject anything into the environment, it just finds the right Ruby to
Expand Down

0 comments on commit fb0366b

Please sign in to comment.