Skip to content

Commit

Permalink
Ensure top level scripts are indexed (#2849)
Browse files Browse the repository at this point in the history
### Motivation

With the optimizations to prevent descending into directories that we know are going to be excluded, we accidentally stopped indexing top level scripts.

### Implementation

Since the code now lists directories to eagerly exclude them, we need a separate path for the top level scripts.

### Automated Tests

Added a test that reproduces the issue.
  • Loading branch information
vinistock authored Nov 14, 2024
1 parent 0eaaee1 commit e6a3703
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/ruby_indexer/lib/ruby_indexer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def indexables

indexables = T.let([], T::Array[IndexablePath])

# Handle top level files separately. The path below is an optimization to prevent descending down directories that
# are going to be excluded anyway, so we need to handle top level scripts separately
Dir.glob(File.join(@workspace_path, "*.rb"), flags).each do |path|
indexables << IndexablePath.new(nil, path)
end

# Add user specified patterns
@included_patterns.each do |pattern|
load_path_entry = T.let(nil, T.nilable(String))
Expand Down
10 changes: 10 additions & 0 deletions lib/ruby_indexer/test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,15 @@ def test_indexables_respect_given_workspace_path
)
end
end

def test_includes_top_level_files
Dir.mktmpdir do |dir|
FileUtils.touch(File.join(dir, "find_me.rb"))
@config.workspace_path = dir

indexables = @config.indexables
assert(indexables.find { |i| File.basename(i.full_path) == "find_me.rb" })
end
end
end
end

0 comments on commit e6a3703

Please sign in to comment.