Skip to content

Commit

Permalink
Lowercase drive letter in URIs for Windows (#1441)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
corben2 authored Dec 21, 2023
1 parent c520791 commit 7801b22
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/els_core/src/els_uri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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, <<>>} ->
Expand Down Expand Up @@ -113,6 +114,13 @@ percent_decode(Str) ->
http_uri:decode(Str).
-endif.

-spec lowercase_drive_letter(binary()) -> binary().
lowercase_drive_letter(<<Drive0, ":", Rest/binary>>) ->
Drive = string:to_lower(Drive0),
<<Drive, ":", Rest/binary>>;
lowercase_drive_letter(Path) ->
Path.

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

Expand Down

0 comments on commit 7801b22

Please sign in to comment.