Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RBS collection cannot load signature for default gem. #2226

Open
ksss opened this issue Jan 9, 2025 · 1 comment
Open

RBS collection cannot load signature for default gem. #2226

ksss opened this issue Jan 9, 2025 · 1 comment

Comments

@ksss
Copy link
Collaborator

ksss commented Jan 9, 2025

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
Copy link
Collaborator Author

ksss commented Jan 9, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant