File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
7592end
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments