-
Notifications
You must be signed in to change notification settings - Fork 24
Fix breakpoint issues on Windows #1016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a51efe5
Fix breakpoint URI schemes on Windows
lionel- 87ea25c
Normalize URIs from LSP and execute requests
lionel- b2a3a45
Fix compilation warnings on Windows
lionel- c0536ba
Take ownership of URI in uppercase util
lionel- 24eccbf
Simplify match
lionel- 3b478f0
Clearer format
lionel- 362e218
Warn in case of failure
lionel- File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| // | ||
| // url.rs | ||
| // | ||
| // Copyright (C) 2026 Posit Software, PBC. All rights reserved. | ||
| // | ||
| // | ||
|
|
||
| use url::Url; | ||
|
|
||
| /// Extended URL utilities for ark. | ||
| /// | ||
| /// On Windows, file URIs can have different representations of the same file. | ||
| /// Positron sends `file:///c%3A/...` (URL-encoded colon, lowercase drive) in | ||
| /// execute requests and LSP notifications. These variants can be problematic | ||
| /// when URI paths are used as HashMap keys. | ||
| /// | ||
| /// This module provides normalized URI construction and parsing to ensure | ||
| /// consistent identity across subsystems (DAP breakpoints, LSP documents, | ||
| /// R code locations). | ||
| /// | ||
| /// Use `ExtUrl` methods instead of `Url` methods when working with file URIs | ||
| /// that will be used as keys or need to match across different sources. | ||
| pub struct ExtUrl; | ||
|
|
||
| impl ExtUrl { | ||
| /// Parse a URL string and normalize file URIs for consistent comparison. | ||
| pub fn parse(s: &str) -> Result<Url, url::ParseError> { | ||
| let url = Url::parse(s)?; | ||
| Ok(Self::normalize(url)) | ||
| } | ||
|
|
||
| /// Convert a file path to a normalized file URI. | ||
| pub fn from_file_path(path: impl AsRef<std::path::Path>) -> Result<Url, ()> { | ||
| let url = Url::from_file_path(path)?; | ||
| Ok(Self::normalize(url)) | ||
| } | ||
|
|
||
| /// Normalize a file URI for consistent comparison. | ||
| /// | ||
| /// On Windows, Positron sends URIs like `file:///c%3A/...` (URL-encoded | ||
| /// colon, lowercase drive letter). By round-tripping through the filesystem | ||
| /// path representation, we normalize encoding variants. We then uppercase | ||
| /// the drive letter. | ||
| #[cfg(windows)] | ||
| pub fn normalize(uri: Url) -> Url { | ||
| if uri.scheme() != "file" { | ||
| return uri; | ||
| } | ||
|
|
||
| // Round-trip through filesystem path to get canonical form. | ||
| // This decodes URL-encoded characters like %3A -> : | ||
| let Some(uri) = uri | ||
| .to_file_path() | ||
| .ok() | ||
| .and_then(|path| Url::from_file_path(&path).ok()) | ||
| else { | ||
| log::warn!("Failed to normalize file URI: {uri}"); | ||
| return uri; | ||
| }; | ||
| uppercase_windows_drive_in_uri(uri) | ||
| } | ||
|
|
||
| /// No-op on non-Windows platforms. | ||
| #[cfg(not(windows))] | ||
| pub fn normalize(uri: Url) -> Url { | ||
| uri | ||
| } | ||
| } | ||
|
|
||
| /// Uppercase the drive letter in a Windows file URI for consistent hashing. | ||
| #[cfg(windows)] | ||
| fn uppercase_windows_drive_in_uri(mut uri: Url) -> Url { | ||
| let path = uri.path(); | ||
| let mut chars = path.chars(); | ||
|
|
||
| // Match pattern: "/" + drive letter + ":" | ||
| let drive = match (chars.next(), chars.next(), chars.next()) { | ||
| (Some('/'), Some(drive), Some(':')) if drive.is_ascii_alphabetic() => drive, | ||
| _ => return uri, | ||
| }; | ||
|
|
||
| let upper = drive.to_ascii_uppercase(); | ||
|
|
||
| if drive != upper { | ||
| let new_path = format!("/{upper}:{}", &path[3..]); | ||
| uri.set_path(&new_path); | ||
| } | ||
|
|
||
| uri | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_normalize_non_file_unchanged() { | ||
| let uri = Url::parse("ark://namespace/test.R").unwrap(); | ||
| let normalized = ExtUrl::normalize(uri.clone()); | ||
| assert_eq!(normalized, uri); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_ext_url_parse_non_file() { | ||
| let uri = ExtUrl::parse("ark://namespace/test.R").unwrap(); | ||
| assert_eq!(uri.as_str(), "ark://namespace/test.R"); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(not(windows))] | ||
| fn test_normalize_is_noop_on_non_windows() { | ||
| // On non-Windows, normalize just returns the input unchanged | ||
| let uri = Url::parse("file:///home/user/test.R").unwrap(); | ||
| let normalized = ExtUrl::normalize(uri.clone()); | ||
| assert_eq!(normalized, uri); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(not(windows))] | ||
| fn test_ext_url_from_file_path_unix() { | ||
| let uri = ExtUrl::from_file_path("/home/user/test.R").unwrap(); | ||
| assert_eq!(uri.as_str(), "file:///home/user/test.R"); | ||
| } | ||
|
|
||
| // Windows-specific tests | ||
|
|
||
| #[test] | ||
| #[cfg(windows)] | ||
| fn test_normalize_decodes_percent_encoded_colon() { | ||
| // Positron sends URIs with encoded colon | ||
| let uri = Url::parse("file:///c%3A/Users/test/file.R").unwrap(); | ||
| let normalized = ExtUrl::normalize(uri); | ||
| assert_eq!(normalized.as_str(), "file:///C:/Users/test/file.R"); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(windows)] | ||
| fn test_normalize_decodes_percent_encoded_colon_lowercase_hex() { | ||
| // %3a (lowercase hex) variant | ||
| let uri = Url::parse("file:///c%3a/Users/test/file.R").unwrap(); | ||
| let normalized = ExtUrl::normalize(uri); | ||
| assert_eq!(normalized.as_str(), "file:///C:/Users/test/file.R"); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(windows)] | ||
| fn test_normalize_uppercases_drive_letter() { | ||
| let uri = Url::parse("file:///c:/Users/test/file.R").unwrap(); | ||
| let normalized = ExtUrl::normalize(uri); | ||
| assert_eq!(normalized.as_str(), "file:///C:/Users/test/file.R"); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(windows)] | ||
| fn test_normalize_preserves_uppercase_drive() { | ||
| let uri = Url::parse("file:///C:/Users/test/file.R").unwrap(); | ||
| let normalized = ExtUrl::normalize(uri.clone()); | ||
| assert_eq!(normalized, uri); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(windows)] | ||
| fn test_normalize_preserves_spaces_encoding() { | ||
| // Spaces should remain percent-encoded after round-trip | ||
| let uri = Url::parse("file:///C:/Users/test%20user/my%20file.R").unwrap(); | ||
| let normalized = ExtUrl::normalize(uri); | ||
| assert_eq!( | ||
| normalized.as_str(), | ||
| "file:///C:/Users/test%20user/my%20file.R" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(windows)] | ||
| fn test_normalize_decodes_colon_preserves_spaces() { | ||
| // Both encoded colon and spaces | ||
| let uri = Url::parse("file:///c%3A/Users/test%20user/file.R").unwrap(); | ||
| let normalized = ExtUrl::normalize(uri); | ||
| assert_eq!(normalized.as_str(), "file:///C:/Users/test%20user/file.R"); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(windows)] | ||
| fn test_ext_url_parse() { | ||
| let uri = ExtUrl::parse("file:///c%3A/Users/test/file.R").unwrap(); | ||
| assert_eq!(uri.as_str(), "file:///C:/Users/test/file.R"); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(windows)] | ||
| fn test_ext_url_from_file_path() { | ||
| let uri = ExtUrl::from_file_path("C:\\Users\\test\\file.R").unwrap(); | ||
| assert_eq!(uri.as_str(), "file:///C:/Users/test/file.R"); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.