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

Make configuration part of the index #2433

Merged
merged 1 commit into from
Aug 13, 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
8 changes: 4 additions & 4 deletions exe/ruby-lsp
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,20 @@ if options[:time_index]
end

if options[:doctor]
index = RubyIndexer::Index.new

if File.exist?(".index.yml")
begin
config = YAML.parse_file(".index.yml").to_ruby
rescue => e
abort("Error parsing config: #{e.message}")
end
RubyIndexer.configuration.apply_config(config)
index.configuration.apply_config(config)
end

index = RubyIndexer::Index.new

puts "Globbing for indexable files"

RubyIndexer.configuration.indexables.each do |indexable|
index.configuration.indexables.each do |indexable|
puts "indexing: #{indexable.full_path}"
index.index_single(indexable)
end
Expand Down
2 changes: 1 addition & 1 deletion exe/ruby-lsp-check
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ puts "\n"
puts "Verifying that indexing executes successfully. This may take a while..."

index = RubyIndexer::Index.new
indexables = RubyIndexer.configuration.indexables
indexables = index.configuration.indexables

indexables.each_with_index do |indexable, i|
index.index_single(indexable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def collect_comments(node)
comment_content = comment.location.slice.chomp

# invalid encodings would raise an "invalid byte sequence" exception
if !comment_content.valid_encoding? || comment_content.match?(RubyIndexer.configuration.magic_comment_regex)
if !comment_content.valid_encoding? || comment_content.match?(@index.configuration.magic_comment_regex)
next
end

Expand Down
7 changes: 6 additions & 1 deletion lib/ruby_indexer/lib/ruby_indexer/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class NonExistingNamespaceError < StandardError; end
# The minimum Jaro-Winkler similarity score for an entry to be considered a match for a given fuzzy search query
ENTRY_SIMILARITY_THRESHOLD = 0.7

sig { returns(Configuration) }
attr_reader :configuration

sig { void }
def initialize
# Holds all entries in the index using the following format:
Expand Down Expand Up @@ -44,6 +47,8 @@ def initialize
{},
T::Hash[String, T::Array[T.proc.params(index: Index, base: Entry::Namespace).void]],
)

@configuration = T.let(RubyIndexer::Configuration.new, Configuration)
end

# Register an enhancement to the index. Enhancements must conform to the `Enhancement` interface
Expand Down Expand Up @@ -296,7 +301,7 @@ def resolve(name, nesting, seen_names = [])
block: T.nilable(T.proc.params(progress: Integer).returns(T::Boolean)),
).void
end
def index_all(indexable_paths: RubyIndexer.configuration.indexables, &block)
def index_all(indexable_paths: @configuration.indexables, &block)
RBSIndexer.new(self).index_ruby_core
# Calculate how many paths are worth 1% of progress
progress_step = (indexable_paths.length / 100.0).ceil
Expand Down
8 changes: 0 additions & 8 deletions lib/ruby_indexer/ruby_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,4 @@
require "ruby_indexer/lib/ruby_indexer/rbs_indexer"

module RubyIndexer
@configuration = T.let(Configuration.new, Configuration)

class << self
extend T::Sig

sig { returns(Configuration) }
attr_reader :configuration
end
end
2 changes: 1 addition & 1 deletion lib/ruby_indexer/test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_configuration_raises_for_unknown_keys
end

def test_magic_comments_regex
regex = RubyIndexer.configuration.magic_comment_regex
regex = @config.magic_comment_regex

[
"# frozen_string_literal:",
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ def process_indexing_configuration(indexing_options)

if File.exist?(index_path)
begin
RubyIndexer.configuration.apply_config(YAML.parse_file(index_path).to_ruby)
@global_state.index.configuration.apply_config(YAML.parse_file(index_path).to_ruby)
send_message(
Notification.new(
method: "window/showMessage",
Expand Down Expand Up @@ -906,7 +906,7 @@ def process_indexing_configuration(indexing_options)
return unless indexing_options

# The index expects snake case configurations, but VS Code standardizes on camel case settings
RubyIndexer.configuration.apply_config(
@global_state.index.configuration.apply_config(
indexing_options.transform_keys { |key| key.to_s.gsub(/([A-Z])/, "_\\1").downcase },
)
end
Expand Down
4 changes: 2 additions & 2 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ def test_handles_editor_indexing_settings
})
end

assert_includes(RubyIndexer.configuration.instance_variable_get(:@excluded_gems), "foo_gem")
assert_includes(RubyIndexer.configuration.instance_variable_get(:@included_gems), "bar_gem")
assert_includes(@server.global_state.index.configuration.instance_variable_get(:@excluded_gems), "foo_gem")
assert_includes(@server.global_state.index.configuration.instance_variable_get(:@included_gems), "bar_gem")
end

def test_closing_document_before_computing_features_does_not_error
Expand Down
Loading