Skip to content

Expose require path resolution to Ruby API#555

Merged
alexcrocha merged 1 commit intomainfrom
02-03-expose_require_path_resolution_to_ruby_api
Feb 4, 2026
Merged

Expose require path resolution to Ruby API#555
alexcrocha merged 1 commit intomainfrom
02-03-expose_require_path_resolution_to_ruby_api

Conversation

@alexcrocha
Copy link
Contributor

@alexcrocha alexcrocha commented Feb 3, 2026

Follow-up to #528, and a step towards #411.

This PR adds FFI and C bindings to expose resolve_require_path to Ruby, returning a Document that can be used directly for go-to-definition on require statements.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@alexcrocha alexcrocha marked this pull request as ready for review February 3, 2026 23:17
@alexcrocha alexcrocha requested a review from a team as a code owner February 3, 2026 23:17
@alexcrocha alexcrocha force-pushed the 02-03-expose_require_path_resolution_to_ruby_api branch 2 times, most recently from a1e279c to 6f99d8c Compare February 3, 2026 23:45
@alexcrocha alexcrocha self-assigned this Feb 4, 2026
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

Nice

@vinistock vinistock added the enhancement New feature or request label Feb 4, 2026
Expose the Rust require path resolution through FFI and C bindings,
allowing Ruby to resolve a require path (e.g., foo/bar) to its
Document given a list of load paths.

This enables go-to-definition functionality for require statements in
editors.
@alexcrocha alexcrocha force-pushed the 02-03-expose_require_path_resolution_to_ruby_api branch from 6f99d8c to 39f23a3 Compare February 4, 2026 17:26
@alexcrocha alexcrocha merged commit e823ef5 into main Feb 4, 2026
27 checks passed
@alexcrocha alexcrocha deleted the 02-03-expose_require_path_resolution_to_ruby_api branch February 4, 2026 17:47
graph.index_all(context.glob("**/*.rb"))

load_paths = [context.absolute_path_to("lib")]
document = graph.resolve_require_path("foo/bar", load_paths)
Copy link
Contributor

Choose a reason for hiding this comment

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

What would happen with this scenario?

context.write!("lib/foo/bar.rb", "class Bar; end")
context.write!("test/foo/bar.rb", "class Bar; end")

load_paths = [context.absolute_path_to("lib"), context.absolute_path_to("test")]
graph.resolve_require_path("foo/bar", load_paths)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, this was a race condition 😄 earliest path should win, not whichever thread completes first. Fixed in #580 and added a test with your scenario too.

Also took the chance to dedup the shared logic with require_paths as you suggested in #537.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants