Skip to content

Commit 6412dbc

Browse files
committed
Make configuration part of the index
Since an Index's data is scoped by configuration, we should make the configuration part of the index. This is especially true with #2424 coming because changing the state of `RubyIndexer.configuration` to affect the index is surprising.
1 parent 84d2488 commit 6412dbc

File tree

8 files changed

+17
-20
lines changed

8 files changed

+17
-20
lines changed

exe/ruby-lsp

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,20 @@ if options[:time_index]
112112
end
113113

114114
if options[:doctor]
115+
index = RubyIndexer::Index.new
116+
115117
if File.exist?(".index.yml")
116118
begin
117119
config = YAML.parse_file(".index.yml").to_ruby
118120
rescue => e
119121
abort("Error parsing config: #{e.message}")
120122
end
121-
RubyIndexer.configuration.apply_config(config)
123+
index.configuration.apply_config(config)
122124
end
123125

124-
index = RubyIndexer::Index.new
125-
126126
puts "Globbing for indexable files"
127127

128-
RubyIndexer.configuration.indexables.each do |indexable|
128+
index.configuration.indexables.each do |indexable|
129129
puts "indexing: #{indexable.full_path}"
130130
index.index_single(indexable)
131131
end

exe/ruby-lsp-check

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ puts "\n"
4444
puts "Verifying that indexing executes successfully. This may take a while..."
4545

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

4949
indexables.each_with_index do |indexable, i|
5050
index.index_single(indexable)

lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def collect_comments(node)
552552
comment_content = comment.location.slice.chomp
553553

554554
# invalid encodings would raise an "invalid byte sequence" exception
555-
if !comment_content.valid_encoding? || comment_content.match?(RubyIndexer.configuration.magic_comment_regex)
555+
if !comment_content.valid_encoding? || comment_content.match?(@index.configuration.magic_comment_regex)
556556
next
557557
end
558558

lib/ruby_indexer/lib/ruby_indexer/index.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class NonExistingNamespaceError < StandardError; end
1111
# The minimum Jaro-Winkler similarity score for an entry to be considered a match for a given fuzzy search query
1212
ENTRY_SIMILARITY_THRESHOLD = 0.7
1313

14+
sig { returns(Configuration) }
15+
attr_reader :configuration
16+
1417
sig { void }
1518
def initialize
1619
# Holds all entries in the index using the following format:
@@ -44,6 +47,8 @@ def initialize
4447
{},
4548
T::Hash[String, T::Array[T.proc.params(index: Index, base: Entry::Namespace).void]],
4649
)
50+
51+
@configuration = T.let(RubyIndexer::Configuration.new, Configuration)
4752
end
4853

4954
# Register an enhancement to the index. Enhancements must conform to the `Enhancement` interface
@@ -296,7 +301,7 @@ def resolve(name, nesting, seen_names = [])
296301
block: T.nilable(T.proc.params(progress: Integer).returns(T::Boolean)),
297302
).void
298303
end
299-
def index_all(indexable_paths: RubyIndexer.configuration.indexables, &block)
304+
def index_all(indexable_paths: @configuration.indexables, &block)
300305
RBSIndexer.new(self).index_ruby_core
301306
# Calculate how many paths are worth 1% of progress
302307
progress_step = (indexable_paths.length / 100.0).ceil

lib/ruby_indexer/ruby_indexer.rb

-8
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,4 @@
1515
require "ruby_indexer/lib/ruby_indexer/rbs_indexer"
1616

1717
module RubyIndexer
18-
@configuration = T.let(Configuration.new, Configuration)
19-
20-
class << self
21-
extend T::Sig
22-
23-
sig { returns(Configuration) }
24-
attr_reader :configuration
25-
end
2618
end

lib/ruby_indexer/test/configuration_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_configuration_raises_for_unknown_keys
108108
end
109109

110110
def test_magic_comments_regex
111-
regex = RubyIndexer.configuration.magic_comment_regex
111+
regex = @config.magic_comment_regex
112112

113113
[
114114
"# frozen_string_literal:",

lib/ruby_lsp/server.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ def process_indexing_configuration(indexing_options)
877877

878878
if File.exist?(index_path)
879879
begin
880-
RubyIndexer.configuration.apply_config(YAML.parse_file(index_path).to_ruby)
880+
@global_state.index.configuration.apply_config(YAML.parse_file(index_path).to_ruby)
881881
send_message(
882882
Notification.new(
883883
method: "window/showMessage",
@@ -906,7 +906,7 @@ def process_indexing_configuration(indexing_options)
906906
return unless indexing_options
907907

908908
# The index expects snake case configurations, but VS Code standardizes on camel case settings
909-
RubyIndexer.configuration.apply_config(
909+
@global_state.index.configuration.apply_config(
910910
indexing_options.transform_keys { |key| key.to_s.gsub(/([A-Z])/, "_\\1").downcase },
911911
)
912912
end

test/server_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ def test_handles_editor_indexing_settings
481481
})
482482
end
483483

484-
assert_includes(RubyIndexer.configuration.instance_variable_get(:@excluded_gems), "foo_gem")
485-
assert_includes(RubyIndexer.configuration.instance_variable_get(:@included_gems), "bar_gem")
484+
assert_includes(@server.global_state.index.configuration.instance_variable_get(:@excluded_gems), "foo_gem")
485+
assert_includes(@server.global_state.index.configuration.instance_variable_get(:@included_gems), "bar_gem")
486486
end
487487

488488
def test_closing_document_before_computing_features_does_not_error

0 commit comments

Comments
 (0)