diff options
author | Omer Ben-Amram <[email protected]> | 2019-12-15 14:51:57 +0000 |
---|---|---|
committer | Omer Ben-Amram <[email protected]> | 2019-12-15 14:51:57 +0000 |
commit | 324cbe839f3110bd4d51726d5a7afe29808ade02 (patch) | |
tree | c8f859c03279f290a106237a800d2c3a2b9ebfae /crates | |
parent | 1d9b585c62dc92889380c9ae130d15ce7f9b08d4 (diff) |
Lowercase drive letters on windows before sending to extension.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_lsp_server/src/world.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 927449b45..be3a5bfb8 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs | |||
@@ -22,6 +22,7 @@ use crate::{ | |||
22 | main_loop::pending_requests::{CompletedRequest, LatestRequests}, | 22 | main_loop::pending_requests::{CompletedRequest, LatestRequests}, |
23 | LspError, Result, | 23 | LspError, Result, |
24 | }; | 24 | }; |
25 | use std::str::FromStr; | ||
25 | 26 | ||
26 | #[derive(Debug, Clone)] | 27 | #[derive(Debug, Clone)] |
27 | pub struct Options { | 28 | pub struct Options { |
@@ -235,6 +236,9 @@ impl WorldSnapshot { | |||
235 | let path = self.vfs.read().file2path(VfsFile(id.0)); | 236 | let path = self.vfs.read().file2path(VfsFile(id.0)); |
236 | let url = Url::from_file_path(&path) | 237 | let url = Url::from_file_path(&path) |
237 | .map_err(|_| format!("can't convert path to url: {}", path.display()))?; | 238 | .map_err(|_| format!("can't convert path to url: {}", path.display()))?; |
239 | |||
240 | #[cfg(target_os = "windows")] | ||
241 | let url = lowercase_drive_letter(&url); | ||
238 | Ok(url) | 242 | Ok(url) |
239 | } | 243 | } |
240 | 244 | ||
@@ -279,3 +283,33 @@ impl WorldSnapshot { | |||
279 | self.analysis.feature_flags() | 283 | self.analysis.feature_flags() |
280 | } | 284 | } |
281 | } | 285 | } |
286 | |||
287 | #[cfg(target_os = "windows")] | ||
288 | fn lowercase_drive_letter(url: &Url) -> Url { | ||
289 | let s = url.to_string(); | ||
290 | let drive_partition: Vec<&str> = s.rsplitn(2, ':').collect::<Vec<&str>>(); | ||
291 | |||
292 | if drive_partition.len() == 1 { | ||
293 | return url.clone(); | ||
294 | } | ||
295 | |||
296 | let joined = drive_partition[1].to_ascii_lowercase() + ":" + drive_partition[0]; | ||
297 | let url = Url::from_str(&joined).expect("This came from a valid `Url`"); | ||
298 | url | ||
299 | } | ||
300 | |||
301 | #[test] | ||
302 | fn test_lowercase_drive_letter_with_drive() { | ||
303 | let url = Url::from_file_path("C:\\Test").unwrap(); | ||
304 | let url = lowercase_drive_letter(&url); | ||
305 | |||
306 | assert_eq!(url.to_string(), "file:///c:/Test"); | ||
307 | } | ||
308 | |||
309 | #[test] | ||
310 | fn test_drive_without_colon_passthrough() { | ||
311 | let url = Url::from_file_path(r#"\\localhost\C$\my_dir"#).expect("Should work"); | ||
312 | let url = lowercase_drive_letter(&url); | ||
313 | |||
314 | assert_eq!(url.to_string(), "file:///C$/my_dir"); | ||
315 | } | ||