File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ gem "minitest"
1111gem "rubocop"
1212gem "rubocop-shopify"
1313gem "extconf_compile_commands_json"
14+ gem "rbs"
1415
1516# Gems that aren't supported on Windows
1617platforms :ruby do
Original file line number Diff line number Diff line change 1111 json (2.18.0 )
1212 language_server-protocol (3.17.0.5 )
1313 lint_roller (1.1.0 )
14+ logger (1.7.0 )
1415 mini_portile2 (2.8.9 )
1516 minitest (6.0.1 )
1617 prism (~> 1.5 )
2930 rake (13.3.1 )
3031 rake-compiler (1.3.0 )
3132 rake
33+ rbs (3.10.3 )
34+ logger
35+ tsort
3236 regexp_parser (2.11.3 )
3337 rubocop (1.81.7 )
3438 json (~> 2.3 )
4953 ruby-progressbar (1.13.0 )
5054 ruby_memcheck (3.0.1 )
5155 nokogiri
56+ tsort (0.2.0 )
5257 unicode-display_width (3.2.0 )
5358 unicode-emoji (~> 4.1 )
5459 unicode-emoji (4.2.0 )
5560
5661PLATFORMS
57- arm64-darwin-23
62+ arm64-darwin-24
5863 ruby
5964
6065DEPENDENCIES
6166 extconf_compile_commands_json
6267 minitest
6368 rake (~> 13.3 )
6469 rake-compiler
70+ rbs
6571 rubocop
6672 rubocop-shopify
6773 ruby_memcheck
6874 rubydex !
6975
7076BUNDLED WITH
71- 4.0.3
77+ 4.0.7
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,35 @@ 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+
577+ def test_index_workspace_includes_user_defined_rbs_files
578+ with_context do |context |
579+ context . write! ( "sig/foo.rbs" , <<~RBS )
580+ class Foo
581+ end
582+ RBS
583+
584+ graph = Rubydex ::Graph . new ( workspace_path : context . absolute_path )
585+ graph . index_workspace
586+ graph . resolve
587+
588+ assert_equal ( "Foo" , graph [ "Foo" ] . name )
589+ end
590+ end
591+
563592 private
564593
565594 def assert_diagnostics ( expected , actual )
You can’t perform that action at this time.
0 commit comments