From: Eshel Yaron Date: Sun, 27 Nov 2022 19:08:14 +0000 (+0200) Subject: ENHANCED: use argument names for holes in predicate completion X-Git-Tag: V9.1.0-sweep-0.9.3~2 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=33323c75863b3b3ad8313161d29c59546e40191b;p=sweep.git ENHANCED: use argument names for holes in predicate completion * sweep.pl (predicate_argument_names/2): new predicate. (sweep_format_predicate/2): use it, and revise into... (sweep_format_predicate/4): new predicate. (sweep_predicate_completion_candidates): use it. --- diff --git a/sweep.pl b/sweep.pl index 2eeb37d..1aaa755 100644 --- a/sweep.pl +++ b/sweep.pl @@ -775,29 +775,37 @@ sweep_atom_collection(Sub, Col) :- sweep_predicate_completion_candidates(D, Ps) :- integer(D), + sweep_current_module(M), findall(H, - ( sweep_current_module(M), - ( @(predicate_property(H0, visible), M) - ; xref_defined(_, H0, _) + ( ( @(predicate_property(H, visible), M) + ; xref_defined(_, H, _) ), - adjust_arity(D, H0, H) + pi_head(_/N, H), + N - D >= 0 ), Hs), - maplist(sweep_format_predicate, Hs, Ps). - -adjust_arity(0, H, H) :- !. -adjust_arity(D, H0, H) :- pi_head(F/N0, H0), !, N is N0 - D, N >= 0, pi_head(F/N, H). -adjust_arity(D, H0, H) :- pi_head(M:F/N0, H0), N is N0 - D, N >= 0, pi_head(M:F/N, H). - -sweep_format_predicate(H, [S|SP]) :- - term_variables(H, Vs), - maplist(=('$VAR'('_')), Vs), + maplist(sweep_format_predicate(M, D), Hs, Ps). + +sweep_format_predicate(M0, D, H0, [S|SP]) :- + pi_head(F/N0, H0), + N is N0 - D, + length(NamedArgs, N), + append(NamedArgs, _, OpenNamedArgs), + ( @(predicate_property(H0, implementation_module(M)), M0), + predicate_argument_names(M:F/N0, As) + -> maplist(name_variable, As, Vs), OpenNamedArgs = Vs + ; maplist(=('$VAR'('_')), NamedArgs) + ), + !, + H =.. [F|NamedArgs], term_string(H, S, [quoted(true), character_escapes(true), spacing(next_argument), numbervars(true)]), term_string(_, S, [subterm_positions(SP)]). +name_variable(N, V) :- V = '$VAR'(N). + sweep_context_callable([H|T], R) :- H = [F0|_], atom_string(F, F0), @@ -882,3 +890,18 @@ sweep_file_path_in_library(Path, Spec) :- file_name_on_path(Path, Spec0), prolog_deps:segments(Spec0, Spec1), term_string(Spec1, Spec). + +predicate_argument_names(M:F/A, Args) :- + doc_comment(M:F/A, _, _, C), + comment_modes(C, ModeAndDets), + member(ModeAndDet, ModeAndDets), + strip_det(ModeAndDet, Head), + Head =.. [_|Args0], + length(Args0, A), + maplist(strip_mode_and_type, Args0, Args). + +strip_mode_and_type(S, N), compound(S) => arg(1, S, N0), strip_type(N0, N). +strip_mode_and_type(S, N) => strip_type(S, N). + +strip_type(N:_, N) :- !. +strip_type(N, N).