Skip to content

Commit 0e94aea

Browse files
mmahroussfda-odoo
authored andcommitted
[IMP] handle windows wsl paths
1 parent 67f15a6 commit 0e94aea

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

server/src/core/file_mgr.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,16 @@ impl FileMgr {
616616
if cfg!(windows) {
617617
slash = "/";
618618
}
619-
let pre_uri = match url::Url::parse(&format!("file://{}{}", slash, s)) {
619+
// If the path starts with \\\\, we want to remove it and also set slash to empty string
620+
// Such that we have file://wsl.localhost for example
621+
// For normal paths we do want file:///C:/...
622+
let replaced = if s.starts_with("\\\\") {
623+
slash = "";
624+
s.replacen("\\\\", "", 1)
625+
} else {
626+
s.clone()
627+
};
628+
let pre_uri = match url::Url::parse(&format!("file://{}{}", slash, replaced)) {
620629
Ok(pre_uri) => pre_uri,
621630
Err(err) => panic!("unable to transform pathname to uri: {s}, {}", err)
622631
};
@@ -627,7 +636,8 @@ impl FileMgr {
627636
}
628637

629638
pub fn uri2pathname(s: &str) -> String {
630-
if let Ok(url) = url::Url::parse(s) {
639+
let str_repr = s.replace("file:////", "file://");
640+
if let Ok(url) = url::Url::parse(&str_repr) {
631641
if let Ok(url) = url.to_file_path() {
632642
return url.sanitize();
633643
}

server/src/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ pub trait ToFilePath {
137137
impl ToFilePath for lsp_types::Uri {
138138

139139
fn to_file_path(&self) -> Result<PathBuf, ()> {
140-
let url = url::Url::from_str(self.as_str()).map_err(|_| ())?;
140+
let str_repr = self.as_str().replace("file:////", "file://");
141+
let url = url::Url::from_str(&str_repr).map_err(|_| ())?;
141142
url.to_file_path()
142143
}
143144

0 commit comments

Comments
 (0)