Skip to content

Commit

Permalink
Avoid requiring json for chruby activation
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Aug 13, 2024
1 parent aa56380 commit 53dfb04
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions vscode/src/ruby/chruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface RubyVersion {
version: string;
}

const ACTIVATION_SEPARATOR = "ACTIVATION_SEPARATOR";

// A tool to change the current Ruby version
// Learn more: https://github.com/postmodern/chruby
export class Chruby extends VersionManager {
Expand Down Expand Up @@ -179,14 +181,16 @@ export class Chruby extends VersionManager {
"end",
`newer_gem_home = File.join(File.dirname(user_dir), "${rubyVersion.version}")`,
"gems = (Dir.exist?(newer_gem_home) ? newer_gem_home : user_dir)",
"data = { defaultGems: Gem.default_dir, gemHome: gems, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }",
"STDERR.print(JSON.dump(data))",
`STDERR.print([Gem.default_dir, gems, !!defined?(RubyVM::YJIT), RUBY_VERSION].join("${ACTIVATION_SEPARATOR}"))`,
].join(";");

const result = await this.runScript(
`${rubyExecutableUri.fsPath} -W0 -rjson -e '${script}'`,
`${rubyExecutableUri.fsPath} -W0 -e '${script}'`,
);

return this.parseWithErrorHandling(result.stderr);
const [defaultGems, gemHome, yjit, version] =
result.stderr.split(ACTIVATION_SEPARATOR);

return { defaultGems, gemHome, yjit: yjit === "true", version };
}
}

0 comments on commit 53dfb04

Please sign in to comment.