Skip to content

Commit 0bf1493

Browse files
Address PR review feedback
- Remove redundant assert_match assertions in URI tests - Extract escape_glob_metacharacters to RubyLsp module and reuse
1 parent 8626f6c commit 0bf1493

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

lib/ruby_indexer/test/uri_test.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,11 @@ def test_from_path_with_unicode_characters
8484

8585
def test_from_path_with_brackets
8686
uri = URI::Generic.from_path(path: "/some/path/[id].rb")
87-
assert_match("%5B", uri.path)
88-
assert_match("%5D", uri.path)
8987
assert_equal("file:///some/path/%5Bid%5D.rb", uri.to_s)
9088
end
9189

9290
def test_from_path_with_braces
9391
uri = URI::Generic.from_path(path: "/some/path/{slug}.rb")
94-
assert_match("%7B", uri.path)
95-
assert_match("%7D", uri.path)
9692
assert_equal("file:///some/path/%7Bslug%7D.rb", uri.to_s)
9793
end
9894

lib/ruby_lsp/listeners/completion.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def complete_require_relative(node)
457457
# if the path is not a directory, glob all possible next characters
458458
# for example ../somethi| (where | is the cursor position)
459459
# should find files for ../somethi*/
460-
escaped_content = content.gsub(/[\[\]{}*?\\]/) { |c| "\\#{c}" }
460+
escaped_content = RubyLsp.escape_glob_metacharacters(content)
461461
path_query = if content.end_with?("/") || content.empty?
462462
"#{escaped_content}**/*.rb"
463463
else

lib/ruby_lsp/requests/go_to_relevant_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def relevant_filename_patterns
115115

116116
#: (String str) -> String
117117
def escape_glob_metacharacters(str)
118-
str.gsub(/[\[\]{}*?\\]/) { |c| "\\#{c}" }
118+
RubyLsp.escape_glob_metacharacters(str)
119119
end
120120

121121
# Using the Jaccard algorithm to determine the similarity between the

lib/ruby_lsp/utils.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ module RubyLsp
2121
GUESSED_TYPES_URL = "https://shopify.github.io/ruby-lsp/#guessed-types"
2222
TEST_PATH_PATTERN = "**/{test,spec,features}/**/{*_test.rb,test_*.rb,*_spec.rb,*.feature}"
2323

24+
# Escape characters that have special meaning in Dir.glob patterns
25+
#: (String str) -> String
26+
def self.escape_glob_metacharacters(str)
27+
str.gsub(/[\[\]{}*?\\]/) { |c| "\\#{c}" }
28+
end
29+
2430
# Request delegation for embedded languages is not yet standardized into the language server specification. Here we
2531
# use this custom error class as a way to return a signal to the client that the request should be delegated to the
2632
# language server for the host language. The support for delegation is custom built on the client side, so each editor

0 commit comments

Comments
 (0)