Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/rubydex/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def workspace_paths
end

add_workspace_dependency_paths(paths)
add_core_rbs_definition_paths(paths)
paths.uniq!
paths
end
Expand All @@ -71,5 +72,21 @@ def add_workspace_dependency_paths(paths)
nil
end
end

# Searches for the latest installation of the `rbs` gem and adds the paths for the core and stdlib RBS definitions
# to the list of paths. This method does not require `rbs` to be a part of the bundle. It searches for whatever
# latest installation of `rbs` exists in the system and fails silently if we can't find one
#
#: (Array[String]) -> void
def add_core_rbs_definition_paths(paths)
rbs_gem_path = Gem.path
.flat_map { |path| Dir.glob(File.join(path, "gems", "rbs-[0-9]*/")) }
.max_by { |path| Gem::Version.new(File.basename(path).delete_prefix("rbs-")) }

return unless rbs_gem_path

paths << File.join(rbs_gem_path, "core")
paths << File.join(rbs_gem_path, "stdlib")
end
end
end
17 changes: 17 additions & 0 deletions test/graph_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,23 @@ def test_workspace_paths
end
end

def test_index_workspace_includes_rbs_core_definitions
# Ensure the `rbs` gem is installed on CI
Gem.install("rbs") if ENV["CI"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if Gem.install in a test is the right approach here — it's a side effect that modifies the system state during a test run.

Should we add it to the tests group in the Gemfile instead?

Another solution is to only install the gem in the context as we do in Tapioca: https://github.com/Shopify/tapioca/blob/main/spec/tapioca/cli/gem_spec.rb#L120-L125


graph = Rubydex::Graph.new
graph.index_workspace
graph.resolve

["Kernel", "Object", "BasicObject", "Integer"].each do |core_namespace|
rbs_kernel = graph[core_namespace].definitions.find do |definition|
uri = URI(definition.location.uri)
File.extname(uri.path) == ".rbs"
end
assert(rbs_kernel, "Expected to find RBS definition for `#{core_namespace}` in the graph")
end
end

private

def assert_diagnostics(expected, actual)
Expand Down
Loading