Skip to content

Commit

Permalink
OTP27 support (#1530)
Browse files Browse the repository at this point in the history
* erlfmt 1.3.0 -> 1.5.0 (otp27 parsing support)

* doc and moduledoc attribute snippets

* assume uri_string:percent_decode/1 (otp<24 support removed)

* removed has_eep48_edoc/0 (assume OTP>=24)

* call to els_completion_SUITE:call_markdown/3 removed
  • Loading branch information
MarkoMin authored Sep 18, 2024
1 parent dc12111 commit eccc48d
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 208 deletions.
31 changes: 1 addition & 30 deletions apps/els_core/src/els_uri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
%%==============================================================================
-module(els_uri).

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

%%==============================================================================
%% Exports
%%==============================================================================
Expand Down Expand Up @@ -45,7 +41,7 @@ path(Uri, IsWindows) ->
path := Path0,
scheme := <<"file">>
} = uri_string:normalize(Uri, [return_map]),
Path = percent_decode(Path0),
Path = uri_string:percent_decode(Path0),
case {IsWindows, Host} of
{true, <<>>} ->
% Windows drive letter, have to strip the initial slash
Expand Down Expand Up @@ -89,31 +85,6 @@ uri(Path) ->
uri_join(List) ->
lists:join(<<"/">>, List).

-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) ->
http_uri:decode(Str).
-endif.

-spec lowercase_drive_letter(binary()) -> binary().
lowercase_drive_letter(<<Drive0, ":", Rest/binary>>) ->
Drive = string:to_lower(Drive0),
Expand Down
8 changes: 8 additions & 0 deletions apps/els_lsp/src/els_compiler_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ make_code(epp, {error, _Term}) ->
<<"E1522">>;
make_code(epp, {warning, _Term}) ->
<<"E1523">>;
make_code(epp, {moduledoc, invalid, _}) ->
<<"E1524">>;
make_code(epp, {moduledoc, file, _}) ->
<<"E1525">>;
make_code(epp, {doc, invalid, _}) ->
<<"E1526">>;
make_code(epp, {doc, file, _}) ->
<<"E1527">>;
make_code(epp, _E) ->
<<"E1599">>;
%% stdlib-3.15.2/src/qlc.erl
Expand Down
60 changes: 59 additions & 1 deletion apps/els_lsp/src/els_completion_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ attributes(Document) ->
snippet(attribute_type),
snippet(attribute_vsn),
attribute_module(Document)
].
] ++ docs_attributes().

-spec attribute_module(els_dt_document:item()) -> item().
attribute_module(#{id := Id}) ->
Expand All @@ -491,6 +491,24 @@ attribute_module(#{id := Id}) ->
<<"module(", IdBin/binary, ").">>
).

-spec docs_attributes() -> items().
-if(?OTP_RELEASE >= 27).
docs_attributes() ->
[
snippet(attribute_moduledoc_map),
snippet(attribute_doc_map),
snippet(attribute_moduledoc_file),
snippet(attribute_doc_file),
snippet(attribute_moduledoc_text),
snippet(attribute_doc_text),
snippet(attribute_moduledoc_false),
snippet(attribute_doc_false)
].
-else.
docs_attributes() ->
[].
-endif.

%%=============================================================================
%% Include paths
%%=============================================================================
Expand Down Expand Up @@ -567,6 +585,46 @@ snippet(attribute_compile) ->
snippet(
<<"-compile().">>,
<<"compile(${1:}).">>
);
snippet(attribute_moduledoc_text) ->
snippet(
<<"-moduledoc \"\"\"Text\"\"\".">>,
<<"moduledoc \"\"\"\n${1:Text}\n\"\"\".">>
);
snippet(attribute_doc_text) ->
snippet(
<<"-doc \"\"\"Text\"\"\".">>,
<<"doc \"\"\"\n${1:Text}\n\"\"\".">>
);
snippet(attribute_moduledoc_false) ->
snippet(
<<"-moduledoc false.">>,
<<"moduledoc false.">>
);
snippet(attribute_doc_false) ->
snippet(
<<"-doc false.">>,
<<"doc false.">>
);
snippet(attribute_moduledoc_map) ->
snippet(
<<"-moduledoc #{}.">>,
<<"moduledoc #{${1:}}.">>
);
snippet(attribute_doc_map) ->
snippet(
<<"-doc #{}.">>,
<<"doc #{${1:}}.">>
);
snippet(attribute_moduledoc_file) ->
snippet(
<<"-moduledoc File.">>,
<<"moduledoc {file,\"${1:File}\"}.">>
);
snippet(attribute_doc_file) ->
snippet(
<<"-doc File.">>,
<<"doc {file,\"${1:File}\"}.">>
).

-spec snippet(binary(), binary()) -> item().
Expand Down
Loading

0 comments on commit eccc48d

Please sign in to comment.