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 762cc52
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
File renamed without changes.
12 changes: 8 additions & 4 deletions lib/ruby_indexer/lib/ruby_indexer/configuration.rb
Expand Up @@ -45,16 +45,20 @@ 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. Add a deprecation warning?
".index.yml"
end

config = YAML.parse_file(".index.yml")
return unless config
config = YAML.parse_file(config_file)
return unless config # TODO: why would this be nil?

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
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 762cc52

Please sign in to comment.