@@ -70,6 +70,41 @@ export class Chruby extends VersionManager {
70
70
} ;
71
71
}
72
72
73
+ // Run the activation script using the Ruby installation we found so that we can discover gem paths
74
+ protected async runActivationScript ( rubyExecutableUri : vscode . Uri ) : Promise < {
75
+ defaultGems : string ;
76
+ gemHome : string ;
77
+ yjit : boolean ;
78
+ version : string ;
79
+ } > {
80
+ // Typically, GEM_HOME points to $HOME/.gem/ruby/version_without_patch. For example, for Ruby 3.2.2, it would be
81
+ // $HOME/.gem/ruby/3.2.0. However, chruby overrides GEM_HOME to use the patch part of the version, resulting in
82
+ // $HOME/.gem/ruby/3.2.2. In our activation script, we check if a directory using the patch exists and then prefer
83
+ // that over the default one.
84
+ const script = [
85
+ "user_dir = Gem.user_dir" ,
86
+ "paths = Gem.path" ,
87
+ "if paths.length > 2" ,
88
+ " paths.delete(Gem.default_dir)" ,
89
+ " paths.delete(Gem.user_dir)" ,
90
+ " if paths[0]" ,
91
+ " user_dir = paths[0] if Dir.exist?(paths[0])" ,
92
+ " end" ,
93
+ "end" ,
94
+ "newer_gem_home = File.join(File.dirname(user_dir), RUBY_VERSION)" ,
95
+ "gems = (Dir.exist?(newer_gem_home) ? newer_gem_home : user_dir)" ,
96
+ "data = { defaultGems: Gem.default_dir, gemHome: gems, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }" ,
97
+ "STDERR.print(JSON.dump(data))" ,
98
+ ] . join ( ";" ) ;
99
+
100
+ const result = await asyncExec (
101
+ `${ rubyExecutableUri . fsPath } -W0 -rjson -e '${ script } '` ,
102
+ { cwd : this . bundleUri . fsPath } ,
103
+ ) ;
104
+
105
+ return this . parseWithErrorHandling ( result . stderr ) ;
106
+ }
107
+
73
108
// Returns the full URI to the Ruby executable
74
109
protected async findRubyUri ( rubyVersion : RubyVersion ) : Promise < vscode . Uri > {
75
110
if ( / \d + \. \d + \. \d + / . exec ( rubyVersion . version ) ) {
@@ -179,39 +214,4 @@ export class Chruby extends VersionManager {
179
214
180
215
throw new Error ( "No .ruby-version file was found" ) ;
181
216
}
182
-
183
- // Run the activation script using the Ruby installation we found so that we can discover gem paths
184
- private async runActivationScript ( rubyExecutableUri : vscode . Uri ) : Promise < {
185
- defaultGems : string ;
186
- gemHome : string ;
187
- yjit : boolean ;
188
- version : string ;
189
- } > {
190
- // Typically, GEM_HOME points to $HOME/.gem/ruby/version_without_patch. For example, for Ruby 3.2.2, it would be
191
- // $HOME/.gem/ruby/3.2.0. However, chruby overrides GEM_HOME to use the patch part of the version, resulting in
192
- // $HOME/.gem/ruby/3.2.2. In our activation script, we check if a directory using the patch exists and then prefer
193
- // that over the default one.
194
- const script = [
195
- "user_dir = Gem.user_dir" ,
196
- "paths = Gem.path" ,
197
- "if paths.length > 2" ,
198
- " paths.delete(Gem.default_dir)" ,
199
- " paths.delete(Gem.user_dir)" ,
200
- " if paths[0]" ,
201
- " user_dir = paths[0] if Dir.exist?(paths[0])" ,
202
- " end" ,
203
- "end" ,
204
- "newer_gem_home = File.join(File.dirname(user_dir), RUBY_VERSION)" ,
205
- "gems = (Dir.exist?(newer_gem_home) ? newer_gem_home : user_dir)" ,
206
- "data = { defaultGems: Gem.default_dir, gemHome: gems, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }" ,
207
- "STDERR.print(JSON.dump(data))" ,
208
- ] . join ( ";" ) ;
209
-
210
- const result = await asyncExec (
211
- `${ rubyExecutableUri . fsPath } -W0 -rjson -e '${ script } '` ,
212
- { cwd : this . bundleUri . fsPath } ,
213
- ) ;
214
-
215
- return this . parseWithErrorHandling ( result . stderr ) ;
216
- }
217
217
}
0 commit comments