From fb0366bedc2570a0c3bb5236ae8599dbaaf1c60b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Sch=C3=B6nleber?= Date: Tue, 2 Apr 2024 12:33:34 +0200 Subject: [PATCH] Fix default paths for `rvm-auto-ruby` 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 --- vscode/src/ruby/rvm.ts | 52 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/vscode/src/ruby/rvm.ts b/vscode/src/ruby/rvm.ts index c79cef96f..571a3363b 100644 --- a/vscode/src/ruby/rvm.ts +++ b/vscode/src/ruby/rvm.ts @@ -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