diff --git a/apps/els_lsp/priv/code_navigation/src/completion_records.erl b/apps/els_lsp/priv/code_navigation/src/completion_records.erl index 4fe4ad6a..803da993 100644 --- a/apps/els_lsp/priv/code_navigation/src/completion_records.erl +++ b/apps/els_lsp/priv/code_navigation/src/completion_records.erl @@ -8,3 +8,11 @@ function_a(#record_a{field_a = a, field_b = b}) -> %% #record_a{ field_y = y}, {}. + +-spec function_b(#record_b{}) -> #record_a{}. +function_b(R) -> + function_a(R). + +-define(A, #record_a{}). +function_c(R) -> + function_a(R). diff --git a/apps/els_lsp/src/els_completion_provider.erl b/apps/els_lsp/src/els_completion_provider.erl index a83b0105..68cb5a57 100644 --- a/apps/els_lsp/src/els_completion_provider.erl +++ b/apps/els_lsp/src/els_completion_provider.erl @@ -628,15 +628,16 @@ complete_record_field( -spec complete_record_field(map(), pos(), binary()) -> items(). complete_record_field(#{text := Text0} = Document, Pos, Suffix) -> Prefix0 = els_text:range(Text0, {1, 1}, Pos), - POIs = els_dt_document:pois(Document, [function]), - %% Look for record start between current pos and end of last function + POIs = els_dt_document:pois(Document, [function, spec, define, callback, record]), + %% Look for record start between current position and end of last + %% relevant top level expression Prefix = case els_scope:pois_before(POIs, #{from => Pos, to => Pos}) of [#{range := #{to := {Line, _}}} | _] -> {_, Prefix1} = els_text:split_at_line(Prefix0, Line), Prefix1; _ -> - %% No function before, consider all the text + %% Found no POI before, consider all the text Prefix0 end, case parse_record(els_text:strip_comments(Prefix), Suffix) of diff --git a/apps/els_lsp/test/els_completion_SUITE.erl b/apps/els_lsp/test/els_completion_SUITE.erl index df9054a6..0f53eeb0 100644 --- a/apps/els_lsp/test/els_completion_SUITE.erl +++ b/apps/els_lsp/test/els_completion_SUITE.erl @@ -33,6 +33,7 @@ records/1, record_fields/1, record_fields_inside_record/1, + record_fields_no_completion/1, types/1, types_export_list/1, types_context/1, @@ -1195,6 +1196,23 @@ record_fields_inside_record(Config) -> ?assertEqual(lists:sort(Expected2), lists:sort(Completion2)), ok. +-spec record_fields_no_completion(config()) -> ok. +record_fields_no_completion(Config) -> + %% These should NOT trigger record fields completion + %% Instead expected behaviour is to trigger regular atom completion + Uri = ?config(completion_records_uri, Config), + TriggerKindInvoked = ?COMPLETION_TRIGGER_KIND_INVOKED, + #{result := Result} = + els_client:completion(Uri, 14, 14, TriggerKindInvoked, <<>>), + + #{result := Result} = + els_client:completion(Uri, 18, 14, TriggerKindInvoked, <<>>), + + Labels = [Label || #{label := Label} <- Result], + ?assert(lists:member(<<"function_a/1">>, Labels)), + ?assert(lists:member(<<"function_b/1">>, Labels)), + ok. + -spec types(config()) -> ok. types(Config) -> TriggerKind = ?COMPLETION_TRIGGER_KIND_INVOKED,