on master help sign in
Fixes #3264 Show auto implicit documentaton in Idris Doc.
commit088846b3c691cc52932b5978865a5563ada2e489 authorJan de Muijnck-Hughes <jfdm@st-andrews.ac.uk> dateWed 13 Jul 2016, 10:29 (10 years ago) parent96e583c
7 files changed+123−43
CHANGELOG.md+5 idris.cabal+9 src/Idris/Docs.hs+56−43 test/docs005/docs005.idr+19 test/docs005/expected+29 test/docs005/input+2 test/docs005/run+3
CHANGELOG.md+5
@@ -26,6 +26,11 @@
2626* The File Effect has been updated to take into account changes in
2727 `Prelude.File` and to provide a 'better' API.
2828
29+## Tool updates
30+
31+* Idris' documentation system now displays the documentation for auto
32+ implicits in the output of `:doc`. This is tested for in `docs005`.
33+
2934# New in 0.12:
3035
3136## Language updates
idris.cabal+9
@@ -858,6 +858,15 @@ Extra-source-files:
858858 test/docs003/input
859859 test/docs003/*.idr
860860 test/docs003/expected
861+ test/docs004/run
862+ test/docs004/input
863+ test/docs004/*.idr
864+ test/docs004/expected
865+ test/docs005/run
866+ test/docs005/input
867+ test/docs005/*.idr
868+ test/docs005/expected
869+
861870
862871 benchmarks/ALL
863872 benchmarks/*.pl
src/Idris/Docs.hs+56−43
@@ -69,49 +69,62 @@ showDoc ist d
6969 renderDocstring (renderDocTerm (pprintDelab ist) (normaliseAll (tt_ctxt ist) [])) d
7070
7171pprintFD :: IState -> Bool -> Bool -> FunDoc -> Doc OutputAnnotation
72−pprintFD ist totalityFlag nsFlag (FD n doc args ty f)
73− = nest 4 (prettyName True nsFlag [] n <+> colon <+>
74− pprintPTerm ppo [] [ n | (n@(UN n'),_,_,_) <- args
75− , not (T.isPrefixOf (T.pack "__") n') ] infixes ty <$>
76− -- show doc
77− renderDocstring (renderDocTerm (pprintDelab ist) (normaliseAll (tt_ctxt ist) [])) doc <$>
78− -- show fixity
79− maybe empty (\f -> text (show f) <> line) f <>
80− -- show arguments doc
81− let argshow = showArgs args [] in
82− (if not (null argshow)
83− then nest 4 $ text "Arguments:" <$> vsep argshow
84− else empty) <>
85− -- show totality status
86− let totality = getTotality in
87− (if totalityFlag && not (null totality) then
88− line <> (vsep . map (\t -> text "The function is" <+> t) $ totality)
89− else
90− empty))
91−
92− where ppo = ppOptionIst ist
93− infixes = idris_infixes ist
94− showArgs ((n, ty, Exp {}, Just d):args) bnd
95− = bindingOf n False <+> colon <+>
96− pprintPTerm ppo bnd [] infixes ty <>
97− showDoc ist d <> line
98− :
99− showArgs args ((n, False):bnd)
100− showArgs ((n, ty, Constraint {}, Just d):args) bnd
101− = text "Class constraint" <+>
102− pprintPTerm ppo bnd [] infixes ty <> showDoc ist d <> line
103− :
104− showArgs args ((n, True):bnd)
105− showArgs ((n, ty, Imp {}, Just d):args) bnd
106− = text "(implicit)" <+>
107− bindingOf n True <+> colon <+>
108− pprintPTerm ppo bnd [] infixes ty <>
109− showDoc ist d <> line
110− :
111− showArgs args ((n, True):bnd)
112− showArgs ((n, _, _, _):args) bnd = showArgs args ((n, True):bnd)
113− showArgs [] _ = []
114− getTotality = map (text . show) $ lookupTotal n (tt_ctxt ist)
72+pprintFD ist totalityFlag nsFlag (FD n doc args ty f) =
73+ nest 4 (prettyName True nsFlag [] n
74+ <+> colon
75+ <+> pprintPTerm ppo [] [ n | (n@(UN n'),_,_,_) <- args
76+ , not (T.isPrefixOf (T.pack "__") n') ] infixes ty
77+ -- show doc
78+ <$> renderDocstring (renderDocTerm (pprintDelab ist) (normaliseAll (tt_ctxt ist) [])) doc
79+ -- show fixity
80+ <$> maybe empty (\f -> text (show f) <> line) f
81+ -- show arguments doc
82+ <> let argshow = showArgs args [] in
83+ (if not (null argshow)
84+ then nest 4 $ text "Arguments:" <$> vsep argshow
85+ else empty)
86+ -- show totality status
87+ <> let totality = getTotality in
88+ (if totalityFlag && not (null totality)
89+ then line <> (vsep . map (\t -> text "The function is" <+> t) $ totality)
90+ else empty))
91+
92+ where
93+ ppo = ppOptionIst ist
94+
95+ infixes = idris_infixes ist
96+
97+ -- Recurse over and show the Function's Documented arguments
98+ showArgs ((n, ty, Exp {}, Just d):args) bnd = -- Explicitly bound.
99+ bindingOf n False
100+ <+> colon
101+ <+> pprintPTerm ppo bnd [] infixes ty
102+ <> showDoc ist d
103+ <> line : showArgs args ((n, False):bnd)
104+ showArgs ((n, ty, Constraint {}, Just d):args) bnd = -- Class constraints.
105+ text "Class constraint"
106+ <+> pprintPTerm ppo bnd [] infixes ty
107+ <> showDoc ist d
108+ <> line : showArgs args ((n, True):bnd)
109+ showArgs ((n, ty, Imp {}, Just d):args) bnd = -- Implicit arguments.
110+ text "(implicit)"
111+ <+> bindingOf n True
112+ <+> colon
113+ <+> pprintPTerm ppo bnd [] infixes ty
114+ <> showDoc ist d
115+ <> line : showArgs args ((n, True):bnd)
116+ showArgs ((n, ty, TacImp{}, Just d):args) bnd = -- Tacit implicits
117+ text "(auto implicit)"
118+ <+> bindingOf n True
119+ <+> colon
120+ <+> pprintPTerm ppo bnd [] infixes ty
121+ <> showDoc ist d
122+ <> line : showArgs args ((n, True):bnd)
123+ showArgs ((n, _, _, _):args) bnd = -- Anything else
124+ showArgs args ((n, True):bnd)
125+ showArgs [] _ = [] -- end of arguments
126+
127+ getTotality = map (text . show) $ lookupTotal n (tt_ctxt ist)
115128
116129pprintFDWithTotality :: IState -> Bool -> FunDoc -> Doc OutputAnnotation
117130pprintFDWithTotality ist = pprintFD ist True
test/docs005/docs005.idrnew file+19
@@ -0,0 +1,19 @@
1+module docs005
2+
3+import Data.List
4+
5+%default total
6+
7+||| A foobar with an auto implicit
8+data Foobar : Type where
9+ ||| New Foo
10+ |||
11+ ||| @xs Some `xs`
12+ ||| @ys Some `ys`
13+ ||| @prf The prf
14+ ||| @prf1 A prf
15+ NewFoo : (xs : List String)
16+ -> (ys : List Nat)
17+ -> {prf1 : NonEmpty xs}
18+ -> {auto prf : NonEmpty ys}
19+ -> Foobar
test/docs005/expectednew file+29
@@ -0,0 +1,29 @@
1+Data type docs005.Foobar : Type
2+ A foobar with an auto implicit
3+
4+Constructors:
5+ NewFoo : (xs : List String) ->
6+ (ys : List Nat) -> {auto prf : NonEmpty ys} -> Foobar
7+ New Foo
8+ Arguments:
9+ xs : List String -- Some xs
10+
11+ ys : List Nat -- Some ys
12+
13+ (implicit) prf1 : NonEmpty xs -- A prf
14+
15+ (auto implicit) prf : NonEmpty ys -- The prf
16+
17+docs005.NewFoo : (xs : List String) ->
18+ (ys : List Nat) -> {auto prf : NonEmpty ys} -> Foobar
19+ New Foo
20+ Arguments:
21+ xs : List String -- Some xs
22+
23+ ys : List Nat -- Some ys
24+
25+ (implicit) prf1 : NonEmpty xs -- A prf
26+
27+ (auto implicit) prf : NonEmpty ys -- The prf
28+
29+ The function is Total
test/docs005/inputnew file+2
@@ -0,0 +1,2 @@
1+:doc Foobar
2+:doc NewFoo
test/docs005/runnew file+3
@@ -0,0 +1,3 @@
1+#!/usr/bin/env bash
2+${IDRIS:-idris} --quiet --nocolor docs005.idr < input
3+rm *.ibc