@@ -23,13 +23,25 @@ public DocumentUri(string url)
23
23
var delimiterIndex = url . IndexOf ( SchemeDelimiter , StringComparison . Ordinal ) ;
24
24
if ( delimiterIndex == - 1 )
25
25
{
26
- url = Uri . UnescapeDataString ( url ) . Replace ( '\\ ' , '/' ) ;
26
+ // Unc path
27
+ if ( url . StartsWith ( "\\ \\ " ) )
28
+ {
29
+ var authorityEndIndex = url . IndexOf ( '\\ ' , 2 ) ;
30
+ Authority = url . Substring ( 2 , authorityEndIndex - 2 ) ;
31
+ url = url . Substring ( authorityEndIndex ) ;
32
+ // Path = Uri.UnescapeDataString(url);
33
+ }
34
+ else
35
+ {
36
+ Authority = string . Empty ;
37
+ }
38
+
39
+ url = url . Replace ( '\\ ' , '/' ) ;
27
40
28
41
Scheme = UriSchemeFile ;
29
- Authority = string . Empty ;
30
42
Query = string . Empty ;
31
43
Fragment = string . Empty ;
32
- Path = Uri . UnescapeDataString ( url ) . TrimStart ( '/' ) ;
44
+ Path = Uri . UnescapeDataString ( url . StartsWith ( "/" ) ? url : "/" + url ) ;
33
45
34
46
return ;
35
47
}
@@ -40,6 +52,15 @@ public DocumentUri(string url)
40
52
Authority = url . Substring ( delimiterIndex + SchemeDelimiter . Length ,
41
53
authorityIndex - ( delimiterIndex + SchemeDelimiter . Length ) ) ;
42
54
55
+ // this is a possible windows path without the proper tripple slash
56
+ // file://c:/some/path.file.cs
57
+ // We need deal with this case.
58
+ if ( Authority . IndexOf ( ':' ) > - 1 || Authority . IndexOf ( "%3a" , StringComparison . OrdinalIgnoreCase ) > - 1 )
59
+ {
60
+ Authority = string . Empty ;
61
+ authorityIndex = delimiterIndex + SchemeDelimiter . Length ;
62
+ }
63
+
43
64
var fragmentIndex = url . IndexOf ( '#' ) ;
44
65
if ( fragmentIndex > - 1 )
45
66
{
@@ -62,8 +83,7 @@ public DocumentUri(string url)
62
83
queryIndex = fragmentIndex ;
63
84
}
64
85
65
- Path = Uri . UnescapeDataString ( url . Substring ( authorityIndex + 1 , queryIndex - ( authorityIndex ) ) )
66
- . TrimStart ( '/' ) ;
86
+ Path = Uri . UnescapeDataString ( url . Substring ( authorityIndex , queryIndex - ( authorityIndex ) + 1 ) ) ;
67
87
}
68
88
69
89
/// <summary>
@@ -133,7 +153,7 @@ public Uri ToUri()
133
153
/// <returns></returns>
134
154
/// <remarks>This will not a uri encode asian and cyrillic characters</remarks>
135
155
public override string ToString ( ) =>
136
- $ "{ Scheme } { SchemeDelimiter } { Authority } / { Path } { ( string . IsNullOrWhiteSpace ( Query ) ? "" : "?" + Query ) } { ( string . IsNullOrWhiteSpace ( Fragment ) ? "" : "#" + Fragment ) } ";
156
+ $ "{ Scheme } { SchemeDelimiter } { Authority } { Path } { ( string . IsNullOrWhiteSpace ( Query ) ? "" : "?" + Query ) } { ( string . IsNullOrWhiteSpace ( Fragment ) ? "" : "#" + Fragment ) } ";
137
157
138
158
/// <summary>
139
159
/// Gets the file system path prefixed with / for unix platforms
@@ -143,7 +163,11 @@ public override string ToString() =>
143
163
public string GetFileSystemPath ( )
144
164
{
145
165
// The language server protocol represents "C:\Foo\Bar" as "file:///c:/foo/bar".
146
- return Path . IndexOf ( ':' ) == - 1 ? "/" + Path : Path . Replace ( '/' , '\\ ' ) ;
166
+ if ( Path . IndexOf ( ':' ) == - 1 && ! ( Scheme == UriSchemeFile && ! string . IsNullOrWhiteSpace ( Authority ) ) )
167
+ return Path ;
168
+ if ( ! string . IsNullOrWhiteSpace ( Authority ) )
169
+ return $ "\\ \\ { Authority } { Path } ". Replace ( '/' , '\\ ' ) ;
170
+ return Path . TrimStart ( '/' ) . Replace ( '/' , '\\ ' ) ;
147
171
}
148
172
149
173
/// <inheritdoc />
0 commit comments