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
7 changed files
with
113 additions
and
31 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,35 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module RubyLsp | ||
class IndexingConfig | ||
extend T::Sig | ||
class << self | ||
extend T::Sig | ||
|
||
# TODO: signature | ||
sig { params(workspace_uri: URI::Generic).returns(T::Hash[String, T.untyped]) } | ||
def call(workspace_uri) | ||
# 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) | ||
warn("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") | ||
".ruby-lsp.yml" | ||
end | ||
|
||
# begin | ||
indexing_config = if File.exist?(index_path) | ||
YAML.parse_file(index_path).to_ruby | ||
elsif File.exist?(ruby_lsp_path) | ||
YAML.parse_file(ruby_lsp_path).to_ruby.fetch("indexing") # TODO: handle exception | ||
else | ||
{} | ||
# end | ||
end | ||
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,43 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
module RubyLsp | ||
class IndexConfigTest < 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::IndexingConfig.call(workspace_uri) | ||
|
||
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::IndexingConfig.call(workspace_uri) | ||
|
||
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::IndexingConfig.call(workspace_uri) | ||
|
||
assert_equal({ "excluded_patterns" => ["**/test/fixtures/**/*.rb"] }, result) | ||
end | ||
end | ||
end |