File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -137,7 +137,8 @@ pub trait ToFilePath {
137137impl 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
You can’t perform that action at this time.
0 commit comments