From 7801b224357ac6b8013cdaf6929c9f04b758bb74 Mon Sep 17 00:00:00 2001 From: Corben Eastman Date: Thu, 21 Dec 2023 02:44:16 -0700 Subject: [PATCH] Lowercase drive letter in URIs for Windows (#1441) If a LSP client on Windows sends a capital drive letter in a URI, then the compiler diagnostics end up sending the wrong position/range. This is because of this line. It checks that the path from the compiler matches the URI path. The path from the compiler has a lowercase drive letter, so they don't match and the diagnostics are treated as if they are coming from an include. I've fixed this in els_uri:path, but there might be a better place to do it, I'm not sure. --- apps/els_core/src/els_uri.erl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/els_core/src/els_uri.erl b/apps/els_core/src/els_uri.erl index feab6efc6..2c77f0458 100644 --- a/apps/els_core/src/els_uri.erl +++ b/apps/els_core/src/els_uri.erl @@ -49,9 +49,10 @@ path(Uri, IsWindows) -> case {IsWindows, Host} of {true, <<>>} -> % Windows drive letter, have to strip the initial slash - re:replace( + Path1 = re:replace( Path, "^/([a-zA-Z]:)(.*)", "\\1\\2", [{return, binary}] - ); + ), + lowercase_drive_letter(Path1); {true, _} -> <<"//", Host/binary, Path/binary>>; {false, <<>>} -> @@ -113,6 +114,13 @@ percent_decode(Str) -> http_uri:decode(Str). -endif. +-spec lowercase_drive_letter(binary()) -> binary(). +lowercase_drive_letter(<>) -> + Drive = string:to_lower(Drive0), + <>; +lowercase_drive_letter(Path) -> + Path. + -ifdef(TEST). -include_lib("eunit/include/eunit.hrl").