Skip to content

Commit 6cae1cd

Browse files
committed
fix uriFromFile on windows
1 parent 25788b3 commit 6cae1cd

File tree

1 file changed

+8
-9
lines changed
  • protocol/source/served/lsp

1 file changed

+8
-9
lines changed

protocol/source/served/lsp/uri.d

+8-9
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,21 @@ private void assertEquals(T)(T a, T b)
1414

1515
DocumentUri uriFromFile(scope const(char)[] file)
1616
{
17+
import std.ascii : isAlpha, 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("\\", "/");
2824
assert(file.length);
29-
if (file.ptr[0] != '/')
30-
file = '/' ~ file; // always triple slash at start but never quad slash
31-
if (file.length >= 2 && file[0 .. 2] == "//") // Shares (\\share\bob) are different somehow
25+
if (file.length >= 2 && file[0].isAlpha && file[1] == ':')
26+
file = file[0].toLower ~ file[1 .. $];
27+
else if (file.length >= 2 && file[0 .. 2] == "//") // Shares (\\share\bob) are different somehow
3228
file = file[2 .. $];
29+
else if (file.ptr[0] != '/')
30+
file = '/' ~ file; // always triple slash at start but never quad slash
31+
3332
return text("file://", file.encodeComponent.replace("%2F", "/"));
3433
}
3534

0 commit comments

Comments
 (0)