@@ -1,5 +1,5 @@
11{-# LANGUAGE PatternGuards #-}
2−module Idris.Delaborate (bugaddr, delab, delab', delabMV, delabTy, delabTy', pprintErr) where
2+module Idris.Delaborate (bugaddr, delab, delab', delabMV, delabTy, delabTy', fancifyAnnots, pprintErr) where
33
44-- Convert core TT back into high level syntax, primarily for display
55-- purposes.
@@ -9,6 +9,7 @@ import Util.Pretty
99import Idris.AbsSyntax
1010import Idris.Core.TT
1111import Idris.Core.Evaluate
12+import Idris.Docstrings (overview, renderDocstring)
1213import Idris.ErrReverse
1314
1415import Data.List (intersperse)
@@ -195,7 +196,7 @@ pprintErr' i (NotInjective p x y) =
195196 pprintTerm i (delab i y)
196197pprintErr' i (CantResolve c) = text "Can't resolve type class" <+> pprintTerm i (delab i c)
197198pprintErr' i (CantResolveAlts as) = text "Can't disambiguate name:" <+>
198− align (cat (punctuate (comma <> space) (map text as)))
199+ align (cat (punctuate (comma <> space) (map (fmap (fancifyAnnots i) . annName) as)))
199200pprintErr' i (NoTypeDecl n) = text "No type declaration for" <+> annName n
200201pprintErr' i (NoSuchVariable n) = text "No such variable" <+> annName n
201202pprintErr' i (IncompleteTerm t) = text "Incomplete term" <+> pprintTerm i (delab i t)
@@ -258,6 +259,29 @@ annName n = annName' n (showbasic n)
258259annName' :: Name -> String -> Doc OutputAnnotation
259260annName' n str = annotate (AnnName n Nothing Nothing Nothing) (text str)
260261
262+fancifyAnnots :: IState -> OutputAnnotation -> OutputAnnotation
263+fancifyAnnots ist annot@(AnnName n _ _ _) =
264+ do let ctxt = tt_ctxt ist
265+ docs = docOverview ist n
266+ ty = Just (getTy ist n)
267+ case () of
268+ _ | isDConName n ctxt -> AnnName n (Just DataOutput) docs ty
269+ _ | isFnName n ctxt -> AnnName n (Just FunOutput) docs ty
270+ _ | isTConName n ctxt -> AnnName n (Just TypeOutput) docs ty
271+ _ | isMetavarName n ist -> AnnName n (Just MetavarOutput) docs ty
272+ _ | otherwise -> annot
273+ where docOverview :: IState -> Name -> Maybe String -- pretty-print first paragraph of docs
274+ docOverview ist n = do docs <- lookupCtxtExact n (idris_docstrings ist)
275+ let o = overview (fst docs)
276+ -- TODO make width configurable
277+ out = displayS . renderPretty 1.0 50 $ renderDocstring o
278+ return (out "")
279+ getTy :: IState -> Name -> String -- fails if name not already extant!
280+ getTy ist n = let theTy = pprintPTerm (ppOptionIst ist) [] [] (idris_infixes ist) $
281+ delabTy ist n
282+ in (displayS . renderPretty 1.0 50 $ theTy) ""
283+fancifyAnnots _ annot = annot
284+
261285showSc :: IState -> [(Name, Term)] -> Doc OutputAnnotation
262286showSc i [] = empty
263287showSc i xs = line <> line <> text "In context:" <>