@@ -169,6 +169,45 @@ export class Chruby extends VersionManager {
169169    return  undefined ; 
170170  } 
171171
172+   // Run the activation script using the Ruby installation we found so that we can discover gem paths 
173+   protected  async  runActivationScript ( 
174+     rubyExecutableUri : vscode . Uri , 
175+     rubyVersion : RubyVersion , 
176+   ) : Promise < { 
177+     defaultGems : string ; 
178+     gemHome : string ; 
179+     yjit : boolean ; 
180+     version : string ; 
181+   } >  { 
182+     // Typically, GEM_HOME points to $HOME/.gem/ruby/version_without_patch. For example, for Ruby 3.2.2, it would be 
183+     // $HOME/.gem/ruby/3.2.0. However, chruby overrides GEM_HOME to use the patch part of the version, resulting in 
184+     // $HOME/.gem/ruby/3.2.2. In our activation script, we check if a directory using the patch exists and then prefer 
185+     // that over the default one. 
186+     const  script  =  [ 
187+       "user_dir = Gem.user_dir" , 
188+       "paths = Gem.path" , 
189+       "if paths.length > 2" , 
190+       "  paths.delete(Gem.default_dir)" , 
191+       "  paths.delete(Gem.user_dir)" , 
192+       "  if paths[0]" , 
193+       "    user_dir = paths[0] if Dir.exist?(paths[0])" , 
194+       "  end" , 
195+       "end" , 
196+       `newer_gem_home = File.join(File.dirname(user_dir), "${ rubyVersion . version }  ")` , 
197+       "gems = (Dir.exist?(newer_gem_home) ? newer_gem_home : user_dir)" , 
198+       `STDERR.print([Gem.default_dir, gems, !!defined?(RubyVM::YJIT), RUBY_VERSION].join("${ ACTIVATION_SEPARATOR }  "))` , 
199+     ] . join ( ";" ) ; 
200+ 
201+     const  result  =  await  this . runScript ( 
202+       `${ rubyExecutableUri . fsPath }   -W0 -e '${ script }  '` , 
203+     ) ; 
204+ 
205+     const  [ defaultGems ,  gemHome ,  yjit ,  version ]  = 
206+       result . stderr . split ( ACTIVATION_SEPARATOR ) ; 
207+ 
208+     return  {  defaultGems,  gemHome,  yjit : yjit  ===  "true" ,  version } ; 
209+   } 
210+ 
172211  private  async  findClosestRubyInstallation ( rubyVersion : RubyVersion ) : Promise < { 
173212    uri : vscode . Uri ; 
174213    rubyVersion : RubyVersion ; 
@@ -443,45 +482,6 @@ export class Chruby extends VersionManager {
443482    throw  new  Error ( "Cannot find any Ruby installations" ) ; 
444483  } 
445484
446-   // Run the activation script using the Ruby installation we found so that we can discover gem paths 
447-   private  async  runActivationScript ( 
448-     rubyExecutableUri : vscode . Uri , 
449-     rubyVersion : RubyVersion , 
450-   ) : Promise < { 
451-     defaultGems : string ; 
452-     gemHome : string ; 
453-     yjit : boolean ; 
454-     version : string ; 
455-   } >  { 
456-     // Typically, GEM_HOME points to $HOME/.gem/ruby/version_without_patch. For example, for Ruby 3.2.2, it would be 
457-     // $HOME/.gem/ruby/3.2.0. However, chruby overrides GEM_HOME to use the patch part of the version, resulting in 
458-     // $HOME/.gem/ruby/3.2.2. In our activation script, we check if a directory using the patch exists and then prefer 
459-     // that over the default one. 
460-     const  script  =  [ 
461-       "user_dir = Gem.user_dir" , 
462-       "paths = Gem.path" , 
463-       "if paths.length > 2" , 
464-       "  paths.delete(Gem.default_dir)" , 
465-       "  paths.delete(Gem.user_dir)" , 
466-       "  if paths[0]" , 
467-       "    user_dir = paths[0] if Dir.exist?(paths[0])" , 
468-       "  end" , 
469-       "end" , 
470-       `newer_gem_home = File.join(File.dirname(user_dir), "${ rubyVersion . version }  ")` , 
471-       "gems = (Dir.exist?(newer_gem_home) ? newer_gem_home : user_dir)" , 
472-       `STDERR.print([Gem.default_dir, gems, !!defined?(RubyVM::YJIT), RUBY_VERSION].join("${ ACTIVATION_SEPARATOR }  "))` , 
473-     ] . join ( ";" ) ; 
474- 
475-     const  result  =  await  this . runScript ( 
476-       `${ rubyExecutableUri . fsPath }   -W0 -e '${ script }  '` , 
477-     ) ; 
478- 
479-     const  [ defaultGems ,  gemHome ,  yjit ,  version ]  = 
480-       result . stderr . split ( ACTIVATION_SEPARATOR ) ; 
481- 
482-     return  {  defaultGems,  gemHome,  yjit : yjit  ===  "true" ,  version } ; 
483-   } 
484- 
485485  private  missingRubyError ( version : string )  { 
486486    return  new  Error ( `Cannot find Ruby installation for version ${ version }  ` ) ; 
487487  } 
0 commit comments