Fix bracket/brace filenames breaking LSP features#4022
Open
andriytyurnikov wants to merge 2 commits intoShopify:mainfrom
Open
Fix bracket/brace filenames breaking LSP features#4022andriytyurnikov wants to merge 2 commits intoShopify:mainfrom
andriytyurnikov wants to merge 2 commits intoShopify:mainfrom
Conversation
Files with `[`, `]`, `{`, or `}` in their names (e.g., `[id].rb`,
`{slug}.rb`) broke multiple ruby-lsp features because brackets were
not percent-encoded in URIs and are glob metacharacters in Dir.glob.
- Remove `[]` from URI safe character set so they are percent-encoded,
matching VS Code's vscode-uri encoding behavior
- Use Dir.glob `base:` parameter in references, rename, addon discovery,
test_style, and go_to_relevant_file to treat paths as literal
- Escape glob metacharacters in user input for require_relative completion
- Fix expectations test runner to use File.file? instead of Dir.glob for
expectation lookup and sanitize test method names
- Add URI tests for brackets, braces, parentheses, and whitespace
This was referenced Mar 20, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4023
Fixes #3503
Motivation
Files with
[,],{, or}in their names (e.g.,[id].rb,{slug}.rb— common in Rails/Next.js routing conventions) break multiple ruby-lsp features. The root cause is twofold:vscode-urialways encodes them ([→%5B,]→%5D). This creates a URI mismatch that prevents the store from finding documents.Dir.globmetacharacters ([id]is interpreted as a character class matchingiord), breaking file discovery when paths contain these characters.When a file like
app/[id].rbexists, all LSP features fail for that file — indexing, go-to-definition, references, hover, completion, diagnostics, code lens, etc.Changes
URI encoding fix
[]from the safe character set inURI::Generic.from_pathso brackets are percent-encoded, matching VS Code's encoding (as identified by @streetpaws in Linux file system with square brackets in the directory/filename are failing to be indexed #3503). Braces were already correctly encoded. Theto_standardized_pathmethod already callsPARSER.unescape(), so the round-trip (path → URI → path) works without additional changes.Dir.glob hardening
Dir.glob'sbase:parameter inreferences.rb,rename.rb,addon.rb,test_style.rb, andgo_to_relevant_file.rbso workspace/file paths are treated as literal filesystem paths rather than glob patterns.require_relativecontent before interpolating into glob patterns in the completion listener.go_to_relevant_file.rb.Test runner fix
Dir.globwithFile.file?checks for expectation file lookup in the expectations test runner, so bracket-named fixtures don't break.[id]→_id_) to prevent syntax errors.Tests
Not included
configuration.rbglob calls were not converted tobase:due to a RubyDir.globbug with empty brace patterns — tracked in #4024.Test plan
bin/test lib/ruby_indexer/test/uri_test.rb— all 23 URI tests passbundle exec rake— full test suite passes (322 runs, 0 failures)bundle exec srb tc— Sorbet type check passesbin/rubocop— no offenses