]> git.eshelyaron.com Git - sweep.git/commitdiff
Fix docs for predicate at point in DCG bodies
authorEshel Yaron <me@eshelyaron.com>
Fri, 24 Nov 2023 11:18:40 +0000 (12:18 +0100)
committerEshel Yaron <me@eshelyaron.com>
Fri, 24 Nov 2023 11:44:54 +0000 (12:44 +0100)
* 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
sweeprolog-tests.el

index 21fb0f64496402dbae6a9ec0be900d20008ec573..cb99ee63925fc3cfc2d429652c2aacbc69240333 100644 (file)
--- 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),
index 595b89e0302bf8ad87075b8b29efacb2a3953e8c..5c57520ab335d1cc55431a956bec307f0380d3d6 100644 (file)
@@ -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