Skip to content

Commit 3b5a9ff

Browse files
authored
Rename indexables to indexable_uris (Shopify#2924)
<!-- NOTE: If you plan to invest significant effort into a large pull request with multiple decisions that may impact the long term maintenance of the Ruby LSP, please open a [discussion](https://github.com/Shopify/ruby-lsp/discussions/new/choose) first to align on the direction. --> ### Motivation Addresses Shopify#2916 (comment) Rename `indexables` to `indexable_uris`, which is a much clearer name.
1 parent 99d322a commit 3b5a9ff

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed

exe/ruby-lsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ if options[:doctor]
139139

140140
puts "Globbing for indexable files"
141141

142-
index.configuration.indexables.each do |uri|
142+
index.configuration.indexable_uris.each do |uri|
143143
puts "indexing: #{uri.full_path}"
144144
index.index_single(uri)
145145
end

exe/ruby-lsp-check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ puts "\n"
4444
puts "Verifying that indexing executes successfully. This may take a while..."
4545

4646
index = RubyIndexer::Index.new
47-
indexables = index.configuration.indexables
47+
uris = index.configuration.indexable_uris
4848

49-
indexables.each_with_index do |uri, i|
49+
uris.each_with_index do |uri, i|
5050
index.index_single(uri)
5151
rescue => e
5252
errors[uri.full_path] = e
5353
ensure
54-
print("\033[M\033[0KIndexed #{i + 1}/#{indexables.length}") unless ENV["CI"]
54+
print("\033[M\033[0KIndexed #{i + 1}/#{uris.length}") unless ENV["CI"]
5555
end
5656
puts "\n"
5757

lib/ruby_indexer/lib/ruby_indexer/configuration.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def merged_excluded_file_pattern
8282
end
8383

8484
sig { returns(T::Array[URI::Generic]) }
85-
def indexables
85+
def indexable_uris
8686
excluded_gems = @excluded_gems - @included_gems
8787
locked_gems = Bundler.locked_gems&.specs
8888

@@ -107,12 +107,12 @@ def indexables
107107
[included_path, relative_path]
108108
end
109109

110-
indexables = T.let([], T::Array[URI::Generic])
110+
uris = T.let([], T::Array[URI::Generic])
111111

112112
# Handle top level files separately. The path below is an optimization to prevent descending down directories that
113113
# are going to be excluded anyway, so we need to handle top level scripts separately
114114
Dir.glob(File.join(@workspace_path, "*.rb"), flags).each do |path|
115-
indexables << URI::Generic.from_path(path: path)
115+
uris << URI::Generic.from_path(path: path)
116116
end
117117

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

137-
indexables << URI::Generic.from_path(path: path, load_path_entry: load_path_entry)
137+
uris << URI::Generic.from_path(path: path, load_path_entry: load_path_entry)
138138
end
139139
end
140140
end
@@ -150,7 +150,7 @@ def indexables
150150
end
151151

152152
# Remove user specified patterns
153-
indexables.reject! do |indexable|
153+
uris.reject! do |indexable|
154154
excluded_patterns.any? do |pattern|
155155
File.fnmatch?(pattern, T.must(indexable.full_path), File::FNM_PATHNAME | File::FNM_EXTGLOB)
156156
end
@@ -182,14 +182,14 @@ def indexables
182182

183183
if pathname.directory?
184184
# If the default_path is a directory, we index all the Ruby files in it
185-
indexables.concat(
185+
uris.concat(
186186
Dir.glob(File.join(default_path, "**", "*.rb"), File::FNM_PATHNAME | File::FNM_EXTGLOB).map! do |path|
187187
URI::Generic.from_path(path: path, load_path_entry: RbConfig::CONFIG["rubylibdir"])
188188
end,
189189
)
190190
elsif pathname.extname == ".rb"
191191
# If the default_path is a Ruby file, we index it
192-
indexables << URI::Generic.from_path(path: default_path, load_path_entry: RbConfig::CONFIG["rubylibdir"])
192+
uris << URI::Generic.from_path(path: default_path, load_path_entry: RbConfig::CONFIG["rubylibdir"])
193193
end
194194
end
195195

@@ -204,7 +204,7 @@ def indexables
204204
# duplicates or accidentally ignoring exclude patterns
205205
next if spec.full_gem_path == @workspace_path
206206

207-
indexables.concat(
207+
uris.concat(
208208
spec.require_paths.flat_map do |require_path|
209209
load_path_entry = File.join(spec.full_gem_path, require_path)
210210
Dir.glob(File.join(load_path_entry, "**", "*.rb")).map! do |path|
@@ -218,8 +218,8 @@ def indexables
218218
# just ignore if they're missing
219219
end
220220

221-
indexables.uniq!(&:to_s)
222-
indexables
221+
uris.uniq!(&:to_s)
222+
uris
223223
end
224224

225225
sig { returns(Regexp) }

lib/ruby_indexer/lib/ruby_indexer/index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def resolve(name, nesting, seen_names = [])
354354
block: T.nilable(T.proc.params(progress: Integer).returns(T::Boolean)),
355355
).void
356356
end
357-
def index_all(uris: @configuration.indexables, &block)
357+
def index_all(uris: @configuration.indexable_uris, &block)
358358
# When troubleshooting an indexing issue, e.g. through irb, it's not obvious that `index_all` will augment the
359359
# existing index values, meaning it may contain 'stale' entries. This check ensures that the user is aware of this
360360
# behavior and can take appropriate action.

lib/ruby_indexer/test/configuration_test.rb

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def setup
1313

1414
def test_load_configuration_executes_configure_block
1515
@config.apply_config({ "excluded_patterns" => ["**/fixtures/**/*.rb"] })
16-
uris = @config.indexables
16+
uris = @config.indexable_uris
1717

1818
assert(uris.none? { |uri| uri.full_path.include?("test/fixtures") })
1919
assert(uris.none? { |uri| uri.full_path.include?("minitest-reporters") })
@@ -22,16 +22,16 @@ def test_load_configuration_executes_configure_block
2222
assert(uris.none? { |uri| uri.full_path == __FILE__ })
2323
end
2424

25-
def test_indexables_have_expanded_full_paths
25+
def test_indexable_uris_have_expanded_full_paths
2626
@config.apply_config({ "included_patterns" => ["**/*.rb"] })
27-
uris = @config.indexables
27+
uris = @config.indexable_uris
2828

2929
# All paths should be expanded
3030
assert(uris.all? { |uri| File.absolute_path?(uri.full_path) })
3131
end
3232

33-
def test_indexables_only_includes_gem_require_paths
34-
uris = @config.indexables
33+
def test_indexable_uris_only_includes_gem_require_paths
34+
uris = @config.indexable_uris
3535

3636
Bundler.locked_gems.specs.each do |lazy_spec|
3737
next if lazy_spec.name == "ruby-lsp"
@@ -43,21 +43,21 @@ def test_indexables_only_includes_gem_require_paths
4343
end
4444
end
4545

46-
def test_indexables_does_not_include_default_gem_path_when_in_bundle
47-
uris = @config.indexables
46+
def test_indexable_uris_does_not_include_default_gem_path_when_in_bundle
47+
uris = @config.indexable_uris
4848
assert(uris.none? { |uri| uri.full_path.start_with?("#{RbConfig::CONFIG["rubylibdir"]}/psych") })
4949
end
5050

51-
def test_indexables_includes_default_gems
52-
paths = @config.indexables.map(&:full_path)
51+
def test_indexable_uris_includes_default_gems
52+
paths = @config.indexable_uris.map(&:full_path)
5353

5454
assert_includes(paths, "#{RbConfig::CONFIG["rubylibdir"]}/pathname.rb")
5555
assert_includes(paths, "#{RbConfig::CONFIG["rubylibdir"]}/ipaddr.rb")
5656
assert_includes(paths, "#{RbConfig::CONFIG["rubylibdir"]}/erb.rb")
5757
end
5858

59-
def test_indexables_includes_project_files
60-
paths = @config.indexables.map(&:full_path)
59+
def test_indexable_uris_includes_project_files
60+
paths = @config.indexable_uris.map(&:full_path)
6161

6262
Dir.glob("#{Dir.pwd}/lib/**/*.rb").each do |path|
6363
next if path.end_with?("_test.rb")
@@ -66,39 +66,39 @@ def test_indexables_includes_project_files
6666
end
6767
end
6868

69-
def test_indexables_avoids_duplicates_if_bundle_path_is_inside_project
69+
def test_indexable_uris_avoids_duplicates_if_bundle_path_is_inside_project
7070
Bundler.settings.temporary(path: "vendor/bundle") do
7171
config = Configuration.new
7272

7373
assert_includes(config.instance_variable_get(:@excluded_patterns), "vendor/bundle/**/*.rb")
7474
end
7575
end
7676

77-
def test_indexables_does_not_include_gems_own_installed_files
78-
uris = @config.indexables
79-
indexables_inside_bundled_lsp = uris.select do |uri|
77+
def test_indexable_uris_does_not_include_gems_own_installed_files
78+
uris = @config.indexable_uris
79+
uris_inside_bundled_lsp = uris.select do |uri|
8080
uri.full_path.start_with?(Bundler.bundle_path.join("gems", "ruby-lsp").to_s)
8181
end
8282

8383
assert_empty(
84-
indexables_inside_bundled_lsp,
85-
"Indexables should not include files from the gem currently being worked on. " \
86-
"Included: #{indexables_inside_bundled_lsp.map(&:full_path)}",
84+
uris_inside_bundled_lsp,
85+
"Indexable URIs should not include files from the gem currently being worked on. " \
86+
"Included: #{uris_inside_bundled_lsp.map(&:full_path)}",
8787
)
8888
end
8989

90-
def test_indexables_does_not_include_non_ruby_files_inside_rubylibdir
90+
def test_indexable_uris_does_not_include_non_ruby_files_inside_rubylibdir
9191
path = Pathname.new(RbConfig::CONFIG["rubylibdir"]).join("extra_file.txt").to_s
9292
FileUtils.touch(path)
9393

94-
uris = @config.indexables
94+
uris = @config.indexable_uris
9595
assert(uris.none? { |uri| uri.full_path == path })
9696
ensure
9797
FileUtils.rm(T.must(path))
9898
end
9999

100100
def test_paths_are_unique
101-
uris = @config.indexables
101+
uris = @config.indexable_uris
102102
assert_equal(uris.uniq.length, uris.length)
103103
end
104104

@@ -128,7 +128,7 @@ def test_magic_comments_regex
128128
end
129129
end
130130

131-
def test_indexables_respect_given_workspace_path
131+
def test_indexable_uris_respect_given_workspace_path
132132
Dir.mktmpdir do |dir|
133133
FileUtils.mkdir(File.join(dir, "ignore"))
134134
FileUtils.touch(File.join(dir, "ignore", "file0.rb"))
@@ -138,10 +138,10 @@ def test_indexables_respect_given_workspace_path
138138
@config.apply_config({ "excluded_patterns" => ["ignore/**/*.rb"] })
139139
@config.workspace_path = dir
140140

141-
uris = @config.indexables
141+
uris = @config.indexable_uris
142142
assert(uris.none? { |uri| uri.full_path.start_with?(File.join(dir, "ignore")) })
143143

144-
# After switching the workspace path, all indexables will be found in one of these places:
144+
# After switching the workspace path, all indexable URIs will be found in one of these places:
145145
# - The new workspace path
146146
# - The Ruby LSP's own code (because Bundler is requiring the dependency from source)
147147
# - Bundled gems
@@ -162,7 +162,7 @@ def test_includes_top_level_files
162162
FileUtils.touch(File.join(dir, "find_me.rb"))
163163
@config.workspace_path = dir
164164

165-
uris = @config.indexables
165+
uris = @config.indexable_uris
166166
assert(uris.find { |u| File.basename(u.full_path) == "find_me.rb" })
167167
end
168168
end

0 commit comments

Comments
 (0)