Skip to content

Commit

Permalink
Add init callback to diagnostics behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
vkatsuba committed Dec 2, 2021
1 parent 630156c commit f3c3852
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
24 changes: 12 additions & 12 deletions apps/els_lsp/src/els_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) ->
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
8 changes: 7 additions & 1 deletion apps/els_lsp/src/els_sheldon_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
%% Exports
%%==============================================================================

-export([ is_default/0
-export([ init/0
, is_default/0
, run/1
, source/0
]).
Expand All @@ -30,6 +31,11 @@
%% Callback Functions
%%==============================================================================

-spec init() -> ok.
init() ->
{ok, _} = application:ensure_all_started(sheldon),
ok.

-spec is_default() -> boolean().
is_default() ->
false.
Expand Down

0 comments on commit f3c3852

Please sign in to comment.