Skip to content
Merged
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem "minitest"
gem "rubocop"
gem "rubocop-shopify"
gem "extconf_compile_commands_json"
gem "rbs"

# Gems that aren't supported on Windows
platforms :ruby do
Expand Down
10 changes: 8 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ GEM
json (2.18.0)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
mini_portile2 (2.8.9)
minitest (6.0.1)
prism (~> 1.5)
Expand All @@ -29,6 +30,9 @@ GEM
rake (13.3.1)
rake-compiler (1.3.0)
rake
rbs (3.10.3)
logger
tsort
regexp_parser (2.11.3)
rubocop (1.81.7)
json (~> 2.3)
Expand All @@ -49,23 +53,25 @@ GEM
ruby-progressbar (1.13.0)
ruby_memcheck (3.0.1)
nokogiri
tsort (0.2.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)

PLATFORMS
arm64-darwin-23
arm64-darwin-24
ruby

DEPENDENCIES
extconf_compile_commands_json
minitest
rake (~> 13.3)
rake-compiler
rbs
rubocop
rubocop-shopify
ruby_memcheck
rubydex!

BUNDLED WITH
4.0.3
4.0.7
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
29 changes: 29 additions & 0 deletions test/graph_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,35 @@ def test_workspace_paths
end
end

def test_index_workspace_includes_rbs_core_definitions
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

def test_index_workspace_includes_user_defined_rbs_files
with_context do |context|
context.write!("sig/foo.rbs", <<~RBS)
class Foo
end
RBS

graph = Rubydex::Graph.new(workspace_path: context.absolute_path)
graph.index_workspace
graph.resolve

assert_equal("Foo", graph["Foo"].name)
end
end

private

def assert_diagnostics(expected, actual)
Expand Down
Loading