rbs icon indicating copy to clipboard operation
rbs copied to clipboard

RBS collection cannot load signature for default gem.

Open ksss opened this issue 11 months ago • 1 comments

ruby: v3.4.1 rbs: v3.8.1

prism v1.2.0 is bundled as default gem with ruby v3.4. link

But rbs collection cannot found it.

RBS::EnvironmentLoader.gem_sig_path('prism', '1.2.0')
#=> nil

Gem::Specification.find_by_name('prism', '1.2.0').gem_dir
#=> "/Users/yuki.kurihara/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/prism-1.2.0"

Dir[Gem::Specification.find_by_name('prism', '1.2.0').gem_dir + "/*"]
#=> []

Even if the gem directory can be found, the sig directory is not synchronised by default gem and cannot be consulted.

https://github.com/ruby/ruby/blob/48d4efcb85000e1ebae42004e963b5d0cedddcf2/tool/sync_default_gems.rb#L376-L398

ksss avatar Jan 09 '25 04:01 ksss

My Current Plan

For ruby side

Sync sig dir from prism from tool/sync_default_gems.rb.

diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb
index 677ed03f55..5624261493 100755
--- a/tool/sync_default_gems.rb
+++ b/tool/sync_default_gems.rb
@@ -391,6 +391,10 @@ def sync_default_gems(gem)
       rm_rf("prism/templates/rbi")
       rm_rf("prism/templates/sig")

+      cp_r("#{upstream}/sig", "prism/")
+      rm_rf("prism/sig/_shims")
+      rm_rf("prism/sig/prism/_private")
+
       rm("test/prism/snapshots_test.rb")
       rm_rf("test/prism/snapshots")

For rbs side

Read sig dir for default gems.

diff --git a/lib/rbs/environment_loader.rb b/lib/rbs/environment_loader.rb
index cdfde833..8e6edebc 100644
--- a/lib/rbs/environment_loader.rb
+++ b/lib/rbs/environment_loader.rb
@@ -29,7 +29,11 @@ module RBS
       requirements = [] #: Array[String]
       requirements << version if version
       spec = Gem::Specification.find_by_name(name, *requirements)
-      path = Pathname(spec.gem_dir) + "sig"
+      path = if spec.default_gem?
+        Pathname("#{RbConfig::CONFIG["rubylibdir"]}/#{name}/sig")
+      else
+        Pathname(spec.gem_dir) + "sig"
+      end
       if path.directory?
         [spec, path]
       end

ksss avatar Jan 09 '25 14:01 ksss