Skip to content

Commit

Permalink
[LSP] Fix initialize on OTP 23.0/23.1 (erlang-ls#1449)
Browse files Browse the repository at this point in the history
* [LSP] Fix initialize on OTP 23.0/23.1

`els_uri:path/2` was calling `uri_string:percent_decode/1`, which is
unavailable until OTP 23.2
(https://www.erlang.org/doc/man/uri_string#percent_decode-1)

* [LSP] Add Dialyzer/xref ignores

Suppress undefined and deprecated function warnings for calls in
`els_uri:percent_decode/1`
  • Loading branch information
danielfinke authored and shuying2244 committed Dec 30, 2023
1 parent 778f420 commit c77bc09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 20 additions & 1 deletion apps/els_core/src/els_uri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
%%==============================================================================
-module(els_uri).

-if(?OTP_RELEASE =:= 23).
-compile([{nowarn_deprecated_function, [{http_uri, decode, 1}]}]).
-endif.

%%==============================================================================
%% Exports
%%==============================================================================
Expand Down Expand Up @@ -84,10 +88,25 @@ uri(Path) ->
uri_join(List) ->
lists:join(<<"/">>, List).

-if(?OTP_RELEASE >= 23).
-if(?OTP_RELEASE > 23).
-spec percent_decode(binary()) -> binary().
percent_decode(Str) ->
uri_string:percent_decode(Str).
-elif(?OTP_RELEASE =:= 23).
-spec percent_decode(binary()) -> binary().
percent_decode(Str) ->
%% The `percent_decode/1' function is unavailable until OTP 23.2
case erlang:function_exported(uri_string, percent_decode, 1) of
'true' ->
percent_decode2(Str);
'false' ->
http_uri:decode(Str)
end.

-dialyzer([{nowarn_function, percent_decode2/1}]).
-spec percent_decode2(binary()) -> binary().
percent_decode2(Str) ->
uri_string:percent_decode(Str).
-else.
-spec percent_decode(binary()) -> binary().
percent_decode(Str) ->
Expand Down
2 changes: 2 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@
%% Set xref ignores for functions introduced in OTP 23 & function of wrangler
{xref_ignores, [
{code, get_doc, 1},
{http_uri, decode, 1},
{shell_docs, render, 4},
{uri_string, percent_decode, 1},
wrangler_handler,
api_wrangler,
wls_code_lens,
Expand Down

0 comments on commit c77bc09

Please sign in to comment.