From 9dace4505692c66c6e397c6d56164eb38cce601e Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Tue, 13 Feb 2024 17:04:50 +0100 Subject: [PATCH] fix uriFromFile on windows --- protocol/source/served/lsp/uri.d | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/protocol/source/served/lsp/uri.d b/protocol/source/served/lsp/uri.d index c2fa2348..4926dbf0 100644 --- a/protocol/source/served/lsp/uri.d +++ b/protocol/source/served/lsp/uri.d @@ -14,17 +14,15 @@ private void assertEquals(T)(T a, T b) DocumentUri uriFromFile(scope const(char)[] file) { + import std.ascii : isUpper, toLower; import std.uri : encodeComponent; if ((!isAbsolute(file) && !file.startsWith("/")) || !file.length) throw new Exception(text("Tried to pass relative path '", file, "' to uriFromFile")); - file = file.buildNormalizedPath(); - version(Windows) - { - file = file.replace("\\", "/"); - file = driveName(file).toLower() ~ stripDrive(file); - } + file = file.buildNormalizedPath().replace("\\", "/"); + if (file.length >= 2 && file[0].isUpper && file[1] == ':') + file = file[0].toLower ~ file[1 .. $]; assert(file.length); if (file.ptr[0] != '/') file = '/' ~ file; // always triple slash at start but never quad slash