diff --git a/apps/els_lsp/src/els_formatting_provider.erl b/apps/els_lsp/src/els_formatting_provider.erl index 68cddb190..f6e1c3b96 100644 --- a/apps/els_lsp/src/els_formatting_provider.erl +++ b/apps/els_lsp/src/els_formatting_provider.erl @@ -158,9 +158,13 @@ format_document_local(Dir, RelativePath, rangeformat_document(_Uri, _Document, _Range, _Options) -> {ok, []}. --spec ontypeformat_document(binary(), map() - , number(), number(), string(), formatting_options()) - -> {ok, [text_edit()]}. +-spec ontypeformat_document(binary(), + map(), + number(), + number(), + string(), + formatting_options()) -> + {ok, [text_edit()]}. ontypeformat_document(_Uri, Document, Line, Col, <<".">>, _Options) -> case find_matching_range(Document, Line) of [] -> @@ -168,17 +172,26 @@ ontypeformat_document(_Uri, Document, Line, Col, <<".">>, _Options) -> [MatchingRange] -> {StartLine, _} = Id = els_poi:id(MatchingRange), Text = els_dt_document:text(Document), - RangeText = els_text:range(Text, Id, {Line, Col}), + RangeText = els_text:range(Text, Id, {Line, Col - 1}), % Skip formatting if the . is on a commented line. - case string:trim(els_text:line(Text, Line - 1), both) of + case string:trim( + els_text:line(Text, Line - 1), both) + of <<"%", _/binary>> -> {ok, []}; _ -> ParseF = fun(Dir) -> TmpFile = tmp_file(Dir), - ok = file:write_file(TmpFile, RangeText), - Opts = #{break_indent => 2, output_dir => current}, + ok = file:write_file(TmpFile, <>), + Opts = + #{formatter => default_formatter, + paper => 100, + parse_macro_definitions => false, + truncate_strings => true, + parenthesize_infix_operations => true, + break_indent => 2, + output_dir => current}, RebarState = #{}, T = rebar3_formatter:new(default_formatter, Opts, RebarState), rebar3_formatter:format_file(TmpFile, T), diff --git a/rebar.config b/rebar.config index 3aa65e0c4..7bafbe6ab 100644 --- a/rebar.config +++ b/rebar.config @@ -11,7 +11,7 @@ , {yamerl, "0.8.1"} , {docsh, "0.7.2"} , {elvis_core, "~> 1.3"} - , {rebar3_format, "0.8.2"} + , {rebar3_format, "1.0.1"} %%, {erlfmt, "1.0.0"} , {erlfmt, {git, "https://github.com/gomoripeti/erlfmt.git", {tag, "erlang_ls_parser_error_loc"}}} %% Temp until erlfmt PR 325 is merged (commit d4422d1) , {ephemeral, "2.0.4"} diff --git a/rebar.lock b/rebar.lock index 7ce421b45..5c91faf1e 100644 --- a/rebar.lock +++ b/rebar.lock @@ -13,10 +13,10 @@ {ref,"e93db1c6725760def005c69d72f53b1a889b4c2f"}}, 0}, {<<"jsx">>,{pkg,<<"jsx">>,<<"3.0.0">>},0}, - {<<"katana_code">>,{pkg,<<"katana_code">>,<<"0.2.1">>},1}, + {<<"katana_code">>,{pkg,<<"katana_code">>,<<"1.1.2">>},1}, {<<"providers">>,{pkg,<<"providers">>,<<"1.8.1">>},1}, {<<"quickrand">>,{pkg,<<"quickrand">>,<<"2.0.1">>},1}, - {<<"rebar3_format">>,{pkg,<<"rebar3_format">>,<<"0.8.2">>},0}, + {<<"rebar3_format">>,{pkg,<<"rebar3_format">>,<<"1.0.1">>},0}, {<<"redbug">>,{pkg,<<"redbug">>,<<"2.0.6">>},0}, {<<"tdiff">>,{pkg,<<"tdiff">>,<<"0.1.2">>},0}, {<<"uuid">>,{pkg,<<"uuid_erl">>,<<"2.0.1">>},0}, @@ -30,10 +30,10 @@ {<<"ephemeral">>, <<"B3E57886ADD5D90C82FE3880F5954978222A122CB8BAA123667401BBAAEC51D6">>}, {<<"getopt">>, <<"C73A9FA687B217F2FF79F68A3B637711BB1936E712B521D8CE466B29CBF7808A">>}, {<<"jsx">>, <<"20A170ABD4335FC6DB24D5FAD1E5D677C55DADF83D1B20A8A33B5FE159892A39">>}, - {<<"katana_code">>, <<"B2195859DF57D8BEBF619A9FD3327CD7D01563A98417156D0F4C5FAB435F2630">>}, + {<<"katana_code">>, <<"4336743263236C3213FF1B979ECAE263940B9084ACE90E9434838F3F98CCA578">>}, {<<"providers">>, <<"70B4197869514344A8A60E2B2A4EF41CA03DEF43CFB1712ECF076A0F3C62F083">>}, {<<"quickrand">>, <<"6D861FA11E6EB51BB2343A2616EFF704C2681A9997F41ABC78E58FA76DA33981">>}, - {<<"rebar3_format">>, <<"2D64DA61E0B87FCA6C4512ADA6D9CBC2B27ADC9AE6844178561147E7121761BD">>}, + {<<"rebar3_format">>, <<"F8D275C9BD9A2541880D03071AF75FD6B78FC80D74158DC0A2C48A913B03D9F4">>}, {<<"redbug">>, <<"A764690B012B67C404562F9C6E1BA47A73892EE17DF5C15F670B1A5BF9D2F25A">>}, {<<"tdiff">>, <<"4E1B30321F1B3D600DF65CD60858EDE1235FE4E5EE042110AB5AD90CD6464AC5">>}, {<<"uuid">>, <<"1FD9079C544D521063897887A1C5B3302DCA98F9BB06AADCDC6FB0663F256797">>}, @@ -46,10 +46,10 @@ {<<"ephemeral">>, <<"4B293D80F75F9C4575FF4B9C8E889A56802F40B018BF57E74F19644EFEE6C850">>}, {<<"getopt">>, <<"53E1AB83B9CEB65C9672D3E7A35B8092E9BDC9B3EE80721471A161C10C59959C">>}, {<<"jsx">>, <<"37BECA0435F5CA8A2F45F76A46211E76418FBEF80C36F0361C249FC75059DC6D">>}, - {<<"katana_code">>, <<"8448AD3F56D9814F98A28BE650F7191BDD506575E345CC16D586660B10F6E992">>}, + {<<"katana_code">>, <<"E7E6162A44E826A03F68B503B7D92981B894BF834C1EF0E647783F7D6688021C">>}, {<<"providers">>, <<"E45745ADE9C476A9A469EA0840E418AB19360DC44F01A233304E118A44486BA0">>}, {<<"quickrand">>, <<"14DB67D4AEF6B8815810EC9F3CCEF5E324B73B56CAE3687F99D752B85BDD4C96">>}, - {<<"rebar3_format">>, <<"CA8FF27638C2169593D1449DACBE8895634193ED3334E906B54FC97F081F5213">>}, + {<<"rebar3_format">>, <<"3896FA8BCA201C8A6B725D5DE67E0031F00A087C4BE69B4202CA7EA7AA0DA9E3">>}, {<<"redbug">>, <<"AAD9498671F4AB91EACA5099FE85A61618158A636E6286892C4F7CF4AF171D04">>}, {<<"tdiff">>, <<"E0C2E168F99252A5889768D5C8F1E6510A184592D4CFA06B22778A18D33D7875">>}, {<<"uuid">>, <<"AB57CACCD51F170011E5F444CE865F84B41605E483A9EFCC468C1AFAEC87553B">>},