@@ -16,6 +16,7 @@ import Debug.Trace
16import System.IO (stdout, Handle, hPutStrLn)
16import System.IO (stdout, Handle, hPutStrLn)
18import Data.List (nub)
18import Data.List (nub)
19+import Data.Maybe (fromMaybe)
20pshow :: IState -> Err -> String
21pshow :: IState -> Err -> String
21pshow ist err = displayDecorated (consoleDecorate ist) .
22pshow ist err = displayDecorated (consoleDecorate ist) .
@@ -53,16 +54,6 @@ iRender d = do w <- getWidth
53 | otherwise -> do width <- runIO getScreenWidth
54 | otherwise -> do width <- runIO getScreenWidth
54 return $ renderPretty 0.8 width d
55 return $ renderPretty 0.8 width d
56−ihPrintResult :: Handle -> String -> Idris ()
57−ihPrintResult h s = do i <- getIState
58− case idris_outputmode i of
59− RawOutput -> case s of
61− s -> runIO $ hPutStrLn h s
63− let good = SexpList [SymbolAtom "ok", toSExp s] in
64− runIO $ hPutStrLn h $ convSExp "return" good n
66-- | Write a pretty-printed term to the console with semantic coloring
57-- | Write a pretty-printed term to the console with semantic coloring
67consoleDisplayAnnotated :: Handle -> Doc OutputAnnotation -> Idris ()
58consoleDisplayAnnotated :: Handle -> Doc OutputAnnotation -> Idris ()
68consoleDisplayAnnotated h output = do ist <- getIState
59consoleDisplayAnnotated h output = do ist <- getIState
@@ -71,23 +62,8 @@ consoleDisplayAnnotated h output = do ist <- getIState
71 displayDecorated (consoleDecorate ist) $
62 displayDecorated (consoleDecorate ist) $
75−-- | Write pretty-printed output to IDESlave with semantic annotations
76−ideSlaveReturnAnnotated :: Integer -> Handle -> Doc OutputAnnotation -> Idris ()
77−ideSlaveReturnAnnotated n h out = do ist <- getIState
78− (str, spans) <- fmap displaySpans .
80− fmap (fancifyAnnots ist) $
82− let good = [SymbolAtom "ok", toSExp str, toSExp spans]
83− runIO . hPutStrLn h $ convSExp "return" good n
85ihPrintTermWithType :: Handle -> Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
65ihPrintTermWithType :: Handle -> Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
86−ihPrintTermWithType h tm ty = do ist <- getIState
66+ihPrintTermWithType h tm ty = ihRenderResult h (tm <+> colon <+> align ty)
87− let output = tm <+> colon <+> align ty
88− case idris_outputmode ist of
89− RawOutput -> consoleDisplayAnnotated h output
90− IdeSlave n -> ideSlaveReturnAnnotated n h output
92-- | Pretty-print a collection of overloadings to REPL or IDESlave - corresponds to :t name
68-- | Pretty-print a collection of overloadings to REPL or IDESlave - corresponds to :t name
93ihPrintFunTypes :: Handle -> [(Name, Bool)] -> Name -> [(Name, PTerm)] -> Idris ()
69ihPrintFunTypes :: Handle -> [(Name, Bool)] -> Name -> [(Name, PTerm)] -> Idris ()
@@ -96,9 +72,7 @@ ihPrintFunTypes h bnd n overloads = do ist <- getIState
96 let ppo = ppOptionIst ist
72 let ppo = ppOptionIst ist
97 let infixes = idris_infixes ist
73 let infixes = idris_infixes ist
98 let output = vsep (map (uncurry (ppOverload ppo infixes)) overloads)
74 let output = vsep (map (uncurry (ppOverload ppo infixes)) overloads)
99− case idris_outputmode ist of
75+ ihRenderResult h output
100− RawOutput -> consoleDisplayAnnotated h output
101− IdeSlave n -> ideSlaveReturnAnnotated n h output
102 where fullName n = prettyName True bnd n
76 where fullName n = prettyName True bnd n
103 ppOverload ppo infixes n tm =
77 ppOverload ppo infixes n tm =
104 fullName n <+> colon <+> align (pprintPTerm ppo bnd [] infixes tm)
78 fullName n <+> colon <+> align (pprintPTerm ppo bnd [] infixes tm)
@@ -109,18 +83,20 @@ ihRenderResult h d = do ist <- getIState
109 RawOutput -> consoleDisplayAnnotated h d
83 RawOutput -> consoleDisplayAnnotated h d
110 IdeSlave n -> ideSlaveReturnAnnotated n h d
84 IdeSlave n -> ideSlaveReturnAnnotated n h d
112−fancifyAnnots :: IState -> OutputAnnotation -> OutputAnnotation
86+makeAnnName :: IState -> Name -> Maybe OutputAnnotation
113−fancifyAnnots ist annot@(AnnName n _ _ _) =
87+makeAnnName ist n
114− do let ctxt = tt_ctxt ist
115− docs = docOverview ist n
116− ty = Just (getTy ist n)
118− _ | isDConName n ctxt -> AnnName n (Just DataOutput) docs ty
88+ | isDConName n ctxt = annName DataOutput
119− _ | isFnName n ctxt -> AnnName n (Just FunOutput) docs ty
89+ | isFnName n ctxt = annName FunOutput
120− _ | isTConName n ctxt -> AnnName n (Just TypeOutput) docs ty
90+ | isTConName n ctxt = annName TypeOutput
121− _ | isMetavarName n ist -> AnnName n (Just MetavarOutput) docs ty
91+ | isMetavarName n ist = annName MetavarOutput
122− _ | otherwise -> annot
92+ | otherwise = Nothing
93+ where ctxt = tt_ctxt ist
94+ docs = docOverview ist n
95+ ty = Just (getTy ist n)
97+ annName :: NameOutput -> Maybe OutputAnnotation
98+ annName nameType = Just (AnnName n (Just nameType) docs ty)
123− where docOverview :: IState -> Name -> Maybe String -- pretty-print first paragraph of docs
99+ docOverview :: IState -> Name -> Maybe String -- pretty-print first paragraph of docs
124 docOverview ist n = do docs <- lookupCtxtExact n (idris_docstrings ist)
100 docOverview ist n = do docs <- lookupCtxtExact n (idris_docstrings ist)
125 let o = overview (fst docs)
101 let o = overview (fst docs)
126 -- TODO make width configurable
102 -- TODO make width configurable
@@ -130,30 +106,54 @@ fancifyAnnots ist annot@(AnnName n _ _ _) =
130 getTy ist n = let theTy = pprintPTerm (ppOptionIst ist) [] [] (idris_infixes ist) $
106 getTy ist n = let theTy = pprintPTerm (ppOptionIst ist) [] [] (idris_infixes ist) $
131 delabTy ist n
107 delabTy ist n
132 in (displayS . renderPretty 1.0 50 $ theTy) ""
108 in (displayS . renderPretty 1.0 50 $ theTy) ""
111+fancifyAnnots :: IState -> OutputAnnotation -> OutputAnnotation
112+fancifyAnnots ist annot@(AnnName n _ _ _) = case makeAnnName ist n of
113+ Just fancyAnnot -> fancyAnnot
133fancifyAnnots _ annot = annot
115fancifyAnnots _ annot = annot
118+ideSlaveReturnWithStatus :: String -> Integer -> Handle -> Doc OutputAnnotation -> Idris ()
119+ideSlaveReturnWithStatus status n h out = do
121+ (str, spans) <- fmap displaySpans .
123+ fmap (fancifyAnnots ist) $
125+ let good = [SymbolAtom status, toSExp str, toSExp spans]
126+ runIO . hPutStrLn h $ convSExp "return" good n
129+-- | Write pretty-printed output to IDESlave with semantic annotations
130+ideSlaveReturnAnnotated :: Integer -> Handle -> Doc OutputAnnotation -> Idris ()
131+ideSlaveReturnAnnotated = ideSlaveReturnWithStatus "ok"
135-- | Show an error with semantic highlighting
133-- | Show an error with semantic highlighting
136ihRenderError :: Handle -> Doc OutputAnnotation -> Idris ()
134ihRenderError :: Handle -> Doc OutputAnnotation -> Idris ()
137ihRenderError h e = do ist <- getIState
135ihRenderError h e = do ist <- getIState
138 case idris_outputmode ist of
136 case idris_outputmode ist of
139 RawOutput -> consoleDisplayAnnotated h e
137 RawOutput -> consoleDisplayAnnotated h e
140− IdeSlave n -> do
138+ IdeSlave n -> ideSlaveReturnWithStatus "error" n h e
141− (str, spans) <- fmap displaySpans .
139+
142− iRender .
140+ihPrintWithStatus :: String -> Handle -> String -> Idris ()
143− fmap (fancifyAnnots ist) $
141+ihPrintWithStatus status h s = do
144− e
142+ i <- getIState
143+ case idris_outputmode i of
144+ RawOutput -> case s of
146+ s -> runIO $ hPutStrLn h s
145− let good = [SymbolAtom "error", toSExp str, toSExp spans]
148+ let good = SexpList [SymbolAtom status, toSExp s] in
146− runIO . hPutStrLn h $ convSExp "return" good n
149+ runIO $ hPutStrLn h $ convSExp "return" good n
152+ihPrintResult :: Handle -> String -> Idris ()
153+ihPrintResult = ihPrintWithStatus "ok"
148ihPrintError :: Handle -> String -> Idris ()
155ihPrintError :: Handle -> String -> Idris ()
149−ihPrintError h s = do i <- getIState
156+ihPrintError = ihPrintWithStatus "error"
150− case idris_outputmode i of
151− RawOutput -> case s of
153− s -> runIO $ hPutStrLn h s
155− let good = SexpList [SymbolAtom "error", toSExp s] in
156− runIO . hPutStrLn h $ convSExp "return" good n
158ihputStrLn :: Handle -> String -> Idris ()
158ihputStrLn :: Handle -> String -> Idris ()
159ihputStrLn h s = do i <- getIState
159ihputStrLn h s = do i <- getIState