Skip to content

Commit 53dfb04

Browse files
committed
Avoid requiring json for chruby activation
1 parent aa56380 commit 53dfb04

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

vscode/src/ruby/chruby.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ interface RubyVersion {
1313
version: string;
1414
}
1515

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

186187
const result = await this.runScript(
187-
`${rubyExecutableUri.fsPath} -W0 -rjson -e '${script}'`,
188+
`${rubyExecutableUri.fsPath} -W0 -e '${script}'`,
188189
);
189190

190-
return this.parseWithErrorHandling(result.stderr);
191+
const [defaultGems, gemHome, yjit, version] =
192+
result.stderr.split(ACTIVATION_SEPARATOR);
193+
194+
return { defaultGems, gemHome, yjit: yjit === "true", version };
191195
}
192196
}

0 commit comments

Comments
 (0)