Skip to content

Commit 9dace45

Browse files
committed
fix uriFromFile on windows
1 parent bf9a55d commit 9dace45

File tree

1 file changed

+4
-6
lines changed
  • protocol/source/served/lsp

1 file changed

+4
-6
lines changed

protocol/source/served/lsp/uri.d

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ private void assertEquals(T)(T a, T b)
1414

1515
DocumentUri uriFromFile(scope const(char)[] file)
1616
{
17+
import std.ascii : isUpper, toLower;
1718
import std.uri : encodeComponent;
1819

1920
if ((!isAbsolute(file) && !file.startsWith("/"))
2021
|| !file.length)
2122
throw new Exception(text("Tried to pass relative path '", file, "' to uriFromFile"));
22-
file = file.buildNormalizedPath();
23-
version(Windows)
24-
{
25-
file = file.replace("\\", "/");
26-
file = driveName(file).toLower() ~ stripDrive(file);
27-
}
23+
file = file.buildNormalizedPath().replace("\\", "/");
24+
if (file.length >= 2 && file[0].isUpper && file[1] == ':')
25+
file = file[0].toLower ~ file[1 .. $];
2826
assert(file.length);
2927
if (file.ptr[0] != '/')
3028
file = '/' ~ file; // always triple slash at start but never quad slash

0 commit comments

Comments
 (0)