Fix relay compiler path issues for Windows#5365
Open
christiansany wants to merge 2 commits into
Open
Conversation
christiansany
marked this pull request as ready for review
July 20, 2026 07:53
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 #5347
The bug
On Windows, the Relay LSP breaks for every graphql tagged literal starting with
relay-compiler21.0.0 (20.0.0 works). The schema can't be resolved and IDE features (hover, autocomplete, diagnostics) silently stop working. The LSP log shows:The give-away is
%3A(a URL-encoded:) and the leading slash before the drive letter: the compiler is treating the raw URI path as a filesystem path instead of decoding it intoc:\Development\….macOS/Linux are unaffected because their URI paths (
/Users/…) need no decoding and have no drive letter.Root cause
This is a regression from
6098dee("Update from lsp-types 0.94 to 0.97"), which migrated relay-lsp fromlsp_types::Url(backed by theurlcrate) tolsp_types::Uri(backed byfluent-uri).Url::to_file_path()used to do two Windows-critical things that the new API does not:%3A→:)./(/C:/…→C:\…).The migration replaced those calls with a naïve
Path::new(uri.path().as_str()), andUri::path()returns the raw, still-percent-encoded path. So on Windows the path stays/c%3A/…, which is:get_file_group_from_urireturns the "Unable to convert URI to file path" error above (schema resolution fails), andstarts_with(root_dir)→is_file_uri_in_dirreturnsfalse, so the LSP treats the file as outside the project and ignores itsdidOpen/didChangeentirely (hover/autocomplete break).The reverse direction (path → URI) was already re-fixed in #5285 (
path_to_file_uri), but the mirror URI → path conversion was never restored — that's the remaining gap.The fix
Added a
uri_to_file_path()helper inrelay-lsp/src/utils.rsthat restores the oldUrl::to_file_path()behavior:fileURIs (returnsNone),percent-encodingcrate (already a dependency), and/only when a Windows drive-letter component (C:,C:/,C:\) follows — Unix paths pass through verbatim.Both broken call sites now route through it:
is_file_uri_in_dir→uri_to_file_path(uri).is_some_and(|p| p.starts_with(root_dir))get_file_group_from_uri→ converts viauri_to_file_path, keeping the existingis_absolute()guard.This is behaviorally equivalent to what
Url::to_file_path()produced in 20.0.0 (same case-preserving output; Rust already compares Windows drive prefixes case-insensitively, and thestarts_withcomparison itself is unchanged from before the regression).Tests
Added a
#[cfg(test)] mod testsinutils.rs(matching the existing inline-unit-test convention used across the compiler, e.g.file_categorizer.rs) covering:file:///c%3A/…URI from the issue →c:/…,file:///C:/…drive letter,%20),fileschemes →None,path_to_file_uri(the reverse direction), andTesting
cargo test -p relay-lsp— all new tests pass, existing tests green.cargo fmt/cargo checkclean perCONTRIBUTING.md.relay-lsp/src/utils.rs; no API, schema, or compiler-CLI changes.