@@ -6,63 +6,62 @@ import Idris.Delaborate
6import Idris.Core.TT
6import Idris.Core.TT
7import Idris.Core.Evaluate
7import Idris.Core.Evaluate
9import Data.Maybe
11import Data.Maybe
10import Data.List
12import Data.List
12-- TODO: Only include names with public/abstract accessibility
14-- TODO: Only include names with public/abstract accessibility
14−data FunDoc = Doc Name String
16+data FunDoc = FD Name String
15− [(Name, PArg)] -- args
17+ [(Name, PArg)] -- args
16− PTerm -- function type
18+ PTerm -- function type
17− (Maybe Fixity)
19+ (Maybe Fixity)
19−data Doc = FunDoc FunDoc
21+data Docs = FunDoc FunDoc
20− | DataDoc FunDoc -- type constructor docs
22+ | DataDoc FunDoc -- type constructor docs
21− [FunDoc] -- data constructor docs
23+ [FunDoc] -- data constructor docs
22− | ClassDoc Name String -- class docs
24+ | ClassDoc Name String -- class docs
23− [FunDoc] -- method docs
25+ [FunDoc] -- method docs
25−showDoc "" = ""
27+showDoc "" = empty
26−showDoc x = " -- " ++ x
28+showDoc x = text " -- " <> text x
28−instance Show FunDoc where
30+pprintFD :: Bool -> FunDoc -> Doc OutputAnnotation
29− show (Doc n doc args ty f)
31+pprintFD imp (FD n doc args ty f)
30− = show n ++ " : " ++ show ty ++ "\n" ++ showDoc doc ++ "\n" ++
32+ = prettyName imp [] n <+> colon <+> prettyImp imp ty <$> showDoc doc <$>
31− maybe "" (\f -> show f ++ "\n\n") f ++
33+ maybe empty (\f -> text (show f) <> line) f <>
32− let argshow = mapMaybe showArg args in
34+ let argshow = mapMaybe showArg args in
33− if not (null argshow)
35+ if not (null argshow)
34− then "Arguments:\n\t" ++ showSep "\t" argshow
36+ then nest 4 $ text "Arguments:" <$> vsep argshow
35− else ""
37+ else empty
37 where showArg (n, arg@(PExp _ _ _ _))
39 where showArg (n, arg@(PExp _ _ _ _))
38− = Just $ showName n ++ show (getTm arg) ++
40+ = Just $ bindingOf n False <> prettyImp imp (getTm arg) <>
39− showDoc (pargdoc arg) ++ "\n"
41+ showDoc (pargdoc arg) <> line
40 showArg (n, arg@(PConstraint _ _ _ _))
42 showArg (n, arg@(PConstraint _ _ _ _))
41− = Just $ "Class constraint " ++
43+ = Just $ text "Class constraint" <+>
42− show (getTm arg) ++ showDoc (pargdoc arg)
44+ prettyImp imp (getTm arg) <> showDoc (pargdoc arg) <> line
44 showArg (n, arg@(PImp _ _ _ _ _ doc))
45 showArg (n, arg@(PImp _ _ _ _ _ doc))
45 | not (null doc)
46 | not (null doc)
46− = Just $ "(implicit) " ++
47+ = Just $ text "(implicit)" <+>
47− show n ++ " : " ++ show (getTm arg)
48+ bindingOf n True <+> colon <+> prettyImp imp (getTm arg)
48− ++ showDoc (pargdoc arg) ++ "\n"
49+ <> showDoc (pargdoc arg) <> line
49 showArg (n, _) = Nothing
50 showArg (n, _) = Nothing
51− showName (MN _ _) = ""
52− showName x = show x ++ " : "
54−instance Show Doc where
56− show (FunDoc d) = show d
54+pprintDocs imp (FunDoc d) = pprintFD imp d
57− show (DataDoc t args) = "Data type " ++ show t ++
55+pprintDocs imp (DataDoc t args)
58− "\nConstructors:\n\n" ++
56+ = text "Data type" <+> pprintFD imp t <$>
59− showSep "\n" (map show args)
57+ nest 4 (text "Constructors:" <> line <>
58+ vsep (map (pprintFD imp) args))
60− show (ClassDoc n doc meths)
59+pprintDocs imp (ClassDoc n doc meths)
61− = "Type class " ++ show n ++ -- parameters?
60+ = text "Type class" <+> prettyName imp [] n <$> -- parameters?
62− "\nMethods:\n\n" ++
61+ nest 4 (text "Methods:" <$>
63− showSep "\n" (map show meths)
62+ vsep (map (pprintFD imp) meths))
65−getDocs :: Name -> Idris Doc
64+getDocs :: Name -> Idris Docs
67 = do i <- getIState
66 = do i <- getIState
68 case lookupCtxt n (idris_classes i) of
67 case lookupCtxt n (idris_classes i) of
@@ -72,13 +71,13 @@ getDocs n
72 _ -> do fd <- docFun n
71 _ -> do fd <- docFun n
73 return (FunDoc fd)
72 return (FunDoc fd)
75−docData :: Name -> TypeInfo -> Idris Doc
74+docData :: Name -> TypeInfo -> Idris Docs
76docData n ti
75docData n ti
77 = do tdoc <- docFun n
76 = do tdoc <- docFun n
78 cdocs <- mapM docFun (con_names ti)
77 cdocs <- mapM docFun (con_names ti)
79 return (DataDoc tdoc cdocs)
78 return (DataDoc tdoc cdocs)
81−docClass :: Name -> ClassInfo -> Idris Doc
80+docClass :: Name -> ClassInfo -> Idris Docs
82docClass n ci
81docClass n ci
83 = do i <- getIState
82 = do i <- getIState
84 let docstr = case lookupCtxt n (idris_docstrings i) of
83 let docstr = case lookupCtxt n (idris_docstrings i) of
@@ -105,7 +104,7 @@ docFun n
105 [] -> Nothing
104 [] -> Nothing
106 (Fix x _:_) -> Just x
105 (Fix x _:_) -> Just x
108− return (Doc n docstr args (delab i ty) f)
107+ return (FD n docstr args (delab i ty) f)
109 where funName :: Name -> String
108 where funName :: Name -> String
110 funName (UN n) = str n
109 funName (UN n) = str n
111 funName (NS n _) = funName n
110 funName (NS n _) = funName n