editor: Fix file URL navigation in hover popover on Windows#59248
Open
MZZW wants to merge 2 commits into
Open
Conversation
Use `Url::to_file_path()` instead of `PathBuf::from(uri.path())` in `open_markdown_url`. On Windows, `url::Url::path()` returns paths with a leading slash (e.g., `/D:/path/to/file.rs`), which `PathBuf::from()` cannot resolve correctly. This caused LSP hover links (file:// URIs from language servers) to fail navigation on Windows. `Url::to_file_path()` handles the platform-specific path conversion properly - it strips the leading slash on Windows and returns the correct D:\path\to\file format. Release Notes: - Fixed LSP hover link navigation failing on Windows due to incorrect file path resolution
Add a test verifying that `Url::to_file_path()` correctly handles Windows-style file:// URLs, which is the conversion used in `open_markdown_url`. Release Notes: - N/A
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.
Use
Url::to_file_path()instead ofPathBuf::from(uri.path())inopen_markdown_url. On Windows,url::Url::path()returns paths with aleading slash (e.g.,
/D:/path/to/file.rs), whichPathBuf::from()cannot resolve correctly. This caused LSP hover links (file:// URIs from
language servers) to fail navigation on Windows.
Url::to_file_path()handles the platform-specific path conversionproperly - it strips the leading slash on Windows and returns the
correct
D:\path\to\fileformat.Objective
Fix LSP hover popover file links failing to navigate when clicking on
Windows. The root cause is that
PathBuf::from(uri.path())does nothandle the leading
/in the URL path on Windows.Solution
Use
url::Url::to_file_path()instead ofPathBuf::from(uri.path()).to_file_path()is the standard, cross-platform way to convert afile://URL to a nativePathBuf— it correctly strips the leadingslash on Windows and produces proper
D:\...paths.Testing
machine.
Windows code path. Non-Windows platforms remain unaffected.
test_file_url_to_path_conversion_on_windowsinhover_popover.rsthat verifiesUrl::to_file_path()produces thecorrect path.
mention.rs(test_parse_file_uris_use_native_separators_on_windows)cover the same underlying path conversion logic and pass.
Self-Review Checklist:
hover_popover.rs)Release Notes: