From 0a58409a4c5404ee349654fde66dd7742a4f4e73 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 24 Nov 2023 12:18:40 +0100 Subject: [PATCH] Fix docs for predicate at point in DCG bodies * sweep.pl (sweep_short_documentation_body/9): Add special handling for control constructs in DCG bodies. * sweeprolog-tests.el (eldoc-dcg): New test. --- sweep.pl | 8 ++++++++ sweeprolog-tests.el | 33 ++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/sweep.pl b/sweep.pl index 21fb0f6..cb99ee6 100644 --- a/sweep.pl +++ b/sweep.pl @@ -375,6 +375,14 @@ sweep_short_documentation_body(Pos, Body, Neck, Point, FileName, Mod, PIString, Neck > 0, !, sweep_short_documentation_body(Pos, Body, 0, Point, FileName, Mod, PIString, Doc, ArgSpan). +sweep_short_documentation_body(term_position(_, _, _, _, ArgsPos), Body, '//', Point, FileName, Mod, PIString, Doc, ArgSpan) :- + is_control_goal(Body), + !, + nth1(Index, ArgsPos, ArgPos), + pos_bounds(ArgPos, ArgBeg, ArgEnd), + ArgBeg =< Point, Point =< ArgEnd, + arg(Index, Body, ArgBody), + sweep_short_documentation_body(ArgPos, ArgBody, '//', Point, FileName, Mod, PIString, Doc, ArgSpan). sweep_short_documentation_body(term_position(_, _, _, _, ArgsPos), Body, Neck, Point, FileName, Mod, PIString, Doc, ArgSpan) :- !, ( nth1(Index, ArgsPos, ArgPos), diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index 595b89e..5c57520 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -2254,8 +2254,8 @@ bbb(A, B) :- "))) (sweeprolog-deftest extract-region-to-predicate-ext-1 () - "Test `sweeprolog-extract-region-to-predicate'." - " + "Test `sweeprolog-extract-region-to-predicate'." + " :- module(bbb, []). bar(A, Y) :- @@ -2316,17 +2316,17 @@ bbb(VarName) :- "))) (sweeprolog-deftest extract-region-to-predicate-lambda-2 () - "Test `sweeprolog-extract-region-to-predicate'." - " + "Test `sweeprolog-extract-region-to-predicate'." + " :- module(bbb, []). bar(A, Y) :- maplist({GoalVarNames}/[VarName]>>ignore(memberchk(VarName, GoalVarNames)), TemplateVarNames). " - (sweeprolog-extract-region-to-predicate 48 114 "bbb") - (should (string= (buffer-string) - " + (sweeprolog-extract-region-to-predicate 48 114 "bbb") + (should (string= (buffer-string) + " :- module(bbb, []). bar(A, Y) :- @@ -2336,4 +2336,23 @@ bar(A, Y) :- bbb(GoalVarNames, VarName) :- ignore(memberchk(VarName, GoalVarNames)). "))) + +(sweeprolog-deftest eldoc-dcg () + "Test `sweep_short_documentation/2' with DCG body terms." + " +:- module(eldocdcg, []). + +%! foo(-Baz:string)// is det. +% +% Doit. + +foo(Bar) --> baz(Bar). +" + (should (equal (sweeprolog--query-once + "sweep" "sweep_short_documentation" + (list "bar --> foo(bar), foo(baz)." 12 (buffer-file-name))) + (list "eldocdcg:foo//1" "foo(-Baz:string)// is det. + Doit. +" (cons 4 15))))) + ;;; sweeprolog-tests.el ends here -- 2.39.2