Skip to content

Commit bbb8d49

Browse files
committed
Include RBS paths when indexing workspace
1 parent 54a44a6 commit bbb8d49

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

lib/rubydex/graph.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def workspace_paths
4545
end
4646

4747
add_workspace_dependency_paths(paths)
48+
add_core_rbs_definition_paths(paths)
4849
paths.uniq!
4950
paths
5051
end
@@ -71,5 +72,21 @@ def add_workspace_dependency_paths(paths)
7172
nil
7273
end
7374
end
75+
76+
# Searches for the latest installation of the `rbs` gem and adds the paths for the core and stdlib RBS definitions
77+
# to the list of paths. This method does not require `rbs` to be a part of the bundle. It searches for whatever
78+
# latest installation of `rbs` exists in the system and fails silently if we can't find one
79+
#
80+
#: (Array[String]) -> void
81+
def add_core_rbs_definition_paths(paths)
82+
rbs_gem_path = Gem.path
83+
.flat_map { |path| Dir.glob(File.join(path, "gems", "rbs-[0-9]*/")) }
84+
.max_by { |path| Gem::Version.new(File.basename(path).delete_prefix("rbs-")) }
85+
86+
return unless rbs_gem_path
87+
88+
paths << File.join(rbs_gem_path, "core")
89+
paths << File.join(rbs_gem_path, "stdlib")
90+
end
7491
end
7592
end

test/graph_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,20 @@ def test_workspace_paths
560560
end
561561
end
562562

563+
def test_index_workspace_includes_rbs_core_definitions
564+
graph = Rubydex::Graph.new
565+
graph.index_workspace
566+
graph.resolve
567+
568+
["Kernel", "Object", "BasicObject", "Integer"].each do |core_namespace|
569+
rbs_kernel = graph[core_namespace].definitions.find do |definition|
570+
uri = URI(definition.location.uri)
571+
File.extname(uri.path) == ".rbs"
572+
end
573+
assert(rbs_kernel, "Expected to find RBS definition for `#{core_namespace}` in the graph")
574+
end
575+
end
576+
563577
private
564578

565579
def assert_diagnostics(expected, actual)

0 commit comments

Comments
 (0)