on master help sign in
More IDESlave semantic highlighting

This adds support for :t name

commitde72eb96d4220fbcec4a55409558dd9d497b0492 authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateTue 28 Jan 2014, 10:37 (13 years ago) parent4d2185b
2 files changed+32−10
src/Idris/AbsSyntax.hs+31−7 src/Idris/REPL.hs+1−3
src/Idris/AbsSyntax.hs+31−7
@@ -397,17 +397,41 @@ ihPrintResult h s = do i <- getIState
397397 let good = SexpList [SymbolAtom "ok", toSExp s] in
398398 runIO $ hPutStrLn h $ convSExp "return" good n
399399
400+-- | Write a pretty-printed term to the console with semantic coloring
401+consoleDisplayAnnotated :: Handle -> Doc OutputAnnotation -> Idris ()
402+consoleDisplayAnnotated h output = do ist <- getIState
403+ runIO . hPutStrLn h .
404+ displayDecorated (consoleDecorate ist) .
405+ renderCompact $ output
406+
407+-- | Write pretty-printed output to IDESlave with semantic annotations
408+ideSlaveReturnAnnotated :: Integer -> Handle -> Doc OutputAnnotation -> Idris ()
409+ideSlaveReturnAnnotated n h out = do ist <- getIState
410+ let (str, spans) = displaySpans .
411+ renderCompact .
412+ fmap (fancifyAnnots ist) $
413+ out
414+ good = [SymbolAtom "ok", toSExp str, toSExp spans]
415+ runIO . hPutStrLn h $ convSExp "return" good n
416+
400417ihPrintTermWithType :: Handle -> Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
401418ihPrintTermWithType h tm ty = do ist <- getIState
402419 let output = tm <+> colon <+> ty
403420 case idris_outputmode ist of
404− RawOutput -> runIO .
405− hPutStrLn h .
406− displayDecorated (consoleDecorate ist) .
407− renderCompact $ output
408− IdeSlave n -> let (str, spans) = displaySpans (fmap (fancifyAnnots ist) (renderCompact output))
409− good = [SymbolAtom "ok", toSExp str, toSExp spans]
410− in runIO . hPutStrLn h $ convSExp "return" good n
421+ RawOutput -> consoleDisplayAnnotated h output
422+ IdeSlave n -> ideSlaveReturnAnnotated n h output
423+
424+-- | Pretty-print a collection of overloadings to REPL or IDESlave - corresponds to :t name
425+ihPrintFunTypes :: Handle -> Name -> [(Name, PTerm)] -> Idris ()
426+ihPrintFunTypes h n [] = ihPrintError h $ "No such variable " ++ show n
427+ihPrintFunTypes h n overloads = do imp <- impShow
428+ ist <- getIState
429+ let output = vsep (map (uncurry (ppOverload imp)) overloads)
430+ case idris_outputmode ist of
431+ RawOutput -> consoleDisplayAnnotated h output
432+ IdeSlave n -> ideSlaveReturnAnnotated n h output
433+ where fullName n = annotate (AnnName n Nothing Nothing) $ text (show n)
434+ ppOverload imp n tm = fullName n <+> colon <+> prettyImp imp tm
411435
412436fancifyAnnots :: IState -> OutputAnnotation -> OutputAnnotation
413437fancifyAnnots ist annot@(AnnName n _ _) =
src/Idris/REPL.hs+1−3
@@ -471,9 +471,7 @@ process h fn (Check (PRef _ n))
471471 ts@(t:_) ->
472472 case lookup t (idris_metavars ist) of
473473 Just (_, i, _) -> ihPrintResult h (showMetavarInfo c imp ist n i)
474− Nothing -> ihPrintResult h $
475− concat . intersperse "\n" . map (\n -> showName (Just ist) [] False c n ++ " : " ++
476− showTm ist (delabTy ist n)) $ ts
474+ Nothing -> ihPrintFunTypes h n (map (\n -> (n, delabTy ist n)) ts)
477475 [] -> ihPrintError h $ "No such variable " ++ show n
478476 where
479477 showMetavarInfo c imp ist n i