Skip to content

Commit

Permalink
Use URI for collecting indexables
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Nov 27, 2024
1 parent ccaf704 commit f80b3e1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/ruby_indexer/lib/ruby_indexer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def merged_excluded_file_pattern
.then { |dirs| File.join(@workspace_path, "{#{dirs.join(",")}}/**/*") }
end

sig { returns(T::Array[IndexablePath]) }
sig { returns(T::Array[URI::Generic]) }
def indexables
excluded_gems = @excluded_gems - @included_gems
locked_gems = Bundler.locked_gems&.specs
Expand All @@ -107,12 +107,12 @@ def indexables
[included_path, relative_path]
end

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

# 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)
indexables << URI::Generic.from_path(path: path)
end

# Add user specified patterns
Expand All @@ -134,7 +134,7 @@ def indexables
load_path_entry = $LOAD_PATH.find { |load_path| path.start_with?(load_path) }
end

indexables << IndexablePath.new(load_path_entry, path)
indexables << URI::Generic.from_path(path: path, load_path_entry: load_path_entry)
end
end
end
Expand Down Expand Up @@ -184,12 +184,12 @@ def indexables
# If the default_path is a directory, we index all the Ruby files in it
indexables.concat(
Dir.glob(File.join(default_path, "**", "*.rb"), File::FNM_PATHNAME | File::FNM_EXTGLOB).map! do |path|
IndexablePath.new(RbConfig::CONFIG["rubylibdir"], path)
URI::Generic.from_path(path: path, load_path_entry: RbConfig::CONFIG["rubylibdir"])
end,
)
elsif pathname.extname == ".rb"
# If the default_path is a Ruby file, we index it
indexables << IndexablePath.new(RbConfig::CONFIG["rubylibdir"], default_path)
indexables << URI::Generic.from_path(path: default_path, load_path_entry: RbConfig::CONFIG["rubylibdir"])
end
end

Expand All @@ -207,7 +207,9 @@ def indexables
indexables.concat(
spec.require_paths.flat_map do |require_path|
load_path_entry = File.join(spec.full_gem_path, require_path)
Dir.glob(File.join(load_path_entry, "**", "*.rb")).map! { |path| IndexablePath.new(load_path_entry, path) }
Dir.glob(File.join(load_path_entry, "**", "*.rb")).map! do |path|
URI::Generic.from_path(path: path, load_path_entry: load_path_entry)
end
end,
)
rescue Gem::MissingSpecError
Expand All @@ -216,7 +218,7 @@ def indexables
# just ignore if they're missing
end

indexables.uniq!(&:full_path)
indexables.uniq!(&:to_s)
indexables
end

Expand Down

0 comments on commit f80b3e1

Please sign in to comment.