Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Fix alternative Ruby activation (#851)
Browse files Browse the repository at this point in the history
* Fix alternative Ruby activation

* Use cwd when searching for `.ruby-version`

Co-authored-by: Ufuk Kayserilioglu <ufuk.kayserilioglu@shopify.com>

---------

Co-authored-by: Ufuk Kayserilioglu <ufuk.kayserilioglu@shopify.com>
  • Loading branch information
vinistock and paracycle authored Oct 19, 2023
1 parent 35030ea commit 8b2850c
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class Ruby {
private _error = false;
private readonly context: vscode.ExtensionContext;
private readonly customBundleGemfile?: string;
private readonly cwd: string;
private readonly outputChannel: vscode.OutputChannel;

constructor(
Expand All @@ -50,6 +51,10 @@ export class Ruby {
? customBundleGemfile
: path.resolve(path.join(this.workingFolder, customBundleGemfile));
}

this.cwd = this.customBundleGemfile
? path.dirname(this.customBundleGemfile)
: this.workingFolder;
}

get versionManager() {
Expand Down Expand Up @@ -135,11 +140,7 @@ export class Ruby {
);
}

const cwd = this.customBundleGemfile
? path.dirname(this.customBundleGemfile)
: this.workingFolder;

const result = await asyncExec("shadowenv hook --json", { cwd });
const result = await asyncExec("shadowenv hook --json", { cwd: this.cwd });

if (result.stdout.trim() === "") {
result.stdout = "{ }";
Expand Down Expand Up @@ -167,18 +168,11 @@ export class Ruby {
command += "'";
}

// If there's a custom bundle configured by the user, we need to activate the Ruby version in that folder, so that
// they can place configuration files such as `.ruby-version` there and use a different Ruby version than the
// project they are working on
const cwd = this.customBundleGemfile
? path.dirname(this.customBundleGemfile)
: this.workingFolder;

this.outputChannel.appendLine(
`Ruby LSP> Trying to activate Ruby environment with command: ${command} inside directory: ${cwd}`,
`Ruby LSP> Trying to activate Ruby environment with command: ${command} inside directory: ${this.cwd}`,
);

const result = await asyncExec(command, { cwd });
const result = await asyncExec(command, { cwd: this.cwd });

const envJson = /RUBY_ENV_ACTIVATE(.*)RUBY_ENV_ACTIVATE/.exec(
result.stdout,
Expand All @@ -190,7 +184,7 @@ export class Ruby {
private async fetchRubyInfo() {
const rubyInfo = await asyncExec(
"ruby -e 'puts \"#{RUBY_VERSION},#{defined?(RubyVM::YJIT)}\"'",
{ env: this._env },
{ env: this._env, cwd: this.cwd },
);

const [rubyVersion, yjitIsDefined] = rubyInfo.stdout.trim().split(",");
Expand Down Expand Up @@ -248,7 +242,7 @@ export class Ruby {
}

private readRubyVersion() {
let dir = this.workingFolder;
let dir = this.cwd;

while (fs.existsSync(dir)) {
const versionFile = path.join(dir, ".ruby-version");
Expand Down

0 comments on commit 8b2850c

Please sign in to comment.