From fa9973941071d026aa6008c6134619a21d4e90de Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 27 Jan 2024 16:03:33 +0100 Subject: [PATCH] ; 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. --- sweep.pl | 10 ++++++++++ sweeprolog-tests.el | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/sweep.pl b/sweep.pl index 6fd7366..d4c088d 100644 --- a/sweep.pl +++ b/sweep.pl @@ -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). diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index 67fb6e4..7827345 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -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 -- 2.39.2