Skip to content

Fix bracket/brace filenames breaking LSP features#4022

Open
andriytyurnikov wants to merge 2 commits intoShopify:mainfrom
andriytyurnikov:bracket-file-fix
Open

Fix bracket/brace filenames breaking LSP features#4022
andriytyurnikov wants to merge 2 commits intoShopify:mainfrom
andriytyurnikov:bracket-file-fix

Conversation

@andriytyurnikov
Copy link

@andriytyurnikov andriytyurnikov commented Mar 20, 2026

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:

  1. URI encoding mismatch: Brackets are not percent-encoded in URIs, but VS Code's vscode-uri always encodes them ([%5B, ]%5D). This creates a URI mismatch that prevents the store from finding documents.
  2. Glob metacharacters: Brackets and braces are Dir.glob metacharacters ([id] is interpreted as a character class matching i or d), breaking file discovery when paths contain these characters.

When a file like app/[id].rb exists, all LSP features fail for that file — indexing, go-to-definition, references, hover, completion, diagnostics, code lens, etc.

Changes

URI encoding fix

Dir.glob hardening

  • Used Dir.glob's base: parameter in references.rb, rename.rb, addon.rb, test_style.rb, and go_to_relevant_file.rb so workspace/file paths are treated as literal filesystem paths rather than glob patterns.
  • Escaped glob metacharacters in user-provided require_relative content before interpolating into glob patterns in the completion listener.
  • Escaped glob metacharacters in filenames used to build search patterns in go_to_relevant_file.rb.

Test runner fix

  • Replaced Dir.glob with File.file? checks for expectation file lookup in the expectations test runner, so bracket-named fixtures don't break.
  • Sanitized fixture names in generated test method names ([id]_id_) to prevent syntax errors.

Tests

  • Added URI unit tests for brackets, braces, parentheses, and whitespace-within-delimiter round-trips.

Not included

configuration.rb glob calls were not converted to base: due to a Ruby Dir.glob bug with empty brace patterns — tracked in #4024.

Test plan

  • bin/test lib/ruby_indexer/test/uri_test.rb — all 23 URI tests pass
  • bundle exec rake — full test suite passes (322 runs, 0 failures)
  • bundle exec srb tc — Sorbet type check passes
  • bin/rubocop — no offenses

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bracket/brace filenames break all LSP features Linux file system with square brackets in the directory/filename are failing to be indexed

1 participant