Skip to content

Commit

Permalink
Introduce .ruby-lsp.yml config file
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Feb 29, 2024
1 parent 4d5bc2e commit 16480f7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
File renamed without changes.
12 changes: 9 additions & 3 deletions lib/ruby_indexer/lib/ruby_indexer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,22 @@ def initialize

sig { void }
def load_config
return unless File.exist?(".index.yml")
config_file = if File.exist?(".ruby-lsp.yml")
".ruby-lsp.yml"
elsif File.exist?(".index.yml") # previously used name
".index.yml"
end

return unless config_file

config = YAML.parse_file(".index.yml")
config = YAML.parse_file(config_file)
return unless config

config_hash = config.to_ruby
validate_config!(config_hash)
apply_config(config_hash)
rescue Psych::SyntaxError => e
raise e, "Syntax error while loading .index.yml configuration: #{e.message}"
raise e, "Syntax error while loading #{config_file} configuration: #{e.message}"
end

sig { returns(T::Array[IndexablePath]) }
Expand Down
17 changes: 17 additions & 0 deletions lib/ruby_indexer/test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ def test_load_configuration_executes_configure_block
assert(indexables.none? { |indexable| indexable.full_path == __FILE__ })
end

def test_supports_older_index_configuration
FileUtils.mv(".ruby-lsp.yml", ".ruby-lsp.yml.tmp")
s = <<~YAML
excluded_patterns:
- "**/test/fixtures/**/*.rb"
YAML
File.write(".index.yml", s)

@config.load_config
indexables = @config.indexables

assert(indexables.none? { |indexable| indexable.full_path.include?("test/fixtures") })
ensure
FileUtils.rm_f(".index.yml")
FileUtils.mv(".ruby-lsp.yml.tmp", ".ruby-lsp.yml")
end

def test_indexables_only_includes_gem_require_paths
@config.load_config
indexables = @config.indexables
Expand Down

0 comments on commit 16480f7

Please sign in to comment.