Skip to content

Commit

Permalink
Add config to enable on type formatting, defaulting to false
Browse files Browse the repository at this point in the history
  • Loading branch information
onno-vos-dev committed Apr 9, 2021
1 parent ea3bfd9 commit 21413de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apps/els_core/src/els_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ do_initialize(RootUri, Capabilities, {ConfigPath, Config}) ->
ok = add_code_paths(CodePathExtraDirs, RootPath),
ElvisConfigPath = maps:get("elvis_config_path", Config, undefined),
BSPEnabled = maps:get("bsp_enabled", Config, false),
FormatOnTypeEnabled = maps:get("format_on_type", Config, false),

%% Passed by the LSP client
ok = set(root_uri , RootUri),
Expand All @@ -118,6 +119,7 @@ do_initialize(RootUri, Capabilities, {ConfigPath, Config}) ->
ok = set(macros , Macros),
ok = set(plt_path , DialyzerPltPath),
ok = set(code_reload , CodeReload),
ok = set(format_on_type , FormatOnTypeEnabled),
?LOG_INFO("Config=~p", [Config]),
ok = set(runtime, maps:merge( els_config_runtime:default_config()
, Runtime)),
Expand Down
9 changes: 5 additions & 4 deletions apps/els_lsp/src/els_formatting_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ is_enabled_range() ->
%% make sense.
-spec is_enabled_on_type() -> document_ontypeformatting_options().
is_enabled_on_type() ->
#{ firstTriggerCharacter => <<".">>
, moreTriggerCharacter => []
}.
case els_config:get(format_on_type) of
true -> #{firstTriggerCharacter => <<".">>, moreTriggerCharacter => []};
false -> false
end.

-spec handle_request(any(), state()) -> {any(), state()}.
handle_request({document_formatting, Params}, State) ->
Expand Down Expand Up @@ -159,7 +160,7 @@ ontypeformat_document(_Uri, Document, Line, Col, <<".">>, _Options) ->
{ok, Bin} = file:read_file(TmpFile),
Bin
end,
%% rebar3_formatter adds a newline, since we terminate on.
%% rebar3_formatter adds a newline, since we terminate on .
%% We want to leave the cursor at the current char rather
%% than jumping to a newline
NewText =
Expand Down

0 comments on commit 21413de

Please sign in to comment.