-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
127 additions
and
32 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
indexing: | ||
excluded_patterns: | ||
- "**/test/fixtures/**/*.rb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module RubyLsp | ||
class Configuration | ||
extend T::Sig | ||
|
||
sig { params(workspace_uri: URI::Generic).void } | ||
def initialize(workspace_uri) | ||
@workspace_uri = workspace_uri | ||
end | ||
|
||
sig { returns(T::Hash[String, T.untyped]) } | ||
def indexing | ||
# Need to use the workspace URI, otherwise, this will fail for people working on a project that is a symlink. | ||
index_path = File.join(@workspace_uri.to_standardized_path, ".index.yml") | ||
ruby_lsp_path = File.join(@workspace_uri.to_standardized_path, ".ruby-lsp.yml") | ||
|
||
if File.exist?(index_path) | ||
$stderr.puts("The .index.yml configuration file is deprecated. Please rename it to .ruby-lsp.yml and update the | ||
structure as described in the README: https://github.com/Shopify/ruby-lsp#configuration") | ||
YAML.parse_file(index_path).to_ruby | ||
elsif File.exist?(ruby_lsp_path) | ||
YAML.parse_file(ruby_lsp_path).to_ruby.fetch("indexing") | ||
else | ||
{} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
module RubyLsp | ||
class ConfigurationTest < Minitest::Test | ||
def test_returns_empty_hash_when_no_configuration_files_exist | ||
FileUtils.mv(".ruby-lsp.yml", ".ruby-lsp.yml.tmp") | ||
workspace_uri = URI::Generic.build(scheme: "file", host: nil, path: "/path/to/workspace") | ||
|
||
result = RubyLsp::Configuration.new(workspace_uri).indexing | ||
|
||
assert_empty(result) | ||
ensure | ||
FileUtils.mv(".ruby-lsp.yml.tmp", ".ruby-lsp.yml") | ||
end | ||
|
||
def test_supports_depecated_index_configuration_file | ||
FileUtils.mv(".ruby-lsp.yml", ".ruby-lsp.yml.tmp") | ||
File.write(".index.yml", <<~YAML) | ||
excluded_patterns: | ||
- "**/test/fixtures/**/*.rb" | ||
YAML | ||
workspace_uri = URI::Generic.build(scheme: "file", host: nil, path: Dir.pwd) | ||
|
||
result = RubyLsp::Configuration.new(workspace_uri).indexing | ||
|
||
assert_equal({ "excluded_patterns" => ["**/test/fixtures/**/*.rb"] }, result) | ||
ensure | ||
FileUtils.mv(".ruby-lsp.yml.tmp", ".ruby-lsp.yml") | ||
FileUtils.rm_f(".index.yml") | ||
end | ||
|
||
def test_supports_newer_configuration | ||
workspace_uri = URI::Generic.build(scheme: "file", host: nil, path: Dir.pwd) | ||
|
||
result = RubyLsp::Configuration.new(workspace_uri).indexing | ||
|
||
assert_equal({ "excluded_patterns" => ["**/test/fixtures/**/*.rb"] }, result) | ||
end | ||
|
||
def test_raises_if_indexing_key_is_missing | ||
FileUtils.mv(".ruby-lsp.yml", ".ruby-lsp.yml.tmp") | ||
File.write(".ruby-lsp.yml", <<~YAML) | ||
excluded_patterns: | ||
- "**/test/fixtures/**/*.rb" | ||
YAML | ||
workspace_uri = URI::Generic.build(scheme: "file", host: nil, path: Dir.pwd) | ||
|
||
error = assert_raises do | ||
RubyLsp::Configuration.new(workspace_uri).indexing | ||
end | ||
assert_equal("key not found: \"indexing\"", error.message) | ||
assert_instance_of(KeyError, error) | ||
ensure | ||
FileUtils.mv(".ruby-lsp.yml.tmp", ".ruby-lsp.yml") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters