Skip to content

Commit

Permalink
Add OTP support in "Add include_lib" action
Browse files Browse the repository at this point in the history
Also fixes completion for OTP behaviours
  • Loading branch information
plux committed Oct 8, 2024
1 parent 04a32dd commit 609a79a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
3 changes: 1 addition & 2 deletions apps/els_lsp/src/els_code_actions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,8 @@ add_include_lib_record(Uri, Range, _Data, [Record]) ->
-spec add_include_file(uri(), range(), els_poi:poi_kind(), atom(), els_poi:poi_id()) -> [map()].
add_include_file(Uri, Range, Kind, Name, Id) ->
%% TODO: Add support for -include() also
%% TODO: Doesn't work for OTP headers
CandidateUris =
els_dt_document:find_candidates(Name, 'header'),
els_dt_document:find_candidates_with_otp(Name, 'header'),
Uris = [
CandidateUri
|| CandidateUri <- CandidateUris,
Expand Down
10 changes: 2 additions & 8 deletions apps/els_lsp/src/els_completion_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -946,20 +946,14 @@ item_kind_module(Module) ->

-spec behaviour_modules(list()) -> [atom()].
behaviour_modules(Begin) ->
OtpBehaviours = [
gen_event,
gen_server,
gen_statem,
supervisor
],
Candidates = els_dt_document:find_candidates(callback),
Candidates = els_dt_document:find_candidates_with_otp(callback, 'module'),
Behaviours = [
els_uri:module(Uri)
|| Uri <- Candidates,
lists:prefix(Begin, atom_to_list(els_uri:module(Uri))),
is_behaviour(Uri)
],
OtpBehaviours ++ Behaviours.
Behaviours.

-spec is_behaviour(uri()) -> boolean().
is_behaviour(Uri) ->
Expand Down
30 changes: 30 additions & 0 deletions apps/els_lsp/src/els_dt_document.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
wrapping_functions/3,
find_candidates/1,
find_candidates/2,
find_candidates_with_otp/2,
get_words/1
]).

Expand Down Expand Up @@ -300,6 +301,35 @@ find_candidates(Pattern, Kind) ->
end,
lists:filtermap(Fun, All).

-spec find_candidates_with_otp(atom() | string(), module | header | '_') -> [uri()].
find_candidates_with_otp(Pattern, Kind) ->
%% ets:fun2ms(fun(#els_dt_document{source = Source, uri = Uri, words = Words})
%% when Source =/= otp -> {Uri, Words} end).
MS = [
{
#els_dt_document{
uri = '$1',
id = '_',
kind = Kind,
text = '_',
pois = '_',
source = '_',
words = '$3',
version = '_'
},
[],
[{{'$1', '$3'}}]
}
],
All = ets:select(name(), MS),
Fun = fun({Uri, Words}) ->
case sets:is_element(Pattern, Words) of
true -> {true, Uri};
false -> false
end
end,
lists:filtermap(Fun, All).

-spec get_words(binary()) -> sets:set().
get_words(Text) ->
case erl_scan:string(els_utils:to_list(Text)) of
Expand Down

0 comments on commit 609a79a

Please sign in to comment.