~eshel/sweep

fa9973941071d026aa6008c6134619a21d4e90de — Eshel Yaron 4 months ago 505d999
; Fix ElDoc at-point docs with SSU guards and DCG pushback lists

* sweep.pl (sweep_short_documentation_head/9): Fix handling of SSU
guards and DCG pushback lists.

* sweeprolog-tests.el (eldoc-ssu-guard,eldoc-dcg-pushback): New tests.
2 files changed, 47 insertions(+), 0 deletions(-)

M sweep.pl
M sweeprolog-tests.el
M sweep.pl => sweep.pl +10 -0
@@ 307,6 307,16 @@ sweep_short_documentation_head(brace_term_position(Beg, End, _), Head, Neck, Poi
    ;   Arg = 0
    ),
    sweep_short_documentation_(FileName, Mod, Head, Arg, Neck, PIString, Doc, ArgSpan).
sweep_short_documentation_head(term_position(_, _, _, _, [HeadPos, GuardPos]), (Head,Guard), Neck, Point, FileName, Mod, PIString, Doc, ArgSpan) :-
    % SSU guard or DCG pushback
    !,
    (   pos_bounds(HeadPos, HeadBeg, HeadEnd),
        HeadBeg =< Point, Point =< HeadEnd
    ->  sweep_short_documentation_head(HeadPos, Head, Neck, Point, FileName, Mod, PIString, Doc, ArgSpan)
    ;   pos_bounds(GuardPos, GuardBeg, GuardEnd),
        GuardBeg =< Point, Point =< GuardEnd
    ->  sweep_short_documentation_body(GuardPos, Guard, Neck, Point, FileName, Mod, PIString, Doc, ArgSpan)
    ).
sweep_short_documentation_head(term_position(_, _, _, _, [_, Pos]), Mod:Head, Neck, Point, FileName, _, PIString, Doc, ArgSpan) :-
    !,
    sweep_short_documentation_head(Pos, Head, Neck, Point, FileName, Mod, PIString, Doc, ArgSpan).

M sweeprolog-tests.el => sweeprolog-tests.el +37 -0
@@ 2441,5 2441,42 @@ foo(Bar) --> baz(Bar).
    Skip zero or more white-space characters.
" nil))))

(sweeprolog-deftest eldoc-ssu-guard ()
  "Test `sweep_short_documentation/2' with SSU guard."
  "
:- module(eldocssuguard, []).

:- use_module(library(lists)).
"
  (should (equal (sweeprolog--query-once
                  "sweep" "sweep_short_documentation"
                  (list "foo(X), member(X,_) => true." 15 (buffer-file-name)))
                 '("lists:member/2" "member(?Elem,?List) is unspec.
    True if Elem is a member of List.
"
                   (7 . 12)))))


(sweeprolog-deftest eldoc-dcg-pushback ()
  "Test `sweep_short_documentation/2' with DCG pushback list."
  "
:- module(eldocdcgpushback, []).

%!  foo(-Baz:string)// is det.
%
%   Doit.

foo(_) --> [].

"
  (should (equal (sweeprolog--query-once
                  "sweep" "sweep_short_documentation"
                  (list "foo(X), [1,2,3] --> []." 5 (buffer-file-name)))
                 '("eldocdcgpushback:foo//1" "foo(-Baz:string)// is det.
    Doit.
"
                   (4 . 15)))))



;;; sweeprolog-tests.el ends here