Skip to content

Commit f0ff86e

Browse files
committed
Add OTP support in "Add include_lib" action
Also fixes completion for OTP behaviours
1 parent 04a32dd commit f0ff86e

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

apps/els_lsp/src/els_code_actions.erl

+1-2
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,8 @@ add_include_lib_record(Uri, Range, _Data, [Record]) ->
189189
-spec add_include_file(uri(), range(), els_poi:poi_kind(), atom(), els_poi:poi_id()) -> [map()].
190190
add_include_file(Uri, Range, Kind, Name, Id) ->
191191
%% TODO: Add support for -include() also
192-
%% TODO: Doesn't work for OTP headers
193192
CandidateUris =
194-
els_dt_document:find_candidates(Name, 'header'),
193+
els_dt_document:find_candidates_with_otp(Name, 'header'),
195194
Uris = [
196195
CandidateUri
197196
|| CandidateUri <- CandidateUris,

apps/els_lsp/src/els_completion_provider.erl

+2-8
Original file line numberDiff line numberDiff line change
@@ -946,20 +946,14 @@ item_kind_module(Module) ->
946946

947947
-spec behaviour_modules(list()) -> [atom()].
948948
behaviour_modules(Begin) ->
949-
OtpBehaviours = [
950-
gen_event,
951-
gen_server,
952-
gen_statem,
953-
supervisor
954-
],
955-
Candidates = els_dt_document:find_candidates(callback),
949+
Candidates = els_dt_document:find_candidates_with_otp(callback, 'module'),
956950
Behaviours = [
957951
els_uri:module(Uri)
958952
|| Uri <- Candidates,
959953
lists:prefix(Begin, atom_to_list(els_uri:module(Uri))),
960954
is_behaviour(Uri)
961955
],
962-
OtpBehaviours ++ Behaviours.
956+
Behaviours.
963957

964958
-spec is_behaviour(uri()) -> boolean().
965959
is_behaviour(Uri) ->

apps/els_lsp/src/els_dt_document.erl

+30
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
wrapping_functions/3,
4040
find_candidates/1,
4141
find_candidates/2,
42+
find_candidates_with_otp/2,
4243
get_words/1
4344
]).
4445

@@ -300,6 +301,35 @@ find_candidates(Pattern, Kind) ->
300301
end,
301302
lists:filtermap(Fun, All).
302303

304+
-spec find_candidates_with_otp(atom() | string(), module | header | '_') -> [uri()].
305+
find_candidates_with_otp(Pattern, Kind) ->
306+
%% ets:fun2ms(fun(#els_dt_document{source = Source, uri = Uri, words = Words})
307+
%% when Source =/= otp -> {Uri, Words} end).
308+
MS = [
309+
{
310+
#els_dt_document{
311+
uri = '$1',
312+
id = '_',
313+
kind = Kind,
314+
text = '_',
315+
pois = '_',
316+
source = '_',
317+
words = '$3',
318+
version = '_'
319+
},
320+
[],
321+
[{{'$1', '$3'}}]
322+
}
323+
],
324+
All = ets:select(name(), MS),
325+
Fun = fun({Uri, Words}) ->
326+
case sets:is_element(Pattern, Words) of
327+
true -> {true, Uri};
328+
false -> false
329+
end
330+
end,
331+
lists:filtermap(Fun, All).
332+
303333
-spec get_words(binary()) -> sets:set().
304334
get_words(Text) ->
305335
case erl_scan:string(els_utils:to_list(Text)) of

0 commit comments

Comments
 (0)