Description
Files with [, ], {, or } in their names (e.g., [id].rb, {slug}.rb) break multiple ruby-lsp features. These filename patterns are common in Rails/Next.js routing conventions.
When such a file exists in the workspace, all LSP features fail for it — indexing, go-to-definition, references, hover, completion, diagnostics, code lens, etc.
Root cause
Two independent issues compound:
-
URI encoding mismatch: URI::Generic.from_path includes [] in its safe character set, so brackets are left unescaped. However, VS Code's vscode-uri always encodes them ([ → %5B, ] → %5D). This mismatch means the server's URI for a file doesn't match the client's URI, so the document store can't find it.
-
Glob metacharacters in paths: Dir.glob treats [] as character classes and {} as alternation groups. When file or workspace paths containing these characters are interpolated into glob patterns (e.g., Dir.glob(File.join(workspace_path, "**/*.rb"))), the glob interprets them as pattern syntax rather than literal characters.
Reproduction
- Create a file named
[id].rb in a Ruby project
- Open the project in VS Code with ruby-lsp
- Open
[id].rb — observe that no LSP features work (no syntax highlighting from semantic tokens, no go-to-definition, no hover, etc.)
Fix
PR #4022
Description
Files with
[,],{, or}in their names (e.g.,[id].rb,{slug}.rb) break multiple ruby-lsp features. These filename patterns are common in Rails/Next.js routing conventions.When such a file exists in the workspace, all LSP features fail for it — indexing, go-to-definition, references, hover, completion, diagnostics, code lens, etc.
Root cause
Two independent issues compound:
URI encoding mismatch:
URI::Generic.from_pathincludes[]in its safe character set, so brackets are left unescaped. However, VS Code'svscode-urialways encodes them ([→%5B,]→%5D). This mismatch means the server's URI for a file doesn't match the client's URI, so the document store can't find it.Glob metacharacters in paths:
Dir.globtreats[]as character classes and{}as alternation groups. When file or workspace paths containing these characters are interpolated into glob patterns (e.g.,Dir.glob(File.join(workspace_path, "**/*.rb"))), the glob interprets them as pattern syntax rather than literal characters.Reproduction
[id].rbin a Ruby project[id].rb— observe that no LSP features work (no syntax highlighting from semantic tokens, no go-to-definition, no hover, etc.)Fix
PR #4022