diff --git a/apps/els_lsp/src/els_diagnostics.erl b/apps/els_lsp/src/els_diagnostics.erl index eb4d32f11..58bd3043f 100644 --- a/apps/els_lsp/src/els_diagnostics.erl +++ b/apps/els_lsp/src/els_diagnostics.erl @@ -39,7 +39,8 @@ -callback run(uri()) -> [diagnostic()]. -callback source() -> binary(). -callback on_complete(uri(), [diagnostic()]) -> ok. --optional_callbacks([ on_complete/2 ]). +-callback init() -> ok. +-optional_callbacks([ on_complete/2, init/0 ]). %%============================================================================== %% API @@ -79,9 +80,7 @@ enabled_diagnostics() -> Default = default_diagnostics(), Enabled = maps:get("enabled", Config, []), Disabled = maps:get("disabled", Config, []), - Diagnostics = lists:usort((Default ++ valid(Enabled)) -- valid(Disabled)), - ok = extra(Diagnostics), - Diagnostics. + lists:usort((Default ++ valid(Enabled)) -- valid(Disabled)). -spec make_diagnostic(range(), binary(), severity(), binary()) -> diagnostic(). make_diagnostic(Range, Message, Severity, Source) -> @@ -119,6 +118,7 @@ run_diagnostic(Uri, Id) -> els_diagnostics_provider:notify(Diagnostics, self()) end }, + ok = init_diagnostic(CbModule), {ok, Pid} = els_background_job:new(Config), Pid. @@ -150,11 +150,11 @@ valid(Ids0) -> end, Valid. --spec extra(list()) -> ok. -extra([]) -> - ok; -extra([<<"sheldon">>|_]) -> - {ok, _} = application:ensure_all_started(sheldon), - ok; -extra([_|T]) -> - extra(T). +-spec init_diagnostic(atom()) -> ok. +init_diagnostic(CbModule) -> + case erlang:function_exported(CbModule, init, 0) of + true -> + CbModule:init(); + false -> + ok + end. diff --git a/apps/els_lsp/src/els_sheldon_diagnostics.erl b/apps/els_lsp/src/els_sheldon_diagnostics.erl index af8422796..84230fa2b 100644 --- a/apps/els_lsp/src/els_sheldon_diagnostics.erl +++ b/apps/els_lsp/src/els_sheldon_diagnostics.erl @@ -1,5 +1,5 @@ %%============================================================================== -%% Compiler diagnostics +%% Sheldon diagnostics %%============================================================================== -module(els_sheldon_diagnostics). @@ -14,7 +14,8 @@ %% Exports %%============================================================================== --export([ is_default/0 +-export([ init/0 + , is_default/0 , run/1 , source/0 ]). @@ -30,6 +31,14 @@ %% Callback Functions %%============================================================================== +-spec init() -> ok. +init() -> + %% By default "sheldon" is not started by reason that he spend few seconds + %% to prepare and load dictionary. The "sheldon" shoulld be load only once + %% when diagnostic is enabled. + application:ensure_all_started(sheldon), + ok. + -spec is_default() -> boolean(). is_default() -> false. @@ -45,8 +54,10 @@ run(Uri) -> of [] -> []; Problems -> format_diagnostics(Problems) - catch _:Err -> - ?LOG_WARNING("Sheldon error.[Err=~p] ", [Err]), + catch Type:Error:Stacktrace -> + ?LOG_WARNING( "Sheldon error: [type=~p] [error=~p] [stacktrace=~p]" + , [Type, Error, Stacktrace] + ), [] end end.