Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always expand indexables' full paths #1977

Merged
merged 1 commit into from
Apr 26, 2024
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 lib/ruby_indexer/lib/ruby_indexer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def indexables
load_path_entry = T.let(nil, T.nilable(String))

Dir.glob(pattern, File::FNM_PATHNAME | File::FNM_EXTGLOB).map! do |path|
path = File.expand_path(path)
Copy link
Member

Choose a reason for hiding this comment

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

Expand path doesn't do anything if the path is already absolute, right? Trying to confirm that we'll continue supporting glob patterns based on absolute paths (e.g.: /Users/username/somewhere/**/*.rb)

Copy link
Member Author

Choose a reason for hiding this comment

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

No it doesn't do anything in that case:

irb(main):005> File.expand_path("lib")
=> "/Users/hung-wulo/src/github.com/ruby/irb/lib"
irb(main):006> File.join(Dir.pwd, "lib")
=> "/Users/hung-wulo/src/github.com/ruby/irb/lib"
irb(main):007> File.expand_path(File.join(Dir.pwd, "lib"))
=> "/Users/hung-wulo/src/github.com/ruby/irb/lib"

# All entries for the same pattern match the same $LOAD_PATH entry. Since searching the $LOAD_PATH for every
# entry is expensive, we memoize it until we find a path that doesn't belong to that $LOAD_PATH. This happens
# on repositories that define multiple gems, like Rails. All frameworks are defined inside the Dir.pwd, but
Expand Down
8 changes: 8 additions & 0 deletions lib/ruby_indexer/test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def test_load_configuration_executes_configure_block
assert(indexables.none? { |indexable| indexable.full_path == __FILE__ })
end

def test_indexables_have_expanded_full_paths
@config.apply_config({ "included_patterns" => ["**/*.rb"] })
indexables = @config.indexables

# All paths should be expanded
assert(indexables.none? { |indexable| indexable.full_path.start_with?("lib/") })
end

def test_indexables_only_includes_gem_require_paths
indexables = @config.indexables

Expand Down
Loading