diff --git a/apps/els_lsp/src/els_code_actions.erl b/apps/els_lsp/src/els_code_actions.erl index 96c7d406..c4e8fb5d 100644 --- a/apps/els_lsp/src/els_code_actions.erl +++ b/apps/els_lsp/src/els_code_actions.erl @@ -191,9 +191,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, diff --git a/apps/els_lsp/src/els_completion_provider.erl b/apps/els_lsp/src/els_completion_provider.erl index 68cb5a57..bce853e0 100644 --- a/apps/els_lsp/src/els_completion_provider.erl +++ b/apps/els_lsp/src/els_completion_provider.erl @@ -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) -> diff --git a/apps/els_lsp/src/els_dt_document.erl b/apps/els_lsp/src/els_dt_document.erl index 14c8fb9d..aee88268 100644 --- a/apps/els_lsp/src/els_dt_document.erl +++ b/apps/els_lsp/src/els_dt_document.erl @@ -39,6 +39,7 @@ wrapping_functions/3, find_candidates/1, find_candidates/2, + find_candidates_with_otp/2, get_words/1 ]). @@ -66,7 +67,7 @@ kind :: kind() | '_', text :: binary() | '_', pois :: [els_poi:poi()] | '_' | ondemand, - source :: source() | '$2', + source :: source() | '_' | '$2', words :: sets:set() | '_' | '$3', version :: version() | '_' }). @@ -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 diff --git a/apps/els_lsp/test/els_completion_SUITE.erl b/apps/els_lsp/test/els_completion_SUITE.erl index 7c7535a0..fa056fc9 100644 --- a/apps/els_lsp/test/els_completion_SUITE.erl +++ b/apps/els_lsp/test/els_completion_SUITE.erl @@ -311,26 +311,6 @@ attribute_behaviour(Config) -> Uri = ?config(completion_attributes_uri, Config), TriggerKindInvoked = ?COMPLETION_TRIGGER_KIND_INVOKED, Expected = [ - #{ - insertTextFormat => ?INSERT_TEXT_FORMAT_PLAIN_TEXT, - kind => ?COMPLETION_ITEM_KIND_MODULE, - label => <<"gen_event">> - }, - #{ - insertTextFormat => ?INSERT_TEXT_FORMAT_PLAIN_TEXT, - kind => ?COMPLETION_ITEM_KIND_MODULE, - label => <<"gen_server">> - }, - #{ - insertTextFormat => ?INSERT_TEXT_FORMAT_PLAIN_TEXT, - kind => ?COMPLETION_ITEM_KIND_MODULE, - label => <<"gen_statem">> - }, - #{ - insertTextFormat => ?INSERT_TEXT_FORMAT_PLAIN_TEXT, - kind => ?COMPLETION_ITEM_KIND_MODULE, - label => <<"supervisor">> - }, #{ insertTextFormat => ?INSERT_TEXT_FORMAT_PLAIN_TEXT, kind => ?COMPLETION_ITEM_KIND_MODULE,