{-|
Module      : Idris.REPL
Description : Entry Point for the Idris REPL and CLI.
License     : BSD3
Maintainer  : The Idris Community.
-}

{-# LANGUAGE CPP, FlexibleContexts, PatternGuards #-}
-- FIXME: {-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
{-# OPTIONS_GHC -fwarn-unused-imports #-}

module Idris.REPL
  ( idemodeStart
  , startServer
  , runClient
  , process
  , replSettings
  , repl
  , proofs
  ) where

import Control.Category
import Control.Concurrent
import Control.Concurrent.Async (race)
import Control.DeepSeq
import qualified Control.Exception as X
import Control.Monad
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Except (runExceptT)
import Control.Monad.Trans.State.Strict (evalStateT, get, put)
import qualified Data.Binary as Binary
import qualified Data.ByteString.Base64 as Base64
import qualified Data.ByteString.Lazy as Lazy
import qualified Data.ByteString.UTF8 as UTF8
import Data.Char
import Data.Either (partitionEithers)
import Data.List hiding (group)
import Data.List.Split (splitOn)
import Data.Maybe
import qualified Data.Set as S
import qualified Data.Text as T
import Data.Version
import Idris.AbsSyntax
import Idris.Apropos (apropos, aproposModules)
import Idris.ASTUtils
import Idris.Colours hiding (colourise)
import Idris.Completion
import Idris.Core.Constraints
import Idris.Core.Evaluate
import Idris.Core.Execute (execute)
import Idris.Core.TT
import Idris.Core.Unify
import Idris.Core.WHNF
import Idris.DataOpts
import Idris.Delaborate
import Idris.Docs
import Idris.Docstrings (overview, renderDocTerm, renderDocstring)
import Idris.Elab.Clause
import Idris.Elab.Term
import Idris.Elab.Value
import Idris.ElabDecls
import Idris.Error
import Idris.ErrReverse
import Idris.Help
import Idris.IBC
import qualified Idris.IdeMode as IdeMode
import Idris.IdrisDoc
import Idris.Info
import Idris.Inliner
import Idris.Interactive
import Idris.ModeCommon
import Idris.Options
import Idris.Output
import Idris.Parser hiding (indent)
import Idris.Prover
import Idris.REPL.Browse (namesInNS, namespacesInNS)
import Idris.REPL.Commands
import Idris.REPL.Parser
import Idris.Termination
import Idris.TypeSearch (searchByType)
import Idris.WhoCalls
import IRTS.CodegenCommon
import IRTS.Compiler
import Network.Socket hiding (defaultPort)
#if (MIN_VERSION_base(4,11,0))
import Prelude hiding (id, (.), (<$>), (<>))
#else
import Prelude hiding (id, (.), (<$>))
#endif
import System.Console.Haskeline as H
import System.Directory
import System.Environment
import System.Exit
import System.FilePath (addExtension, dropExtension, splitExtension,
                        takeDirectory, takeExtension, (<.>), (</>))
import System.FSNotify (watchDir, withManager)
import System.FSNotify.Devel (allEvents, doAllEvents)
import System.IO
import System.Process
import Util.DynamicLinker
import Util.Net (listenOnLocalhost, listenOnLocalhostAnyPort)
import Util.Pretty hiding ((</>))
import Util.System
import Version_idris (gitHash)

-- | Run the REPL
repl :: IState -- ^ The initial state
     -> [FilePath] -- ^ The loaded modules
     -> FilePath -- ^ The file to edit (with :e)
     -> InputT Idris ()
repl :: IState -> [FilePath] -> FilePath -> InputT Idris ()
repl IState
orig [FilePath]
mods FilePath
efile
   = -- H.catch
     do let quiet :: Bool
quiet = IOption -> Bool
opt_quiet (IState -> IOption
idris_options IState
orig)
        IState
i <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Idris IState
getIState
        let colour :: Bool
colour = IState -> Bool
idris_colourRepl IState
i
        let theme :: ColourTheme
theme = IState -> ColourTheme
idris_colourTheme IState
i
        let mvs :: [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
mvs = IState -> [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
idris_metavars IState
i
        let prompt :: FilePath
prompt = if Bool
quiet
                        then FilePath
""
                        else forall {a} {b}.
Show a =>
Bool -> ColourTheme -> [(a, b)] -> FilePath
showMVs Bool
colour ColourTheme
theme [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
mvs forall a. [a] -> [a] -> [a]
++
                             let str :: FilePath
str = [FilePath] -> FilePath
mkPrompt [FilePath]
mods forall a. [a] -> [a] -> [a]
++ FilePath
">" in
                             (if Bool
colour Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
isWindows
                                then ColourTheme -> FilePath -> FilePath
colourisePrompt ColourTheme
theme FilePath
str
                                else FilePath
str) forall a. [a] -> [a] -> [a]
++ FilePath
" "
        Maybe FilePath
x <- forall (m :: * -> *) a. MonadMask m => m a -> m a -> m a
H.handleInterrupt (forall a. InputT Idris a -> InputT Idris a
ctrlC (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just FilePath
"")) (forall (m :: * -> *) a.
(MonadIO m, MonadMask m) =>
InputT m a -> InputT m a
H.withInterrupt forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
(MonadIO m, MonadMask m) =>
FilePath -> InputT m (Maybe FilePath)
getInputLine FilePath
prompt)
        case Maybe FilePath
x of
            Maybe FilePath
Nothing -> do forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not Bool
quiet) (FilePath -> Idris ()
iputStrLn FilePath
"Bye bye")
                          forall (m :: * -> *) a. Monad m => a -> m a
return ()
            Just FilePath
input -> -- H.catch
                do Maybe [FilePath]
ms <- forall (m :: * -> *) a. MonadMask m => m a -> m a -> m a
H.handleInterrupt (forall a. InputT Idris a -> InputT Idris a
ctrlC (forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just [FilePath]
mods))) (forall (m :: * -> *) a.
(MonadIO m, MonadMask m) =>
InputT m a -> InputT m a
H.withInterrupt forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ FilePath
-> IState -> [FilePath] -> FilePath -> Idris (Maybe [FilePath])
processInput FilePath
input IState
orig [FilePath]
mods FilePath
efile)
                   case Maybe [FilePath]
ms of
                        Just [FilePath]
mods -> let efile' :: FilePath
efile' = forall a. a -> Maybe a -> a
fromMaybe FilePath
efile (forall a. [a] -> Maybe a
listToMaybe [FilePath]
mods)
                                     in IState -> [FilePath] -> FilePath -> InputT Idris ()
repl IState
orig [FilePath]
mods FilePath
efile'
                        Maybe [FilePath]
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
--                             ctrlC)
--       ctrlC
   where ctrlC :: InputT Idris a -> InputT Idris a
         ctrlC :: forall a. InputT Idris a -> InputT Idris a
ctrlC InputT Idris a
act = do forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ FilePath -> Idris ()
iputStrLn FilePath
"Interrupted"
                        InputT Idris a
act -- repl orig mods

         showMVs :: Bool -> ColourTheme -> [(a, b)] -> FilePath
showMVs Bool
c ColourTheme
thm [] = FilePath
""
         showMVs Bool
c ColourTheme
thm [(a, b)]
ms = FilePath
"Holes: " forall a. [a] -> [a] -> [a]
++
                                 forall {t} {a}.
(Eq t, Num t, Show a) =>
t -> Bool -> ColourTheme -> [a] -> FilePath
show' Integer
4 Bool
c ColourTheme
thm (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(a, b)]
ms) forall a. [a] -> [a] -> [a]
++ FilePath
"\n"

         show' :: t -> Bool -> ColourTheme -> [a] -> FilePath
show' t
0 Bool
c ColourTheme
thm [a]
ms = let l :: Int
l = forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
ms in
                          FilePath
"... ( + " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Int
l
                             forall a. [a] -> [a] -> [a]
++ FilePath
" other"
                             forall a. [a] -> [a] -> [a]
++ if Int
l forall a. Eq a => a -> a -> Bool
== Int
1 then FilePath
")" else FilePath
"s)"
         show' t
n Bool
c ColourTheme
thm [a
m] = forall {a}. Show a => Bool -> ColourTheme -> a -> FilePath
showM Bool
c ColourTheme
thm a
m
         show' t
n Bool
c ColourTheme
thm (a
m : [a]
ms) = forall {a}. Show a => Bool -> ColourTheme -> a -> FilePath
showM Bool
c ColourTheme
thm a
m forall a. [a] -> [a] -> [a]
++ FilePath
", " forall a. [a] -> [a] -> [a]
++
                                  t -> Bool -> ColourTheme -> [a] -> FilePath
show' (t
n forall a. Num a => a -> a -> a
- t
1) Bool
c ColourTheme
thm [a]
ms

         showM :: Bool -> ColourTheme -> a -> FilePath
showM Bool
c ColourTheme
thm a
n = if Bool
c then ColourTheme -> FilePath -> FilePath
colouriseFun ColourTheme
thm (forall a. Show a => a -> FilePath
show a
n)
                              else forall a. Show a => a -> FilePath
show a
n

-- | Run the REPL server
startServer :: PortNumber -> IState -> [FilePath] -> Idris ()
startServer :: PortNumber -> IState -> [FilePath] -> Idris ()
startServer PortNumber
port IState
orig [FilePath]
fn_in = do ThreadId
tid <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ IO () -> IO ThreadId
forkIO (forall {a}. PortNumber -> IO a
serverLoop PortNumber
port)
                                 forall (m :: * -> *) a. Monad m => a -> m a
return ()
  where serverLoop :: PortNumber -> IO a
serverLoop PortNumber
port = forall a. IO a -> IO a
withSocketsDo forall a b. (a -> b) -> a -> b
$
                              do Socket
sock <- PortNumber -> IO Socket
listenOnLocalhost PortNumber
port
                                 forall {b}. FilePath -> IState -> Socket -> IO b
loop FilePath
fn IState
orig { idris_colourRepl :: Bool
idris_colourRepl = Bool
False } Socket
sock

        fn :: FilePath
fn = forall a. a -> Maybe a -> a
fromMaybe FilePath
"" (forall a. [a] -> Maybe a
listToMaybe [FilePath]
fn_in)

        loop :: FilePath -> IState -> Socket -> IO b
loop FilePath
fn IState
ist Socket
sock
            = do (Socket
s, SockAddr
_) <- Socket -> IO (Socket, SockAddr)
accept Socket
sock
                 Handle
h <- Socket -> IOMode -> IO Handle
socketToHandle Socket
s IOMode
ReadWriteMode
                 Handle -> TextEncoding -> IO ()
hSetEncoding Handle
h TextEncoding
utf8
                 FilePath
cmd <- Handle -> IO FilePath
hGetLine Handle
h
                 let isth :: IState
isth = case IState -> OutputMode
idris_outputmode IState
ist of
                              RawOutput Handle
_ -> IState
ist {idris_outputmode :: OutputMode
idris_outputmode = Handle -> OutputMode
RawOutput Handle
h}
                              IdeMode Integer
n Handle
_ -> IState
ist {idris_outputmode :: OutputMode
idris_outputmode = Integer -> Handle -> OutputMode
IdeMode Integer
n Handle
h}
                 (IState
ist', FilePath
fn) <- IState
-> IState
-> Handle
-> FilePath
-> FilePath
-> IO (IState, FilePath)
processNetCmd IState
orig IState
isth Handle
h FilePath
fn FilePath
cmd
                 Handle -> IO ()
hClose Handle
h
                 FilePath -> IState -> Socket -> IO b
loop FilePath
fn IState
ist' Socket
sock

processNetCmd :: IState -> IState -> Handle -> FilePath -> String ->
                 IO (IState, FilePath)
processNetCmd :: IState
-> IState
-> Handle
-> FilePath
-> FilePath
-> IO (IState, FilePath)
processNetCmd IState
orig IState
i Handle
h FilePath
fn FilePath
cmd
    = do Either Err (IState, FilePath)
res <- case IState
-> FilePath
-> FilePath
-> Either ParseError (Either FilePath Command)
parseCmd IState
i FilePath
"(net)" FilePath
cmd of
                  Left ParseError
err -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a b. a -> Either a b
Left (forall t. FilePath -> Err' t
Msg FilePath
" invalid command"))
                  Right (Right Command
c) -> forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT (FilePath
-> Command -> StateT IState (ExceptT Err IO) (IState, FilePath)
processNet FilePath
fn Command
c) IState
i
                  Right (Left FilePath
err) -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a b. a -> Either a b
Left (forall t. FilePath -> Err' t
Msg FilePath
err))
         case Either Err (IState, FilePath)
res of
              Right (IState, FilePath)
x -> forall (m :: * -> *) a. Monad m => a -> m a
return (IState, FilePath)
x
              Left Err
err -> do Handle -> FilePath -> IO ()
hPutStrLn Handle
h (forall a. Show a => a -> FilePath
show Err
err)
                             forall (m :: * -> *) a. Monad m => a -> m a
return (IState
i, FilePath
fn)
  where
    processNet :: FilePath
-> Command -> StateT IState (ExceptT Err IO) (IState, FilePath)
processNet FilePath
fn Command
Reload = FilePath
-> Command -> StateT IState (ExceptT Err IO) (IState, FilePath)
processNet FilePath
fn (FilePath -> Maybe Int -> Command
Load FilePath
fn forall a. Maybe a
Nothing)
    processNet FilePath
fn (Load FilePath
f Maybe Int
toline) =
  -- The $!! here prevents a space leak on reloading.
  -- This isn't a solution - but it's a temporary stopgap.
  -- See issue #2386
        do IState -> Idris ()
putIState forall a b. NFData a => (a -> b) -> a -> b
$!! IState
orig { idris_options :: IOption
idris_options = IState -> IOption
idris_options IState
i
                              , idris_colourTheme :: ColourTheme
idris_colourTheme = IState -> ColourTheme
idris_colourTheme IState
i
                              , idris_colourRepl :: Bool
idris_colourRepl = Bool
False
                              }
           Bool -> Idris ()
setErrContext Bool
True
           Handle -> Idris ()
setOutH Handle
h
           Bool -> Idris ()
setQuiet Bool
True
           Int -> Idris ()
setVerbose Int
0
           [FilePath]
mods <- [FilePath] -> Maybe Int -> Idris [FilePath]
loadInputs [FilePath
f] Maybe Int
toline
           IState
ist <- Idris IState
getIState
           forall (m :: * -> *) a. Monad m => a -> m a
return (IState
ist, FilePath
f)
    processNet FilePath
fn Command
c = do FilePath -> Command -> Idris ()
process FilePath
fn Command
c
                         IState
ist <- Idris IState
getIState
                         forall (m :: * -> *) a. Monad m => a -> m a
return (IState
ist, FilePath
fn)
    setOutH :: Handle -> Idris ()
    setOutH :: Handle -> Idris ()
setOutH Handle
h =
      do IState
ist <- Idris IState
getIState
         IState -> Idris ()
putIState forall a b. (a -> b) -> a -> b
$ case IState -> OutputMode
idris_outputmode IState
ist of
           RawOutput Handle
_ -> IState
ist {idris_outputmode :: OutputMode
idris_outputmode = Handle -> OutputMode
RawOutput Handle
h}
           IdeMode Integer
n Handle
_ -> IState
ist {idris_outputmode :: OutputMode
idris_outputmode = Integer -> Handle -> OutputMode
IdeMode Integer
n Handle
h}

-- | Run a command on the server on localhost
runClient :: Maybe PortNumber -> String -> IO ()
runClient :: Maybe PortNumber -> FilePath -> IO ()
runClient Maybe PortNumber
port FilePath
str = forall a. IO a -> IO a
withSocketsDo forall a b. (a -> b) -> a -> b
$ do
              let port' :: PortNumber
port' = forall a. a -> Maybe a -> a
fromMaybe PortNumber
defaultPort Maybe PortNumber
port
              Socket
s <- Family -> SocketType -> ProtocolNumber -> IO Socket
socket Family
AF_INET SocketType
Stream ProtocolNumber
defaultProtocol
              Either SomeException ()
res <- forall e a. Exception e => IO a -> IO (Either e a)
X.try (Socket -> SockAddr -> IO ()
connect Socket
s (PortNumber -> HostAddress -> SockAddr
SockAddrInet PortNumber
port' forall a b. (a -> b) -> a -> b
$ (Word8, Word8, Word8, Word8) -> HostAddress
tupleToHostAddress (Word8
127,Word8
0,Word8
0,Word8
1)))
              case Either SomeException ()
res of
                Right () -> do
                  Handle
h <- Socket -> IOMode -> IO Handle
socketToHandle Socket
s IOMode
ReadWriteMode
                  Handle -> TextEncoding -> IO ()
hSetEncoding Handle
h TextEncoding
utf8
                  Handle -> FilePath -> IO ()
hPutStrLn Handle
h FilePath
str
                  FilePath
resp <- FilePath -> Handle -> IO FilePath
hGetResp FilePath
"" Handle
h
                  FilePath -> IO ()
putStr FilePath
resp
                  Handle -> IO ()
hClose Handle
h

                Left SomeException
err -> do
                  SomeException -> IO ()
connectionError SomeException
err
                  forall a. ExitCode -> IO a
exitWith (Int -> ExitCode
ExitFailure Int
1)

    where hGetResp :: FilePath -> Handle -> IO FilePath
hGetResp FilePath
acc Handle
h = do Bool
eof <- Handle -> IO Bool
hIsEOF Handle
h
                              if Bool
eof then forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
acc
                                     else do FilePath
l <- Handle -> IO FilePath
hGetLine Handle
h
                                             FilePath -> Handle -> IO FilePath
hGetResp (FilePath
acc forall a. [a] -> [a] -> [a]
++ FilePath
l forall a. [a] -> [a] -> [a]
++ FilePath
"\n") Handle
h

          connectionError :: X.SomeException -> IO ()
          connectionError :: SomeException -> IO ()
connectionError SomeException
_ =
            FilePath -> IO ()
putStrLn FilePath
"Unable to connect to a running Idris repl"


initIdemodeSocket :: IO Handle
initIdemodeSocket :: IO Handle
initIdemodeSocket = do
  (Socket
sock, PortNumber
port) <- IO (Socket, PortNumber)
listenOnLocalhostAnyPort
  FilePath -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> FilePath
show PortNumber
port
  (Socket
s, SockAddr
_) <- Socket -> IO (Socket, SockAddr)
accept Socket
sock
  Handle
h <- Socket -> IOMode -> IO Handle
socketToHandle Socket
s IOMode
ReadWriteMode
  Handle -> TextEncoding -> IO ()
hSetEncoding Handle
h TextEncoding
utf8
  forall (m :: * -> *) a. Monad m => a -> m a
return Handle
h

-- | Run the IdeMode
idemodeStart :: Bool -> IState -> [FilePath] -> Idris ()
idemodeStart :: Bool -> IState -> [FilePath] -> Idris ()
idemodeStart Bool
s IState
orig [FilePath]
mods
  = do Handle
h <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ if Bool
s then IO Handle
initIdemodeSocket else forall (m :: * -> *) a. Monad m => a -> m a
return Handle
stdout
       Bool -> Handle -> Idris ()
setIdeMode Bool
True Handle
h
       forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ Handle -> NewlineMode -> IO ()
hSetNewlineMode Handle
h (NewlineMode { inputNL :: Newline
inputNL = Newline
CRLF, outputNL :: Newline
outputNL = Newline
LF })
       IState
i <- Idris IState
getIState
       case IState -> OutputMode
idris_outputmode IState
i of
         IdeMode Integer
n Handle
h ->
           do forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"protocol-version" Int
IdeMode.ideModeEpoch Integer
n
              case [FilePath]
mods of
                FilePath
a:[FilePath]
_ -> Handle
-> Integer
-> IState
-> FilePath
-> [FilePath]
-> IdeModeCommand
-> Idris ()
runIdeModeCommand Handle
h Integer
n IState
i FilePath
"" [] (FilePath -> Maybe Int -> IdeModeCommand
IdeMode.LoadFile FilePath
a forall a. Maybe a
Nothing)
                [FilePath]
_   -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
       Handle -> IState -> [FilePath] -> Idris ()
idemode Handle
h IState
orig [FilePath]
mods

idemode :: Handle -> IState -> [FilePath] -> Idris ()
idemode :: Handle -> IState -> [FilePath] -> Idris ()
idemode Handle
h IState
orig [FilePath]
mods
  = do forall a. Idris a -> (Err -> Idris a) -> Idris a
idrisCatch
         (do let inh :: Handle
inh = if Handle
h forall a. Eq a => a -> a -> Bool
== Handle
stdout then Handle
stdin else Handle
h
             Either Err Int
len' <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ Handle -> IO (Either Err Int)
IdeMode.getLen Handle
inh
             Int
len <- case Either Err Int
len' of
               Left Err
err -> forall a. Err -> Idris a
ierror Err
err
               Right Int
n  -> forall (m :: * -> *) a. Monad m => a -> m a
return Int
n
             FilePath
l <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ Handle -> Int -> FilePath -> IO FilePath
IdeMode.getNChar Handle
inh Int
len FilePath
""
             (SExp
sexp, Integer
id) <- case FilePath -> Either Err (SExp, Integer)
IdeMode.parseMessage FilePath
l of
                             Left Err
err -> forall a. Err -> Idris a
ierror Err
err
                             Right (SExp
sexp, Integer
id) -> forall (m :: * -> *) a. Monad m => a -> m a
return (SExp
sexp, Integer
id)
             IState
i <- Idris IState
getIState
             IState -> Idris ()
putIState forall a b. (a -> b) -> a -> b
$ IState
i { idris_outputmode :: OutputMode
idris_outputmode = (Integer -> Handle -> OutputMode
IdeMode Integer
id Handle
h) }
             forall a. Idris a -> (Err -> Idris a) -> Idris a
idrisCatch -- to report correct id back!
               (do let fn :: FilePath
fn = forall a. a -> Maybe a -> a
fromMaybe FilePath
"" (forall a. [a] -> Maybe a
listToMaybe [FilePath]
mods)
                   case SExp -> Maybe IdeModeCommand
IdeMode.sexpToCommand SExp
sexp of
                     Just IdeModeCommand
cmd -> Handle
-> Integer
-> IState
-> FilePath
-> [FilePath]
-> IdeModeCommand
-> Idris ()
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods IdeModeCommand
cmd
                     Maybe IdeModeCommand
Nothing  -> FilePath -> Idris ()
iPrintError FilePath
"did not understand" )
               (\Err
e -> do FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> FilePath
show Err
e))
         (\Err
e -> do FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> FilePath
show Err
e)
       Handle -> IState -> [FilePath] -> Idris ()
idemode Handle
h IState
orig [FilePath]
mods

-- | Run IDEMode commands
runIdeModeCommand :: Handle -- ^^ The handle for communication
                   -> Integer -- ^^ The continuation ID for the client
                   -> IState -- ^^ The original IState
                   -> FilePath -- ^^ The current open file
                   -> [FilePath] -- ^^ The currently loaded modules
                   -> IdeMode.IdeModeCommand -- ^^ The command to process
                   -> Idris ()
runIdeModeCommand :: Handle
-> Integer
-> IState
-> FilePath
-> [FilePath]
-> IdeModeCommand
-> Idris ()
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.Interpret FilePath
cmd) =
  do Bool
c <- Idris Bool
colourise
     IState
i <- Idris IState
getIState
     case IState
-> FilePath
-> FilePath
-> Either ParseError (Either FilePath Command)
parseCmd IState
i FilePath
"(input)" FilePath
cmd of
       Left ParseError
err -> FilePath -> Idris ()
iPrintError forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Show a => a -> FilePath
show forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Doc -> Doc
fixColour Bool
False forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ParseError -> Doc
parseErrorDoc forall a b. (a -> b) -> a -> b
$ ParseError
err
       Right (Right (Prove Bool
mode Name
n')) ->
         forall a. Idris a -> (Err -> Idris a) -> Idris a
idrisCatch
           (do FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Name -> Command
Prove Bool
mode Name
n')
               FilePath -> Idris ()
isetPrompt ([FilePath] -> FilePath
mkPrompt [FilePath]
mods)
               case IState -> OutputMode
idris_outputmode IState
i of
                 IdeMode Integer
n Handle
h -> -- signal completion of proof to ide
                   forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$
                     forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return"
                       (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok", FilePath
"")
                       Integer
n
                 OutputMode
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ())
           (\Err
e -> do IState
ist <- Idris IState
getIState
                     FilePath -> Idris ()
isetPrompt ([FilePath] -> FilePath
mkPrompt [FilePath]
mods)
                     case IState -> OutputMode
idris_outputmode IState
i of
                       IdeMode Integer
n Handle
h ->
                         forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$
                           forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"abandon-proof" FilePath
"Abandoned" Integer
n
                       OutputMode
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
                     Doc OutputAnnotation -> Idris ()
iRenderError forall a b. (a -> b) -> a -> b
$ IState -> Err -> Doc OutputAnnotation
pprintErr IState
ist Err
e)
       Right (Right Command
cmd) -> forall a. Idris a -> (Err -> Idris a) -> Idris a
idrisCatch
                        (FilePath -> Command -> Idris ()
idemodeProcess FilePath
fn Command
cmd)
                        (\Err
e -> Idris IState
getIState forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Doc OutputAnnotation -> Idris ()
iRenderError forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip IState -> Err -> Doc OutputAnnotation
pprintErr Err
e)
       Right (Left FilePath
err) -> FilePath -> Idris ()
iPrintError FilePath
err
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.REPLCompletions FilePath
str) =
  do (FilePath
unused, [Completion]
compls) <- CompletionFunc Idris
replCompletion (forall a. [a] -> [a]
reverse FilePath
str, FilePath
"")
     let good :: SExp
good = [SExp] -> SExp
IdeMode.SexpList [FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok",
                                   forall a. SExpable a => a -> SExp
IdeMode.toSExp (forall a b. (a -> b) -> [a] -> [b]
map Completion -> FilePath
replacement [Completion]
compls,
                                   forall a. [a] -> [a]
reverse FilePath
unused)]
     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" SExp
good Integer
id
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.LoadFile FilePath
filename Maybe Int
toline) =
  -- The $!! here prevents a space leak on reloading.
  -- This isn't a solution - but it's a temporary stopgap.
  -- See issue #2386
  do IState
i <- Idris IState
getIState
     Idris ()
clearErr
     IState -> Idris ()
putIState forall a b. NFData a => (a -> b) -> a -> b
$!! IState
orig { idris_options :: IOption
idris_options = IState -> IOption
idris_options IState
i,
                          idris_outputmode :: OutputMode
idris_outputmode = (Integer -> Handle -> OutputMode
IdeMode Integer
id Handle
h) }
     [FilePath]
mods <- [FilePath] -> Maybe Int -> Idris [FilePath]
loadInputs [FilePath
filename] Maybe Int
toline
     FilePath -> Idris ()
isetPrompt ([FilePath] -> FilePath
mkPrompt [FilePath]
mods)
     -- Report either success or failure
     IState
i <- Idris IState
getIState
     case (IState -> Maybe FC
errSpan IState
i) of
       Maybe FC
Nothing -> let msg :: SExp
msg = forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([SExp] -> SExp
IdeMode.SexpList [FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok",
                                                      [SExp] -> SExp
IdeMode.SexpList []])
                                  (\FC
fc -> [SExp] -> SExp
IdeMode.SexpList [FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok",
                                                             forall a. SExpable a => a -> SExp
IdeMode.toSExp FC
fc])
                                  (IState -> Maybe FC
idris_parsedSpan IState
i)
                  in forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" SExp
msg Integer
id
       Just FC
x -> FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ FilePath
"didn't load " forall a. [a] -> [a] -> [a]
++ FilePath
filename
     Handle -> IState -> [FilePath] -> Idris ()
idemode Handle
h IState
orig [FilePath]
mods
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.TypeOf FilePath
name) =
  case FilePath -> Either FilePath Name
splitName FilePath
name of
    Left FilePath
err -> FilePath -> Idris ()
iPrintError FilePath
err
    Right Name
n -> FilePath -> Command -> Idris ()
process FilePath
"(idemode)"
                 (PTerm -> Command
Check (FC -> [FC] -> Name -> PTerm
PRef (FilePath -> (Int, Int) -> (Int, Int) -> FC
FC FilePath
"(idemode)" (Int
0,Int
0) (Int
0,Int
0)) [] Name
n))
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.DocsFor FilePath
name WhatDocs
w) =
  case IState -> FilePath -> Either ParseError Const
parseConst IState
orig FilePath
name of
    Right Const
c -> FilePath -> Command -> Idris ()
process FilePath
"(idemode)" (Either Name Const -> HowMuchDocs -> Command
DocStr (forall a b. b -> Either a b
Right Const
c) (WhatDocs -> HowMuchDocs
howMuch WhatDocs
w))
    Left ParseError
_ ->
     case FilePath -> Either FilePath Name
splitName FilePath
name of
       Left FilePath
err -> FilePath -> Idris ()
iPrintError FilePath
err
       Right Name
n -> FilePath -> Command -> Idris ()
process FilePath
"(idemode)" (Either Name Const -> HowMuchDocs -> Command
DocStr (forall a b. a -> Either a b
Left Name
n) (WhatDocs -> HowMuchDocs
howMuch WhatDocs
w))
  where howMuch :: WhatDocs -> HowMuchDocs
howMuch WhatDocs
IdeMode.Overview = HowMuchDocs
OverviewDocs
        howMuch WhatDocs
IdeMode.Full     = HowMuchDocs
FullDocs
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.CaseSplit Int
line FilePath
name) =
  FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
CaseSplitAt Bool
False Int
line (FilePath -> Name
sUN FilePath
name))
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.AddClause Int
line FilePath
name) =
  FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
AddClauseFrom Bool
False Int
line (FilePath -> Name
sUN FilePath
name))
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.AddProofClause Int
line FilePath
name) =
  FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
AddProofClauseFrom Bool
False Int
line (FilePath -> Name
sUN FilePath
name))
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.AddMissing Int
line FilePath
name) =
  FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
AddMissing Bool
False Int
line (FilePath -> Name
sUN FilePath
name))
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.MakeWithBlock Int
line FilePath
name) =
  FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
MakeWith Bool
False Int
line (FilePath -> Name
sUN FilePath
name))
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.MakeCaseBlock Int
line FilePath
name) =
  FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
MakeCase Bool
False Int
line (FilePath -> Name
sUN FilePath
name))
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.ProofSearch Bool
r Int
line FilePath
name [FilePath]
hints Maybe Int
depth) =
  FilePath
-> Bool -> Bool -> Int -> Name -> [Name] -> Maybe Int -> Idris ()
doProofSearch FilePath
fn Bool
False Bool
r Int
line (FilePath -> Name
sUN FilePath
name) (forall a b. (a -> b) -> [a] -> [b]
map FilePath -> Name
sUN [FilePath]
hints) Maybe Int
depth
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.MakeLemma Int
line FilePath
name) =
  case FilePath -> Either FilePath Name
splitName FilePath
name of
    Left FilePath
err -> FilePath -> Idris ()
iPrintError FilePath
err
    Right Name
n -> FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
MakeLemma Bool
False Int
line Name
n)
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.Apropos FilePath
a) =
  FilePath -> Command -> Idris ()
process FilePath
fn ([PkgName] -> FilePath -> Command
Apropos [] FilePath
a)
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeModeCommand
IdeMode.GetOpts) =
  do IState
ist <- Idris IState
getIState
     let opts :: IOption
opts = IState -> IOption
idris_options IState
ist
     let impshow :: Bool
impshow = IOption -> Bool
opt_showimp IOption
opts
     let errCtxt :: Bool
errCtxt = IOption -> Bool
opt_errContext IOption
opts
     let options :: (SExp, [(SExp, Bool)])
options = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok",
                    [(FilePath -> SExp
IdeMode.SymbolAtom FilePath
"show-implicits", Bool
impshow),
                     (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"error-context", Bool
errCtxt)])
     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp, [(SExp, Bool)])
options Integer
id
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.SetOpt Opt
IdeMode.ShowImpl Bool
b) =
  do Bool -> Idris ()
setImpShow Bool
b
     let msg :: (SExp, Bool)
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok", Bool
b)
     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp, Bool)
msg Integer
id
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.SetOpt Opt
IdeMode.ErrContext Bool
b) =
  do Bool -> Idris ()
setErrContext Bool
b
     let msg :: (SExp, Bool)
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok", Bool
b)
     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp, Bool)
msg Integer
id
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.Metavariables Int
cols) =
  do IState
ist <- Idris IState
getIState
     let mvs :: [(Name, Int)]
mvs = forall a. [a] -> [a]
reverse forall a b. (a -> b) -> a -> b
$ [ (Name
n, Int
i)
                         | (Name
n, (Maybe Name
_, Int
i, [Name]
_, Bool
_, Bool
_)) <- IState -> [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
idris_metavars IState
ist
                         , Bool -> Bool
not (Name
n forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
primDefs)
                         ]
     -- splitMvs is a list of pairs of names and their split types
     let splitMvs :: [(Name, ([(Name, Term, PTerm)], Term, PTerm))]
splitMvs = [ (Name
n, ([(Name, Term, PTerm)]
premises, Term
concl, PTerm
tm))
                    | (Name
n, Int
i, Term
ty) <- IState -> [(Name, Int)] -> [(Name, Int, Term)]
mvTys IState
ist [(Name, Int)]
mvs
                    , let ([(Name, Term, PTerm)]
premises, Term
concl, PTerm
tm) = IState -> Int -> Term -> ([(Name, Term, PTerm)], Term, PTerm)
splitPi IState
ist Int
i Term
ty]
     -- mvOutput is the pretty-printed version ready for conversion to SExpr
     let mvOutput :: [(FilePath, [(FilePath, FilePath, SpanList OutputAnnotation)],
  (FilePath, SpanList OutputAnnotation))]
mvOutput = forall a b. (a -> b) -> [a] -> [b]
map (\(FilePath
n, ([(FilePath, FilePath, SpanList OutputAnnotation)]
hs, (FilePath, SpanList OutputAnnotation)
c)) -> (FilePath
n, [(FilePath, FilePath, SpanList OutputAnnotation)]
hs, (FilePath, SpanList OutputAnnotation)
c)) forall a b. (a -> b) -> a -> b
$
                    forall {b} {a} {b} {b}.
(b -> a) -> (b -> b) -> [(b, b)] -> [(a, b)]
mapPair forall a. Show a => a -> FilePath
show
                            (\([(Name, Term, PTerm)]
hs, Term
c, PTerm
pc) ->
                             let bnd :: [Name]
bnd = [ Name
n | (Name
n,Term
_,PTerm
_) <- [(Name, Term, PTerm)]
hs ] in
                             let bnds :: [[Name]]
bnds = forall a. [a] -> [[a]]
inits [Name]
bnd in
                             (forall a b. (a -> b) -> [a] -> [b]
map (\([Name]
bnd, (Name, Term, PTerm)
h) -> IState
-> [Name]
-> (Name, Term, PTerm)
-> (FilePath, FilePath, SpanList OutputAnnotation)
processPremise IState
ist [Name]
bnd (Name, Term, PTerm)
h)
                                  (forall a b. [a] -> [b] -> [(a, b)]
zip [[Name]]
bnds [(Name, Term, PTerm)]
hs),
                              IState
-> [Name] -> Term -> PTerm -> (FilePath, SpanList OutputAnnotation)
render IState
ist [Name]
bnd Term
c PTerm
pc))
                            [(Name, ([(Name, Term, PTerm)], Term, PTerm))]
splitMvs
     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$
       forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok", [(FilePath, [(FilePath, FilePath, SpanList OutputAnnotation)],
  (FilePath, SpanList OutputAnnotation))]
mvOutput) Integer
id
  where mapPair :: (b -> a) -> (b -> b) -> [(b, b)] -> [(a, b)]
mapPair b -> a
f b -> b
g [(b, b)]
xs = forall a b. [a] -> [b] -> [(a, b)]
zip (forall a b. (a -> b) -> [a] -> [b]
map (b -> a
f forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (a, b) -> a
fst) [(b, b)]
xs) (forall a b. (a -> b) -> [a] -> [b]
map (b -> b
g forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (a, b) -> b
snd) [(b, b)]
xs)
        -- | Split a function type into a pair of premises, conclusion.
        -- Each maintains both the original and delaborated versions.
        splitPi :: IState -> Int -> Type -> ([(Name, Type, PTerm)], Type, PTerm)
        splitPi :: IState -> Int -> Term -> ([(Name, Term, PTerm)], Term, PTerm)
splitPi IState
ist Int
i (Bind Name
n (Pi RigCount
_ Maybe ImplicitInfo
_ Term
t Term
_) Term
rest) | Int
i forall a. Ord a => a -> a -> Bool
> Int
0 =
          let ([(Name, Term, PTerm)]
hs, Term
c, PTerm
_) = IState -> Int -> Term -> ([(Name, Term, PTerm)], Term, PTerm)
splitPi IState
ist (Int
i forall a. Num a => a -> a -> a
- Int
1) Term
rest in
            ((Name
n, Term
t, IState
-> [PArg]
-> [(Name, Term)]
-> Term
-> Bool
-> Bool
-> Bool
-> PTerm
delabTy' IState
ist [] [] Term
t Bool
False Bool
False Bool
True)forall a. a -> [a] -> [a]
:[(Name, Term, PTerm)]
hs,
             Term
c, IState
-> [PArg]
-> [(Name, Term)]
-> Term
-> Bool
-> Bool
-> Bool
-> PTerm
delabTy' IState
ist [] [] Term
c Bool
False Bool
False Bool
True)
        splitPi IState
ist Int
i Term
tm = ([], Term
tm, IState
-> [PArg]
-> [(Name, Term)]
-> Term
-> Bool
-> Bool
-> Bool
-> PTerm
delabTy' IState
ist [] [] Term
tm Bool
False Bool
False Bool
True)

        -- | Get the types of a list of metavariable names
        mvTys :: IState -> [(Name, Int)] -> [(Name, Int, Type)]
        mvTys :: IState -> [(Name, Int)] -> [(Name, Int, Term)]
mvTys IState
ist [(Name, Int)]
mvs = [ (Name
n, Int
i, Term
ty)
                        | (Name
n, Int
i) <- [(Name, Int)]
mvs
                        , Term
ty <- forall a. Maybe a -> [a]
maybeToList (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall n. TT n -> TT n
vToP forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (a, b) -> b
snd) (Name -> Context -> Maybe (Name, Term)
lookupTyNameExact Name
n (IState -> Context
tt_ctxt IState
ist)))
                        ]

        -- | Show a type and its corresponding PTerm in a format suitable
        -- for the IDE - that is, pretty-printed and annotated.
        render :: IState -> [Name] -> Type -> PTerm -> (String, SpanList OutputAnnotation)
        render :: IState
-> [Name] -> Term -> PTerm -> (FilePath, SpanList OutputAnnotation)
render IState
ist [Name]
bnd Term
t PTerm
pt =
          let prettyT :: Doc OutputAnnotation
prettyT = PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm (IState -> PPOption
ppOptionIst IState
ist)
                                    (forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
bnd (forall a. a -> [a]
repeat Bool
False))
                                    []
                                    (IState -> [FixDecl]
idris_infixes IState
ist)
                                    PTerm
pt
          in
            forall a. SimpleDoc a -> (FilePath, SpanList a)
displaySpans forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
            forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
0.9 Int
cols forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IState -> Bool -> OutputAnnotation -> OutputAnnotation
fancifyAnnots IState
ist Bool
True) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
            forall a. a -> Doc a -> Doc a
annotate ([(Name, Bool)] -> Term -> OutputAnnotation
AnnTerm (forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
bnd (forall a. Int -> [a] -> [a]
take (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Name]
bnd) (forall a. a -> [a]
repeat Bool
False))) Term
t) forall a b. (a -> b) -> a -> b
$
              Doc OutputAnnotation
prettyT

        -- | Juggle the bits of a premise to prepare for output.
        processPremise :: IState
                       -> [Name] -- ^ the names to highlight as bound
                       -> (Name, Type, PTerm)
                       -> (String,
                           String,
                           SpanList OutputAnnotation)
        processPremise :: IState
-> [Name]
-> (Name, Term, PTerm)
-> (FilePath, FilePath, SpanList OutputAnnotation)
processPremise IState
ist [Name]
bnd (Name
n, Term
t, PTerm
pt) =
          let (FilePath
out, SpanList OutputAnnotation
spans) = IState
-> [Name] -> Term -> PTerm -> (FilePath, SpanList OutputAnnotation)
render IState
ist [Name]
bnd Term
t PTerm
pt in
          (forall a. Show a => a -> FilePath
show Name
n , FilePath
out, SpanList OutputAnnotation
spans)

runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.WhoCalls FilePath
n) =
  case FilePath -> Either FilePath Name
splitName FilePath
n of
       Left FilePath
err -> FilePath -> Idris ()
iPrintError FilePath
err
       Right Name
n -> do [(Name, [Name])]
calls <- Name -> Idris [(Name, [Name])]
whoCalls Name
n
                     IState
ist <- Idris IState
getIState
                     let msg :: (SExp,
 [((FilePath, SpanList OutputAnnotation),
   [(FilePath, SpanList OutputAnnotation)])])
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok",
                                forall a b. (a -> b) -> [a] -> [b]
map (\ (Name
n,[Name]
ns) -> (IState -> Name -> (FilePath, SpanList OutputAnnotation)
pn IState
ist Name
n, forall a b. (a -> b) -> [a] -> [b]
map (IState -> Name -> (FilePath, SpanList OutputAnnotation)
pn IState
ist) [Name]
ns)) [(Name, [Name])]
calls)
                     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp,
 [((FilePath, SpanList OutputAnnotation),
   [(FilePath, SpanList OutputAnnotation)])])
msg Integer
id
  where pn :: IState -> Name -> (FilePath, SpanList OutputAnnotation)
pn IState
ist = forall a. SimpleDoc a -> (FilePath, SpanList a)
displaySpans forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                 forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
0.9 Int
1000 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IState -> Bool -> OutputAnnotation -> OutputAnnotation
fancifyAnnots IState
ist Bool
True) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                 Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
True []

runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.CallsWho FilePath
n) =
  case FilePath -> Either FilePath Name
splitName FilePath
n of
       Left FilePath
err -> FilePath -> Idris ()
iPrintError FilePath
err
       Right Name
n -> do [(Name, [Name])]
calls <- Name -> Idris [(Name, [Name])]
callsWho Name
n
                     IState
ist <- Idris IState
getIState
                     let msg :: (SExp,
 [((FilePath, SpanList OutputAnnotation),
   [(FilePath, SpanList OutputAnnotation)])])
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok",
                                forall a b. (a -> b) -> [a] -> [b]
map (\ (Name
n,[Name]
ns) -> (IState -> Name -> (FilePath, SpanList OutputAnnotation)
pn IState
ist Name
n, forall a b. (a -> b) -> [a] -> [b]
map (IState -> Name -> (FilePath, SpanList OutputAnnotation)
pn IState
ist) [Name]
ns)) [(Name, [Name])]
calls)
                     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp,
 [((FilePath, SpanList OutputAnnotation),
   [(FilePath, SpanList OutputAnnotation)])])
msg Integer
id
  where pn :: IState -> Name -> (FilePath, SpanList OutputAnnotation)
pn IState
ist = forall a. SimpleDoc a -> (FilePath, SpanList a)
displaySpans forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                 forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
0.9 Int
1000 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IState -> Bool -> OutputAnnotation -> OutputAnnotation
fancifyAnnots IState
ist Bool
True) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                 Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
True []

runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
modes (IdeMode.BrowseNS FilePath
ns) =
  case forall a. Eq a => [a] -> [a] -> [[a]]
splitOn FilePath
"." FilePath
ns of
    [] -> FilePath -> Idris ()
iPrintError FilePath
"No namespace provided"
    [FilePath]
ns -> do [FilePath]
underNSs <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. a -> [a] -> [a]
intersperse FilePath
".") forall a b. (a -> b) -> a -> b
$ [FilePath] -> Idris [[FilePath]]
namespacesInNS [FilePath]
ns
             [Name]
names <- [FilePath] -> Idris [Name]
namesInNS [FilePath]
ns
             if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FilePath]
underNSs Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Name]
names
                then FilePath -> Idris ()
iPrintError FilePath
"Invalid or empty namespace"
                else do IState
ist <- Idris IState
getIState
                        [(FilePath, SpanList OutputAnnotation)]
underNs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Name
-> StateT
     IState (ExceptT Err IO) (FilePath, SpanList OutputAnnotation)
pn [Name]
names
                        let msg :: (SExp, ([FilePath], [(FilePath, SpanList OutputAnnotation)]))
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok", ([FilePath]
underNSs, [(FilePath, SpanList OutputAnnotation)]
underNs))
                        forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp, ([FilePath], [(FilePath, SpanList OutputAnnotation)]))
msg Integer
id
  where pn :: Name
-> StateT
     IState (ExceptT Err IO) (FilePath, SpanList OutputAnnotation)
pn Name
n =
          do Context
ctxt <- Idris Context
getContext
             IState
ist <- Idris IState
getIState
             forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
               forall a. SimpleDoc a -> (FilePath, SpanList a)
displaySpans forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
               forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
0.9 Int
1000 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
               forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IState -> Bool -> OutputAnnotation -> OutputAnnotation
fancifyAnnots IState
ist Bool
True) forall a b. (a -> b) -> a -> b
$
                 Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
False [] Name
n forall a. Doc a -> Doc a -> Doc a
<>
                 case Name -> Context -> Maybe Term
lookupTyExact Name
n Context
ctxt of
                   Just Term
t ->
                     forall a. Doc a
space forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
colon forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
space forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a -> Doc a
align (forall a. Doc a -> Doc a
group (IState -> Name -> Term -> Doc OutputAnnotation
pprintDelabTy' IState
ist Name
n Term
t))
                   Maybe Term
Nothing ->
                     forall a. Doc a
empty

runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
modes (IdeMode.TermNormalise [(Name, Bool)]
bnd Term
tm) =
  do Context
ctxt <- Idris Context
getContext
     IState
ist <- Idris IState
getIState
     let tm' :: Term
tm' = Context -> Env -> Term -> Term
normaliseAll Context
ctxt [] Term
tm
         ptm :: Doc OutputAnnotation
ptm = forall a. a -> Doc a -> Doc a
annotate ([(Name, Bool)] -> Term -> OutputAnnotation
AnnTerm [(Name, Bool)]
bnd Term
tm')
               (PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm (IState -> PPOption
ppOptionIst IState
ist)
                            [(Name, Bool)]
bnd
                            []
                            (IState -> [FixDecl]
idris_infixes IState
ist)
                            (IState -> Term -> PTerm
delab IState
ist Term
tm'))
         msg :: (SExp, (FilePath, SpanList OutputAnnotation))
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok",
                forall a. SimpleDoc a -> (FilePath, SpanList a)
displaySpans forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
0.9 Int
80 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IState -> Bool -> OutputAnnotation -> OutputAnnotation
fancifyAnnots IState
ist Bool
True) forall a b. (a -> b) -> a -> b
$ Doc OutputAnnotation
ptm)
     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp, (FilePath, SpanList OutputAnnotation))
msg Integer
id
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
modes (IdeMode.TermShowImplicits [(Name, Bool)]
bnd Term
tm) =
  Handle -> Integer -> [(Name, Bool)] -> Bool -> Term -> Idris ()
ideModeForceTermImplicits Handle
h Integer
id [(Name, Bool)]
bnd Bool
True Term
tm
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
modes (IdeMode.TermNoImplicits [(Name, Bool)]
bnd Term
tm) =
  Handle -> Integer -> [(Name, Bool)] -> Bool -> Term -> Idris ()
ideModeForceTermImplicits Handle
h Integer
id [(Name, Bool)]
bnd Bool
False Term
tm
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
modes (IdeMode.TermElab [(Name, Bool)]
bnd Term
tm) =
  do IState
ist <- Idris IState
getIState
     let ptm :: Doc OutputAnnotation
ptm = forall a. a -> Doc a -> Doc a
annotate ([(Name, Bool)] -> Term -> OutputAnnotation
AnnTerm [(Name, Bool)]
bnd Term
tm)
                 ([Name] -> Term -> Doc OutputAnnotation
pprintTT (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(Name, Bool)]
bnd) Term
tm)
         msg :: (SExp, (FilePath, SpanList OutputAnnotation))
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok",
                forall a. SimpleDoc a -> (FilePath, SpanList a)
displaySpans forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
0.9 Int
70 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IState -> Bool -> OutputAnnotation -> OutputAnnotation
fancifyAnnots IState
ist Bool
True) forall a b. (a -> b) -> a -> b
$ Doc OutputAnnotation
ptm)
     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp, (FilePath, SpanList OutputAnnotation))
msg Integer
id
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
mods (IdeMode.PrintDef FilePath
name) =
  case FilePath -> Either FilePath Name
splitName FilePath
name of
    Left FilePath
err -> FilePath -> Idris ()
iPrintError FilePath
err
    Right Name
n -> FilePath -> Command -> Idris ()
process FilePath
"(idemode)" (Name -> Command
PrintDef Name
n)
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
modes (IdeMode.ErrString Err
e) =
  do IState
ist <- Idris IState
getIState
     let out :: FilePath -> FilePath
out = forall a. SimpleDoc a -> FilePath -> FilePath
displayS forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
1.0 Int
60 forall a b. (a -> b) -> a -> b
$ IState -> Err -> Doc OutputAnnotation
pprintErr IState
ist Err
e
         msg :: (SExp, SExp)
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok", FilePath -> SExp
IdeMode.StringAtom forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath
out FilePath
"")
     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp, SExp)
msg Integer
id
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
modes (IdeMode.ErrPPrint Err
e) =
  do IState
ist <- Idris IState
getIState
     let (FilePath
out, SpanList OutputAnnotation
spans) =
           forall a. SimpleDoc a -> (FilePath, SpanList a)
displaySpans forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
           forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
0.9 Int
80 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
           forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IState -> Bool -> OutputAnnotation -> OutputAnnotation
fancifyAnnots IState
ist Bool
True) forall a b. (a -> b) -> a -> b
$ IState -> Err -> Doc OutputAnnotation
pprintErr IState
ist Err
e
         msg :: (SExp, FilePath, SpanList OutputAnnotation)
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok", FilePath
out, SpanList OutputAnnotation
spans)
     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp, FilePath, SpanList OutputAnnotation)
msg Integer
id
runIdeModeCommand Handle
h Integer
id IState
orig FilePath
fn [FilePath]
modes IdeModeCommand
IdeMode.GetIdrisVersion =
  let idrisVersion :: ([Int], [FilePath])
idrisVersion = (Version -> [Int]
versionBranch Version
getIdrisVersionNoGit,
                      if Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null FilePath
gitHash)
                        then [FilePath
gitHash]
                        else [])
      msg :: (SExp, ([Int], [FilePath]))
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok", ([Int], [FilePath])
idrisVersion)
  in forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp, ([Int], [FilePath]))
msg Integer
id


-- | Show a term for IDEMode with the specified implicitness
ideModeForceTermImplicits :: Handle -> Integer -> [(Name, Bool)] -> Bool -> Term -> Idris ()
ideModeForceTermImplicits :: Handle -> Integer -> [(Name, Bool)] -> Bool -> Term -> Idris ()
ideModeForceTermImplicits Handle
h Integer
id [(Name, Bool)]
bnd Bool
impl Term
tm =
  do IState
ist <- Idris IState
getIState
     let expl :: Doc OutputAnnotation
expl = forall a. a -> Doc a -> Doc a
annotate ([(Name, Bool)] -> Term -> OutputAnnotation
AnnTerm [(Name, Bool)]
bnd Term
tm)
                (PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm ((IState -> PPOption
ppOptionIst IState
ist) { ppopt_impl :: Bool
ppopt_impl = Bool
impl })
                             [(Name, Bool)]
bnd [] (IState -> [FixDecl]
idris_infixes IState
ist)
                             (IState -> Term -> PTerm
delab IState
ist Term
tm))
         msg :: (SExp, (FilePath, SpanList OutputAnnotation))
msg = (FilePath -> SExp
IdeMode.SymbolAtom FilePath
"ok",
                forall a. SimpleDoc a -> (FilePath, SpanList a)
displaySpans forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                forall a. Float -> Int -> Doc a -> SimpleDoc a
renderPretty Float
0.9 Int
80 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IState -> Bool -> OutputAnnotation -> OutputAnnotation
fancifyAnnots IState
ist Bool
True) forall a b. (a -> b) -> a -> b
$ Doc OutputAnnotation
expl)
     forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$ forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"return" (SExp, (FilePath, SpanList OutputAnnotation))
msg Integer
id

splitName :: String -> Either String Name
splitName :: FilePath -> Either FilePath Name
splitName FilePath
s | FilePath
"{{{{{" forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` FilePath
s =
              forall {b}. Binary b => FilePath -> Either FilePath b
decode forall a b. (a -> b) -> a -> b
$ forall a. Int -> [a] -> [a]
drop Int
5 forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
reverse forall a b. (a -> b) -> a -> b
$ forall a. Int -> [a] -> [a]
drop Int
5 forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
reverse FilePath
s
  where decode :: FilePath -> Either FilePath b
decode FilePath
x =
          case ByteString -> Either FilePath ByteString
Base64.decode (FilePath -> ByteString
UTF8.fromString FilePath
x) of
            Left FilePath
err -> forall a b. a -> Either a b
Left FilePath
err
            Right ByteString
ok ->
              case forall a.
Binary a =>
ByteString
-> Either
     (ByteString, ByteOffset, FilePath) (ByteString, ByteOffset, a)
Binary.decodeOrFail (ByteString -> ByteString
Lazy.fromStrict ByteString
ok) of
                Left (ByteString, ByteOffset, FilePath)
_ -> forall a b. a -> Either a b
Left FilePath
"Bad binary instance for Name"
                Right (ByteString
_, ByteOffset
_, b
n) -> forall a b. b -> Either a b
Right b
n

splitName FilePath
s = case forall a. [a] -> [a]
reverse forall a b. (a -> b) -> a -> b
$ forall a. Eq a => [a] -> [a] -> [[a]]
splitOn FilePath
"." FilePath
s of
                [] -> forall a b. a -> Either a b
Left (FilePath
"Didn't understand name '" forall a. [a] -> [a] -> [a]
++ FilePath
s forall a. [a] -> [a] -> [a]
++ FilePath
"'")
                [FilePath
n] -> forall a b. b -> Either a b
Right forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> Name
sUN forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath
unparen FilePath
n
                (FilePath
n:[FilePath]
ns) -> forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ Name -> [FilePath] -> Name
sNS (FilePath -> Name
sUN (FilePath -> FilePath
unparen FilePath
n)) [FilePath]
ns
  where unparen :: FilePath -> FilePath
unparen FilePath
"" = FilePath
""
        unparen (Char
'(':Char
x:FilePath
xs) | forall a. [a] -> a
last FilePath
xs forall a. Eq a => a -> a -> Bool
== Char
')' = forall a. [a] -> [a]
init (Char
xforall a. a -> [a] -> [a]
:FilePath
xs)
        unparen FilePath
str = FilePath
str

idemodeProcess :: FilePath -> Command -> Idris ()
idemodeProcess :: FilePath -> Command -> Idris ()
idemodeProcess FilePath
fn Command
ShowVersion = FilePath -> Command -> Idris ()
process FilePath
fn Command
ShowVersion
idemodeProcess FilePath
fn Command
Warranty = FilePath -> Command -> Idris ()
process FilePath
fn Command
Warranty
idemodeProcess FilePath
fn Command
Help = FilePath -> Command -> Idris ()
process FilePath
fn Command
Help
idemodeProcess FilePath
fn (RunShellCommand FilePath
cmd) =
  FilePath -> Idris ()
iPrintError FilePath
":! is not currently supported in IDE mode."
idemodeProcess FilePath
fn (ChangeDirectory FilePath
f) =
  do FilePath -> Command -> Idris ()
process FilePath
fn (FilePath -> Command
ChangeDirectory FilePath
f)
     FilePath
dir <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ IO FilePath
getCurrentDirectory
     FilePath -> Idris ()
iPrintResult forall a b. (a -> b) -> a -> b
$ FilePath
"changed directory to " forall a. [a] -> [a] -> [a]
++ FilePath
dir
idemodeProcess FilePath
fn (ModImport FilePath
f) = FilePath -> Command -> Idris ()
process FilePath
fn (FilePath -> Command
ModImport FilePath
f)
idemodeProcess FilePath
fn (Eval PTerm
t) = FilePath -> Command -> Idris ()
process FilePath
fn (PTerm -> Command
Eval PTerm
t)
idemodeProcess FilePath
fn (NewDefn [PDecl]
decls) = do FilePath -> Command -> Idris ()
process FilePath
fn ([PDecl] -> Command
NewDefn [PDecl]
decls)
                                       FilePath -> Idris ()
iPrintResult FilePath
"defined"
idemodeProcess FilePath
fn (Undefine [Name]
n) = FilePath -> Command -> Idris ()
process FilePath
fn ([Name] -> Command
Undefine [Name]
n)
idemodeProcess FilePath
fn (ExecVal PTerm
t) = FilePath -> Command -> Idris ()
process FilePath
fn (PTerm -> Command
ExecVal PTerm
t)
idemodeProcess FilePath
fn (Check (PRef FC
x [FC]
hls Name
n)) = FilePath -> Command -> Idris ()
process FilePath
fn (PTerm -> Command
Check (FC -> [FC] -> Name -> PTerm
PRef FC
x [FC]
hls Name
n))
idemodeProcess FilePath
fn (Check PTerm
t) = FilePath -> Command -> Idris ()
process FilePath
fn (PTerm -> Command
Check PTerm
t)
idemodeProcess FilePath
fn (Core PTerm
t) = FilePath -> Command -> Idris ()
process FilePath
fn (PTerm -> Command
Core PTerm
t)
idemodeProcess FilePath
fn (DocStr Either Name Const
n HowMuchDocs
w) = FilePath -> Command -> Idris ()
process FilePath
fn (Either Name Const -> HowMuchDocs -> Command
DocStr Either Name Const
n HowMuchDocs
w)
idemodeProcess FilePath
fn Command
Universes = FilePath -> Command -> Idris ()
process FilePath
fn Command
Universes
idemodeProcess FilePath
fn (Defn Name
n) = do FilePath -> Command -> Idris ()
process FilePath
fn (Name -> Command
Defn Name
n)
                                FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (TotCheck Name
n) = FilePath -> Command -> Idris ()
process FilePath
fn (Name -> Command
TotCheck Name
n)
idemodeProcess FilePath
fn (DebugInfo Name
n) = do FilePath -> Command -> Idris ()
process FilePath
fn (Name -> Command
DebugInfo Name
n)
                                     FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (Search [PkgName]
ps PTerm
t) = FilePath -> Command -> Idris ()
process FilePath
fn ([PkgName] -> PTerm -> Command
Search [PkgName]
ps PTerm
t)
idemodeProcess FilePath
fn (Spec PTerm
t) = FilePath -> Command -> Idris ()
process FilePath
fn (PTerm -> Command
Spec PTerm
t)
-- RmProof and AddProof not supported!
idemodeProcess FilePath
fn (ShowProof Name
n') = FilePath -> Command -> Idris ()
process FilePath
fn (Name -> Command
ShowProof Name
n')
idemodeProcess FilePath
fn (WHNF PTerm
t) = FilePath -> Command -> Idris ()
process FilePath
fn (PTerm -> Command
WHNF PTerm
t)
--idemodeProcess fn TTShell = process fn TTShell -- need some prove mode!
idemodeProcess FilePath
fn (TestInline PTerm
t) = FilePath -> Command -> Idris ()
process FilePath
fn (PTerm -> Command
TestInline PTerm
t)

idemodeProcess FilePath
fn (Execute PTerm
t) = do FilePath -> Command -> Idris ()
process FilePath
fn (PTerm -> Command
Execute PTerm
t)
                                   FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (Compile Codegen
codegen FilePath
f) = do FilePath -> Command -> Idris ()
process FilePath
fn (Codegen -> FilePath -> Command
Compile Codegen
codegen FilePath
f)
                                           FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (LogLvl Int
i) = do FilePath -> Command -> Idris ()
process FilePath
fn (Int -> Command
LogLvl Int
i)
                                  FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (Pattelab PTerm
t) = FilePath -> Command -> Idris ()
process FilePath
fn (PTerm -> Command
Pattelab PTerm
t)
idemodeProcess FilePath
fn (Missing Name
n) = FilePath -> Command -> Idris ()
process FilePath
fn (Name -> Command
Missing Name
n)
idemodeProcess FilePath
fn (DynamicLink FilePath
l) = do FilePath -> Command -> Idris ()
process FilePath
fn (FilePath -> Command
DynamicLink FilePath
l)
                                       FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn Command
ListDynamic = do FilePath -> Command -> Idris ()
process FilePath
fn Command
ListDynamic
                                   FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn Command
Metavars = FilePath -> Command -> Idris ()
process FilePath
fn Command
Metavars
idemodeProcess FilePath
fn (SetOpt Opt
ErrContext) = do FilePath -> Command -> Idris ()
process FilePath
fn (Opt -> Command
SetOpt Opt
ErrContext)
                                           FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (UnsetOpt Opt
ErrContext) = do FilePath -> Command -> Idris ()
process FilePath
fn (Opt -> Command
UnsetOpt Opt
ErrContext)
                                             FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (SetOpt Opt
ShowImpl) = do FilePath -> Command -> Idris ()
process FilePath
fn (Opt -> Command
SetOpt Opt
ShowImpl)
                                         FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (UnsetOpt Opt
ShowImpl) = do FilePath -> Command -> Idris ()
process FilePath
fn (Opt -> Command
UnsetOpt Opt
ShowImpl)
                                           FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (SetOpt Opt
ShowOrigErr) = do FilePath -> Command -> Idris ()
process FilePath
fn (Opt -> Command
SetOpt Opt
ShowOrigErr)
                                            FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (UnsetOpt Opt
ShowOrigErr) = do FilePath -> Command -> Idris ()
process FilePath
fn (Opt -> Command
UnsetOpt Opt
ShowOrigErr)
                                              FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (SetOpt Opt
x) = FilePath -> Command -> Idris ()
process FilePath
fn (Opt -> Command
SetOpt Opt
x)
idemodeProcess FilePath
fn (UnsetOpt Opt
x) = FilePath -> Command -> Idris ()
process FilePath
fn (Opt -> Command
UnsetOpt Opt
x)
idemodeProcess FilePath
fn (CaseSplitAt Bool
False Int
pos Name
str) = FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
CaseSplitAt Bool
False Int
pos Name
str)
idemodeProcess FilePath
fn (AddProofClauseFrom Bool
False Int
pos Name
str) = FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
AddProofClauseFrom Bool
False Int
pos Name
str)
idemodeProcess FilePath
fn (AddClauseFrom Bool
False Int
pos Name
str) = FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
AddClauseFrom Bool
False Int
pos Name
str)
idemodeProcess FilePath
fn (AddMissing Bool
False Int
pos Name
str) = FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
AddMissing Bool
False Int
pos Name
str)
idemodeProcess FilePath
fn (MakeWith Bool
False Int
pos Name
str) = FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
MakeWith Bool
False Int
pos Name
str)
idemodeProcess FilePath
fn (MakeCase Bool
False Int
pos Name
str) = FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Int -> Name -> Command
MakeCase Bool
False Int
pos Name
str)
idemodeProcess FilePath
fn (DoProofSearch Bool
False Bool
r Int
pos Name
str [Name]
xs) = FilePath -> Command -> Idris ()
process FilePath
fn (Bool -> Bool -> Int -> Name -> [Name] -> Command
DoProofSearch Bool
False Bool
r Int
pos Name
str [Name]
xs)
idemodeProcess FilePath
fn (SetConsoleWidth ConsoleWidth
w) = do FilePath -> Command -> Idris ()
process FilePath
fn (ConsoleWidth -> Command
SetConsoleWidth ConsoleWidth
w)
                                           FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (SetPrinterDepth Maybe Int
d) = do FilePath -> Command -> Idris ()
process FilePath
fn (Maybe Int -> Command
SetPrinterDepth Maybe Int
d)
                                           FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (Apropos [PkgName]
pkg FilePath
a) = do FilePath -> Command -> Idris ()
process FilePath
fn ([PkgName] -> FilePath -> Command
Apropos [PkgName]
pkg FilePath
a)
                                       FilePath -> Idris ()
iPrintResult FilePath
""
idemodeProcess FilePath
fn (Browse [FilePath]
ns) = FilePath -> Command -> Idris ()
process FilePath
fn ([FilePath] -> Command
Browse [FilePath]
ns)
idemodeProcess FilePath
fn (WhoCalls Name
n) = FilePath -> Command -> Idris ()
process FilePath
fn (Name -> Command
WhoCalls Name
n)
idemodeProcess FilePath
fn (CallsWho Name
n) = FilePath -> Command -> Idris ()
process FilePath
fn (Name -> Command
CallsWho Name
n)
idemodeProcess FilePath
fn (PrintDef Name
n) = FilePath -> Command -> Idris ()
process FilePath
fn (Name -> Command
PrintDef Name
n)
idemodeProcess FilePath
fn (PPrint OutputFmt
fmt Int
n PTerm
tm) = FilePath -> Command -> Idris ()
process FilePath
fn (OutputFmt -> Int -> PTerm -> Command
PPrint OutputFmt
fmt Int
n PTerm
tm)
idemodeProcess FilePath
fn Command
_ = FilePath -> Idris ()
iPrintError FilePath
"command not recognized or not supported"


-- | The prompt consists of the currently loaded modules, or "Idris" if there are none
mkPrompt :: [FilePath] -> FilePath
mkPrompt [] = FilePath
"Idris"
mkPrompt [FilePath
x] = FilePath
"*" forall a. [a] -> [a] -> [a]
++ FilePath -> FilePath
dropExtension FilePath
x
mkPrompt (FilePath
x:[FilePath]
xs) = FilePath
"*" forall a. [a] -> [a] -> [a]
++ FilePath -> FilePath
dropExtension FilePath
x forall a. [a] -> [a] -> [a]
++ FilePath
" " forall a. [a] -> [a] -> [a]
++ [FilePath] -> FilePath
mkPrompt [FilePath]
xs

-- | Determine whether a file uses literate syntax
lit :: FilePath -> Bool
lit FilePath
f = case FilePath -> (FilePath, FilePath)
splitExtension FilePath
f of
            (FilePath
_, FilePath
".lidr") -> Bool
True
            (FilePath, FilePath)
_ -> Bool
False

reload :: IState -> [FilePath] -> Idris (Maybe [FilePath])
reload :: IState -> [FilePath] -> Idris (Maybe [FilePath])
reload IState
orig [FilePath]
inputs = do
  IState
i <- Idris IState
getIState
  -- The $!! here prevents a space leak on reloading.
  -- This isn't a solution - but it's a temporary stopgap.
  -- See issue #2386
  IState -> Idris ()
putIState forall a b. NFData a => (a -> b) -> a -> b
$!! IState
orig { idris_options :: IOption
idris_options = IState -> IOption
idris_options IState
i
    , idris_colourTheme :: ColourTheme
idris_colourTheme = IState -> ColourTheme
idris_colourTheme IState
i
    , imported :: [FilePath]
imported = IState -> [FilePath]
imported IState
i
  }
  Idris ()
clearErr
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ [FilePath] -> Maybe Int -> Idris [FilePath]
loadInputs [FilePath]
inputs forall a. Maybe a
Nothing

watch :: IState -> [FilePath] -> Idris (Maybe [FilePath])
watch :: IState -> [FilePath] -> Idris (Maybe [FilePath])
watch IState
orig [FilePath]
inputs = do
  Either FilePath FilePath
resp <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ do
    let dirs :: [FilePath]
dirs = forall a. Eq a => [a] -> [a]
nub forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map FilePath -> FilePath
takeDirectory [FilePath]
inputs
    Set FilePath
inputSet <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Ord a => [a] -> Set a
S.fromList forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM FilePath -> IO FilePath
canonicalizePath [FilePath]
inputs
    MVar FilePath
signal <- forall a. IO (MVar a)
newEmptyMVar
    forall a. (WatchManager -> IO a) -> IO a
withManager forall a b. (a -> b) -> a -> b
$ \WatchManager
mgr -> do
      forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [FilePath]
dirs forall a b. (a -> b) -> a -> b
$ \FilePath
dir ->
        WatchManager -> FilePath -> ActionPredicate -> Action -> IO (IO ())
watchDir WatchManager
mgr FilePath
dir ((FilePath -> Bool) -> ActionPredicate
allEvents forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Ord a => a -> Set a -> Bool
S.member Set FilePath
inputSet) (forall (m :: * -> *).
Monad m =>
(FilePath -> m ()) -> Event -> m ()
doAllEvents forall a b. (a -> b) -> a -> b
$ forall a. MVar a -> a -> IO ()
putMVar MVar FilePath
signal)
      forall a b. IO a -> IO b -> IO (Either a b)
race IO FilePath
getLine (forall a. MVar a -> IO a
takeMVar MVar FilePath
signal)
  case Either FilePath FilePath
resp of
    Left FilePath
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just [FilePath]
inputs) -- canceled, so nop
    Right FilePath
_ -> IState -> [FilePath] -> Idris (Maybe [FilePath])
reload IState
orig [FilePath]
inputs forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IState -> [FilePath] -> Idris (Maybe [FilePath])
watch IState
orig [FilePath]
inputs

processInput :: String ->
                IState -> [FilePath] -> FilePath -> Idris (Maybe [FilePath])
processInput :: FilePath
-> IState -> [FilePath] -> FilePath -> Idris (Maybe [FilePath])
processInput FilePath
cmd IState
orig [FilePath]
inputs FilePath
efile
    = do IState
i <- Idris IState
getIState
         let opts :: IOption
opts = IState -> IOption
idris_options IState
i
         let quiet :: Bool
quiet = IOption -> Bool
opt_quiet IOption
opts
         let fn :: FilePath
fn = forall a. a -> Maybe a -> a
fromMaybe FilePath
"" (forall a. [a] -> Maybe a
listToMaybe [FilePath]
inputs)
         case IState
-> FilePath
-> FilePath
-> Either ParseError (Either FilePath Command)
parseCmd IState
i FilePath
"(input)" FilePath
cmd of
            Left ParseError
err -> forall a. a -> Maybe a
Just [FilePath]
inputs forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall w. Message w => w -> Idris ()
emitWarning ParseError
err
            Right (Right Command
Reload) ->
                IState -> [FilePath] -> Idris (Maybe [FilePath])
reload IState
orig [FilePath]
inputs
            Right (Right Command
Watch) ->
                if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FilePath]
inputs then
                  do FilePath -> Idris ()
iputStrLn FilePath
"No loaded files to watch."
                     forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just [FilePath]
inputs)
                else
                  do FilePath -> Idris ()
iputStrLn FilePath
efile
                     FilePath -> Idris ()
iputStrLn forall a b. (a -> b) -> a -> b
$ FilePath
"Watching for .idr changes in " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show [FilePath]
inputs forall a. [a] -> [a] -> [a]
++ FilePath
", press enter to cancel."
                     IState -> [FilePath] -> Idris (Maybe [FilePath])
watch IState
orig [FilePath]
inputs
            Right (Right (Load FilePath
f Maybe Int
toline)) ->
                -- The $!! here prevents a space leak on reloading.
                -- This isn't a solution - but it's a temporary stopgap.
                -- See issue #2386
                do IState -> Idris ()
putIState forall a b. NFData a => (a -> b) -> a -> b
$!! IState
orig { idris_options :: IOption
idris_options = IState -> IOption
idris_options IState
i
                                      , idris_colourTheme :: ColourTheme
idris_colourTheme = IState -> ColourTheme
idris_colourTheme IState
i
                                      }
                   Idris ()
clearErr
                   [FilePath]
mod <- [FilePath] -> Maybe Int -> Idris [FilePath]
loadInputs [FilePath
f] Maybe Int
toline
                   forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just [FilePath]
mod)
            Right (Right (ModImport FilePath
f)) ->
                do Idris ()
clearErr
                   Maybe FilePath
fmod <- FilePath -> IBCPhase -> Idris (Maybe FilePath)
loadModule FilePath
f (Bool -> IBCPhase
IBC_REPL Bool
True)
                   forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just ([FilePath]
inputs forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (forall a. a -> [a] -> [a]
:[]) Maybe FilePath
fmod))
            Right (Right Command
Edit) -> do -- takeMVar stvar
                               FilePath -> IState -> Idris ()
edit FilePath
efile IState
orig
                               forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just [FilePath]
inputs)
            Right (Right Command
Proofs) -> forall a. a -> Maybe a
Just [FilePath]
inputs forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IState -> Idris ()
proofs IState
orig
            Right (Right Command
Quit) -> forall a. Maybe a
Nothing forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not Bool
quiet) (FilePath -> Idris ()
iputStrLn FilePath
"Bye bye")
            Right (Right Command
cmd ) -> do forall a. Idris a -> (Err -> Idris a) -> Idris a
idrisCatch (FilePath -> Command -> Idris ()
process FilePath
fn Command
cmd)
                                            (\Err
e -> do FilePath
msg <- Err -> Idris FilePath
showErr Err
e ; FilePath -> Idris ()
iputStrLn FilePath
msg)
                                     forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just [FilePath]
inputs)
            Right (Left FilePath
err) -> do forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO ()
putStrLn FilePath
err
                                   forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just [FilePath]
inputs)

resolveProof :: Name -> Idris Name
resolveProof :: Name -> Idris Name
resolveProof Name
n'
  = do IState
i <- Idris IState
getIState
       Context
ctxt <- Idris Context
getContext
       Name
n <- case Name -> Context -> [Name]
lookupNames Name
n' Context
ctxt of
                 [Name
x] -> forall (m :: * -> *) a. Monad m => a -> m a
return Name
x
                 [] -> forall (m :: * -> *) a. Monad m => a -> m a
return Name
n'
                 [Name]
ns -> forall a. Err -> Idris a
ierror (forall t. [Name] -> Err' t
CantResolveAlts [Name]
ns)
       forall (m :: * -> *) a. Monad m => a -> m a
return Name
n

removeProof :: Name -> Idris ()
removeProof :: Name -> Idris ()
removeProof Name
n =
  do IState
i <- Idris IState
getIState
     let proofs :: [(Name, (Bool, [FilePath]))]
proofs = IState -> [(Name, (Bool, [FilePath]))]
proof_list IState
i
     let ps :: [(Name, (Bool, [FilePath]))]
ps = forall a. (a -> Bool) -> [a] -> [a]
filter ((forall a. Eq a => a -> a -> Bool
/= Name
n) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (a, b) -> a
fst) [(Name, (Bool, [FilePath]))]
proofs
     IState -> Idris ()
putIState forall a b. (a -> b) -> a -> b
$ IState
i { proof_list :: [(Name, (Bool, [FilePath]))]
proof_list = [(Name, (Bool, [FilePath]))]
ps }

edit :: FilePath -> IState -> Idris ()
edit :: FilePath -> IState -> Idris ()
edit FilePath
"" IState
orig = FilePath -> Idris ()
iputStrLn FilePath
"Nothing to edit"
edit FilePath
f IState
orig
    = do IState
i <- Idris IState
getIState
         [(FilePath, FilePath)]
env <- forall a. IO a -> Idris a
runIO IO [(FilePath, FilePath)]
getEnvironment
         let editor :: FilePath
editor = [(FilePath, FilePath)] -> FilePath
getEditor [(FilePath, FilePath)]
env
         let line :: FilePath
line = case IState -> Maybe FC
errSpan IState
i of
                        Just FC
l -> Char
'+' forall a. a -> [a] -> [a]
: forall a. Show a => a -> FilePath
show (forall a b. (a, b) -> a
fst (FC -> (Int, Int)
fc_start FC
l))
                        Maybe FC
Nothing -> FilePath
""
         let cmdLine :: FilePath
cmdLine = forall a. [a] -> [[a]] -> [a]
intercalate FilePath
" " [FilePath
editor, FilePath
line, FilePath -> FilePath
fixName FilePath
f]
         forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO ExitCode
system FilePath
cmdLine
         Idris ()
clearErr
  -- The $!! here prevents a space leak on reloading.
  -- This isn't a solution - but it's a temporary stopgap.
  -- See issue #2386
         IState -> Idris ()
putIState forall a b. NFData a => (a -> b) -> a -> b
$!! IState
orig { idris_options :: IOption
idris_options = IState -> IOption
idris_options IState
i
                            , idris_colourTheme :: ColourTheme
idris_colourTheme = IState -> ColourTheme
idris_colourTheme IState
i
                            }
         [FilePath] -> Maybe Int -> Idris [FilePath]
loadInputs [FilePath
f] forall a. Maybe a
Nothing
--          clearOrigPats
         Idris ()
iucheck
         forall (m :: * -> *) a. Monad m => a -> m a
return ()
   where getEditor :: [(FilePath, FilePath)] -> FilePath
getEditor [(FilePath, FilePath)]
env | Just FilePath
ed <- forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup FilePath
"EDITOR" [(FilePath, FilePath)]
env = FilePath
ed
                       | Just FilePath
ed <- forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup FilePath
"VISUAL" [(FilePath, FilePath)]
env = FilePath
ed
                       | Bool
otherwise = FilePath
"vi"
         fixName :: FilePath -> FilePath
fixName FilePath
file | forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower (FilePath -> FilePath
takeExtension FilePath
file) forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [FilePath
".lidr", FilePath
".idr"] = FilePath -> FilePath
quote FilePath
file
                      | Bool
otherwise = FilePath -> FilePath
quote forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath -> FilePath
addExtension FilePath
file FilePath
"idr"
            where
                quoteChar :: Char
quoteChar = if Bool
isWindows then Char
'"' else Char
'\''
                quote :: FilePath -> FilePath
quote FilePath
s = [Char
quoteChar] forall a. [a] -> [a] -> [a]
++ FilePath
s forall a. [a] -> [a] -> [a]
++ [Char
quoteChar]



proofs :: IState -> Idris ()
proofs :: IState -> Idris ()
proofs IState
orig
  = do IState
i <- Idris IState
getIState
       let ps :: [(Name, (Bool, [FilePath]))]
ps = IState -> [(Name, (Bool, [FilePath]))]
proof_list IState
i
       case [(Name, (Bool, [FilePath]))]
ps of
            [] -> FilePath -> Idris ()
iputStrLn FilePath
"No proofs available"
            [(Name, (Bool, [FilePath]))]
_  -> FilePath -> Idris ()
iputStrLn forall a b. (a -> b) -> a -> b
$ FilePath
"Proofs:\n\t" forall a. [a] -> [a] -> [a]
++ (forall a. Show a => a -> FilePath
show forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(Name, (Bool, [FilePath]))]
ps)

insertScript :: String -> [String] -> [String]
insertScript :: FilePath -> [FilePath] -> [FilePath]
insertScript FilePath
prf [] = FilePath
"\n---------- Proofs ----------" forall a. a -> [a] -> [a]
: FilePath
"" forall a. a -> [a] -> [a]
: [FilePath
prf]
insertScript FilePath
prf (p :: FilePath
p@FilePath
"---------- Proofs ----------" : FilePath
"" : [FilePath]
xs)
    = FilePath
p forall a. a -> [a] -> [a]
: FilePath
"" forall a. a -> [a] -> [a]
: FilePath
prf forall a. a -> [a] -> [a]
: [FilePath]
xs
insertScript FilePath
prf (FilePath
x : [FilePath]
xs) = FilePath
x forall a. a -> [a] -> [a]
: FilePath -> [FilePath] -> [FilePath]
insertScript FilePath
prf [FilePath]
xs

process :: FilePath -> Command -> Idris ()
process :: FilePath -> Command -> Idris ()
process FilePath
fn Command
Help = FilePath -> Idris ()
iPrintResult FilePath
displayHelp
process FilePath
fn Command
ShowVersion = FilePath -> Idris ()
iPrintResult FilePath
getIdrisVersion
process FilePath
fn Command
Warranty = FilePath -> Idris ()
iPrintResult FilePath
warranty
process FilePath
fn (RunShellCommand FilePath
cmd) = forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO ExitCode
system FilePath
cmd forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return ()
process FilePath
fn (ChangeDirectory FilePath
f)
                 = do forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO ()
setCurrentDirectory FilePath
f
                      forall (m :: * -> *) a. Monad m => a -> m a
return ()
process FilePath
fn (ModImport FilePath
f) = do Maybe FilePath
fmod <- FilePath -> IBCPhase -> Idris (Maybe FilePath)
loadModule FilePath
f (Bool -> IBCPhase
IBC_REPL Bool
True)
                              case Maybe FilePath
fmod of
                                Just FilePath
pr -> FilePath -> Idris ()
isetPrompt FilePath
pr
                                Maybe FilePath
Nothing -> FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ FilePath
"Can't find import " forall a. [a] -> [a] -> [a]
++ FilePath
f
process FilePath
fn (Eval PTerm
t)
                 = forall a. Idris a -> Idris a
withErrorReflection forall a b. (a -> b) -> a -> b
$
                   do Int -> FilePath -> Idris ()
logParser Int
5 forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> FilePath
show PTerm
t
                      Idris IState
getIState forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a b c. (a -> b -> c) -> b -> a -> c
flip IState -> PTerm -> Idris ()
warnDisamb PTerm
t
                      (Term
tm, Term
ty) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabREPL (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS PTerm
t
                      Context
ctxt <- Idris Context
getContext
                      let tm' :: Term
tm' = Term -> Term
perhapsForce forall a b. (a -> b) -> a -> b
$ Context -> Env -> [Name] -> Term -> Term
normaliseBlocking Context
ctxt []
                                                  [FilePath -> Name
sUN FilePath
"foreign",
                                                   FilePath -> Name
sUN FilePath
"prim_read",
                                                   FilePath -> Name
sUN FilePath
"prim_write"]
                                                 Term
tm
                      let ty' :: Term
ty' = Term -> Term
perhapsForce forall a b. (a -> b) -> a -> b
$ Context -> Env -> Term -> Term
normaliseAll Context
ctxt [] Term
ty
                      -- Add value to context, call it "it"
                      (Context -> Context) -> Idris ()
updateContext (Name -> Def -> Context -> Context
addCtxtDef (FilePath -> Name
sUN FilePath
"it") (Term -> Term -> Def
Function Term
ty' Term
tm'))
                      IState
ist <- Idris IState
getIState
                      Int -> FilePath -> Idris ()
logParser Int
3 forall a b. (a -> b) -> a -> b
$ FilePath
"Raw: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show (Term
tm', Term
ty')
                      Int -> FilePath -> Idris ()
logParser Int
10 forall a b. (a -> b) -> a -> b
$ FilePath
"Debug: " forall a. [a] -> [a] -> [a]
++ forall {a}.
(Show a, Eq a) =>
[(a, RigCount, Binder (TT a))] -> TT a -> FilePath
showEnvDbg [] Term
tm'
                      let tmDoc :: Doc OutputAnnotation
tmDoc = IState -> Term -> Doc OutputAnnotation
pprintDelab IState
ist Term
tm'
                          -- errReverse to make type more readable
                          tyDoc :: Doc OutputAnnotation
tyDoc =  IState -> Term -> Doc OutputAnnotation
pprintDelab IState
ist (IState -> Term -> Term
errReverse IState
ist Term
ty')
                      Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
iPrintTermWithType Doc OutputAnnotation
tmDoc Doc OutputAnnotation
tyDoc
  where perhapsForce :: Term -> Term
perhapsForce Term
tm | Int -> Term -> Bool
termSmallerThan Int
100 Term
tm = forall a. NFData a => a -> a
force Term
tm
                        | Bool
otherwise = Term
tm

process FilePath
fn (NewDefn [PDecl]
decls) = do
        Int -> FilePath -> Idris ()
logParser Int
3 (FilePath
"Defining names using these decls: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show (PPOption -> [PDecl] -> Doc OutputAnnotation
showDecls PPOption
verbosePPOption [PDecl]
decls))
        forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ [PDecl] -> Idris ()
defineName [[PDecl]]
namedGroups where
  namedGroups :: [[PDecl]]
namedGroups = forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy (\PDecl
d1 PDecl
d2 -> PDecl -> Maybe Name
getName PDecl
d1 forall a. Eq a => a -> a -> Bool
== PDecl -> Maybe Name
getName PDecl
d2) [PDecl]
decls
  getName :: PDecl -> Maybe Name
  getName :: PDecl -> Maybe Name
getName (PTy Docstring (Either Err PTerm)
docs [(Name, Docstring (Either Err PTerm))]
argdocs SyntaxInfo
syn FC
fc FnOpts
opts Name
name FC
_ PTerm
ty) = forall a. a -> Maybe a
Just Name
name
  getName (PClauses FC
fc FnOpts
opts Name
name (PClause' PTerm
clause:[PClause' PTerm]
clauses)) = forall a. a -> Maybe a
Just (forall {t}. PClause' t -> Name
getClauseName PClause' PTerm
clause)
  getName (PData Docstring (Either Err PTerm)
doc [(Name, Docstring (Either Err PTerm))]
argdocs SyntaxInfo
syn FC
fc DataOpts
opts PData' PTerm
dataDecl) = forall a. a -> Maybe a
Just (forall t. PData' t -> Name
d_name PData' PTerm
dataDecl)
  getName (PInterface Docstring (Either Err PTerm)
doc SyntaxInfo
syn FC
fc [(Name, PTerm)]
constraints Name
name FC
nfc [(Name, FC, PTerm)]
parms [(Name, Docstring (Either Err PTerm))]
parmdocs [(Name, FC)]
fds [PDecl]
decls Maybe (Name, FC)
_ Docstring (Either Err PTerm)
_) = forall a. a -> Maybe a
Just Name
name
  getName PDecl
_ = forall a. Maybe a
Nothing
  -- getClauseName is partial and I am not sure it's used safely! -- trillioneyes
  getClauseName :: PClause' t -> Name
getClauseName (PClause FC
fc Name
name t
whole [t]
with t
rhs [PDecl' t]
whereBlock) = Name
name
  getClauseName (PWith FC
fc Name
name t
whole [t]
with t
rhs Maybe (Name, FC)
pn [PDecl' t]
whereBlock) = Name
name
  defineName :: [PDecl] -> Idris ()
  defineName :: [PDecl] -> Idris ()
defineName (tyDecl :: PDecl
tyDecl@(PTy Docstring (Either Err PTerm)
docs [(Name, Docstring (Either Err PTerm))]
argdocs SyntaxInfo
syn FC
fc FnOpts
opts Name
name FC
_ PTerm
ty) : [PDecl]
decls) = do
    ElabWhat -> ElabInfo -> PDecl -> Idris ()
elabDecl ElabWhat
EAll ElabInfo
info PDecl
tyDecl
    ElabInfo -> FC -> FnOpts -> Name -> [PClause' PTerm] -> Idris ()
elabClauses ElabInfo
info FC
fc FnOpts
opts Name
name (forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall {t}. PDecl' t -> [PClause' t]
getClauses [PDecl]
decls)
    Maybe Name -> Idris ()
setReplDefined (forall a. a -> Maybe a
Just Name
name)
  defineName [PClauses FC
fc FnOpts
opts Name
_ [PClause' PTerm
clause]] = do
    let pterm :: PTerm
pterm = PClause' PTerm -> PTerm
getRHS PClause' PTerm
clause
    (Term
tm,Term
ty) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal ElabInfo
info ElabMode
ERHS PTerm
pterm
    Context
ctxt <- Idris Context
getContext
    let tm' :: Term
tm' = forall a. NFData a => a -> a
force (Context -> Env -> Term -> Term
normaliseAll Context
ctxt [] Term
tm)
    let ty' :: Term
ty' = forall a. NFData a => a -> a
force (Context -> Env -> Term -> Term
normaliseAll Context
ctxt [] Term
ty)
    (Context -> Context) -> Idris ()
updateContext (Name -> Def -> Context -> Context
addCtxtDef (forall {t}. PClause' t -> Name
getClauseName PClause' PTerm
clause) (Term -> Term -> Def
Function Term
ty' Term
tm'))
    Maybe Name -> Idris ()
setReplDefined (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall {t}. PClause' t -> Name
getClauseName PClause' PTerm
clause)
  defineName (PClauses{} : [PDecl]
_) = forall a. TC a -> Idris a
tclift forall a b. (a -> b) -> a -> b
$ forall a. Err -> TC a
tfail (forall t. FilePath -> Err' t
Msg FilePath
"Only one function body is allowed without a type declaration.")
  -- fixity and syntax declarations are ignored by elabDecls, so they'll have to be handled some other way
  defineName (PFix FC
fc Fixity
fixity [FilePath]
strs : [PDecl]
defns) = do
    forall s (m :: * -> *) a.
MonadState s m =>
Field s a -> (a -> a) -> m ()
fmodifyState Field IState [FixDecl]
idris_fixities (forall a b. (a -> b) -> [a] -> [b]
map (Fixity -> FilePath -> FixDecl
Fix Fixity
fixity) [FilePath]
strs forall a. [a] -> [a] -> [a]
++)
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PDecl]
defns) forall a b. (a -> b) -> a -> b
$ [PDecl] -> Idris ()
defineName [PDecl]
defns
  defineName (PSyntax FC
_ Syntax
syntax:[PDecl]
_) = do
    IState
i <- forall (m :: * -> *) s. Monad m => StateT s m s
get
    forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put (IState -> Syntax -> IState
addReplSyntax IState
i Syntax
syntax)
  defineName [PDecl]
decls = do
    ElabInfo -> [PDecl] -> Idris ()
elabDecls (FilePath -> ElabInfo
toplevelWith FilePath
fn) (forall a b. (a -> b) -> [a] -> [b]
map forall t. PDecl' t -> PDecl' t
fixClauses [PDecl]
decls)
    Maybe Name -> Idris ()
setReplDefined (PDecl -> Maybe Name
getName (forall a. [a] -> a
head [PDecl]
decls))
  getClauses :: PDecl' t -> [PClause' t]
getClauses (PClauses FC
fc FnOpts
opts Name
name [PClause' t]
clauses) = [PClause' t]
clauses
  getClauses PDecl' t
_ = []
  getRHS :: PClause -> PTerm
  getRHS :: PClause' PTerm -> PTerm
getRHS (PClause FC
fc Name
name PTerm
whole [PTerm]
with PTerm
rhs [PDecl]
whereBlock) = PTerm
rhs
  getRHS (PWith FC
fc Name
name PTerm
whole [PTerm]
with PTerm
rhs Maybe (Name, FC)
pn [PDecl]
whereBlock) = PTerm
rhs
  getRHS (PClauseR FC
fc [PTerm]
with PTerm
rhs [PDecl]
whereBlock) = PTerm
rhs
  getRHS (PWithR FC
fc [PTerm]
with PTerm
rhs Maybe (Name, FC)
pn [PDecl]
whereBlock) = PTerm
rhs
  setReplDefined :: Maybe Name -> Idris ()
  setReplDefined :: Maybe Name -> Idris ()
setReplDefined Maybe Name
Nothing = forall (m :: * -> *) a. Monad m => a -> m a
return ()
  setReplDefined (Just Name
n) = do
    IState
oldState <- forall (m :: * -> *) s. Monad m => StateT s m s
get
    forall s (m :: * -> *) a.
MonadState s m =>
Field s a -> (a -> a) -> m ()
fmodifyState Field IState [Name]
repl_definitions (Name
nforall a. a -> [a] -> [a]
:)
  -- the "name" field of PClauses seems to always be MN 2 "__", so we need to
  -- retrieve the actual name from deeper inside.
  -- This should really be a full recursive walk through the structure of PDecl, but
  -- I think it should work this way and I want to test sooner. Also lazy.
  fixClauses :: PDecl' t -> PDecl' t
  fixClauses :: forall t. PDecl' t -> PDecl' t
fixClauses (PClauses FC
fc FnOpts
opts Name
_ css :: [PClause' t]
css@(PClause' t
clause:[PClause' t]
cs)) =
    forall t. FC -> FnOpts -> Name -> [PClause' t] -> PDecl' t
PClauses FC
fc FnOpts
opts (forall {t}. PClause' t -> Name
getClauseName PClause' t
clause) [PClause' t]
css
  fixClauses (PImplementation Docstring (Either Err t)
doc [(Name, Docstring (Either Err t))]
argDocs SyntaxInfo
syn FC
fc [(Name, t)]
constraints [Name]
pnames Accessibility
acc FnOpts
opts Name
cls FC
nfc [t]
parms [(Name, t)]
pextra t
ty Maybe Name
implName [PDecl' t]
decls) =
    forall t.
Docstring (Either Err t)
-> [(Name, Docstring (Either Err t))]
-> SyntaxInfo
-> FC
-> [(Name, t)]
-> [Name]
-> Accessibility
-> FnOpts
-> Name
-> FC
-> [t]
-> [(Name, t)]
-> t
-> Maybe Name
-> [PDecl' t]
-> PDecl' t
PImplementation Docstring (Either Err t)
doc [(Name, Docstring (Either Err t))]
argDocs SyntaxInfo
syn FC
fc [(Name, t)]
constraints [Name]
pnames Accessibility
acc FnOpts
opts Name
cls FC
nfc [t]
parms [(Name, t)]
pextra t
ty Maybe Name
implName (forall a b. (a -> b) -> [a] -> [b]
map forall t. PDecl' t -> PDecl' t
fixClauses [PDecl' t]
decls)
  fixClauses PDecl' t
decl = PDecl' t
decl

  info :: ElabInfo
info = FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")

process FilePath
fn (Undefine [Name]
names) = [Name] -> Idris ()
undefine [Name]
names
  where
    undefine :: [Name] -> Idris ()
    undefine :: [Name] -> Idris ()
undefine [] = do
      [Name]
allDefined <- IState -> [Name]
idris_repl_defs forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall (m :: * -> *) s. Monad m => StateT s m s
get
      [Name] -> [Name] -> Idris ()
undefine' [Name]
allDefined []
    -- Keep track of which names you've removed so you can
    -- print them out to the user afterward
    undefine [Name]
names = [Name] -> [Name] -> Idris ()
undefine' [Name]
names []
    undefine' :: [Name] -> [Name] -> Idris ()
undefine' [] [Name]
list = do Doc OutputAnnotation -> Idris ()
iRenderResult forall a b. (a -> b) -> a -> b
$ [Name] -> Doc OutputAnnotation
printUndefinedNames [Name]
list
                           forall (m :: * -> *) a. Monad m => a -> m a
return ()
    undefine' (Name
n:[Name]
names) [Name]
already = do
      [Name]
allDefined <- IState -> [Name]
idris_repl_defs forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall (m :: * -> *) s. Monad m => StateT s m s
get
      if Name
n forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Name]
allDefined
         then do [Name]
undefinedJustNow <- Name -> Idris [Name]
undefClosure Name
n
                 [Name] -> [Name] -> Idris ()
undefine' [Name]
names ([Name]
undefinedJustNow forall a. [a] -> [a] -> [a]
++ [Name]
already)
         else do forall a. TC a -> Idris a
tclift forall a b. (a -> b) -> a -> b
$ forall a. Err -> TC a
tfail forall a b. (a -> b) -> a -> b
$ forall t. FilePath -> Err' t
Msg (FilePath
"Can't undefine " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Name
n forall a. [a] -> [a] -> [a]
++ FilePath
" because it wasn't defined at the repl")
                 [Name] -> [Name] -> Idris ()
undefine' [Name]
names [Name]
already
    undefOne :: Name -> m ()
undefOne Name
n = do forall s (m :: * -> *) a. MonadState s m => Field s a -> a -> m ()
fputState (forall a. Name -> Field (Ctxt a) (Maybe a)
ctxt_lookup Name
n forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Field
  IState
  (Ctxt
     (Def, RigCount, Bool, Accessibility, Totality, MetaInformation))
known_terms) forall a. Maybe a
Nothing
                    -- for now just assume it's an interface. Eventually we'll want some kind of
                    -- smart detection of exactly what kind of name we're undefining.
                    forall s (m :: * -> *) a. MonadState s m => Field s a -> a -> m ()
fputState (forall a. Name -> Field (Ctxt a) (Maybe a)
ctxt_lookup Name
n forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Field IState (Ctxt InterfaceInfo)
known_interfaces) forall a. Maybe a
Nothing
                    forall s (m :: * -> *) a.
MonadState s m =>
Field s a -> (a -> a) -> m ()
fmodifyState Field IState [Name]
repl_definitions (forall a. Eq a => a -> [a] -> [a]
delete Name
n)
    undefClosure :: Name -> Idris [Name]
undefClosure Name
n =
      do [Name]
replDefs <- IState -> [Name]
idris_repl_defs forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall (m :: * -> *) s. Monad m => StateT s m s
get
         [(Name, [Name])]
callGraph <- Name -> Idris [(Name, [Name])]
whoCalls Name
n
         let users :: [Name]
users = case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
n [(Name, [Name])]
callGraph of
                        Just [Name]
ns -> forall a. Eq a => [a] -> [a]
nub [Name]
ns
                        Maybe [Name]
Nothing -> forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath
"Tried to undefine nonexistent name" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Name
n)
         [Name]
undefinedJustNow <- forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Name -> Idris [Name]
undefClosure [Name]
users
         forall {m :: * -> *}. MonadState IState m => Name -> m ()
undefOne Name
n
         forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Eq a => [a] -> [a]
nub (Name
n forall a. a -> [a] -> [a]
: [Name]
undefinedJustNow))



process FilePath
fn (ExecVal PTerm
t)
                  = do Context
ctxt <- Idris Context
getContext
                       IState
ist <- Idris IState
getIState
                       (Term
tm, Term
ty) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS PTerm
t
--                       let tm' = normaliseAll ctxt [] tm
                       let ty' :: Term
ty' = Context -> Env -> Term -> Term
normaliseAll Context
ctxt [] Term
ty
                       Term
res <- Term -> Idris Term
execute Term
tm
                       let (Doc OutputAnnotation
resOut, Doc OutputAnnotation
tyOut) = (IState -> PTerm -> Doc OutputAnnotation
prettyIst IState
ist (IState -> Term -> PTerm
delab IState
ist Term
res),
                                              IState -> PTerm -> Doc OutputAnnotation
prettyIst IState
ist (IState -> Term -> PTerm
delab IState
ist Term
ty'))
                       Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
iPrintTermWithType Doc OutputAnnotation
resOut Doc OutputAnnotation
tyOut

process FilePath
fn (Check (PRef FC
_ [FC]
_ Name
n))
   = do Context
ctxt <- Idris Context
getContext
        IState
ist <- Idris IState
getIState
        let ppo :: PPOption
ppo = IState -> PPOption
ppOptionIst IState
ist
        case Name -> Context -> [Name]
lookupVisibleNames Name
n Context
ctxt of
          ts :: [Name]
ts@(Name
t:[Name]
_) ->
            case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
t (IState -> [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
idris_metavars IState
ist) of
                Just (Maybe Name
_, Int
i, [Name]
_, Bool
_, Bool
_) -> Doc OutputAnnotation -> Idris ()
iRenderResult forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (IState -> Bool -> OutputAnnotation -> OutputAnnotation
fancifyAnnots IState
ist Bool
True) forall a b. (a -> b) -> a -> b
$
                                        PPOption -> IState -> Name -> Int -> Doc OutputAnnotation
showMetavarInfo PPOption
ppo IState
ist Name
n Int
i
                Maybe (Maybe Name, Int, [Name], Bool, Bool)
Nothing -> [(Name, Bool)]
-> Name -> [(Name, Doc OutputAnnotation)] -> Idris ()
iPrintFunTypes [] Name
n (forall a b. (a -> b) -> [a] -> [b]
map (\Name
n -> (Name
n, IState -> Name -> Doc OutputAnnotation
pprintDelabTy IState
ist Name
n)) [Name]
ts)
          [] -> FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ FilePath
"No such variable " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Name
n
  where
    lookupVisibleNames :: Name -> Context -> [Name]
    lookupVisibleNames :: Name -> Context -> [Name]
lookupVisibleNames Name
n Context
ctxt = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n (Context
-> Ctxt
     (Def, RigCount, Bool, Accessibility, Totality, MetaInformation)
visibleDefinitions Context
ctxt)

    showMetavarInfo :: PPOption -> IState -> Name -> Int -> Doc OutputAnnotation
showMetavarInfo PPOption
ppo IState
ist Name
n Int
i
         = case Name -> Context -> [Term]
lookupTy Name
n (IState -> Context
tt_ctxt IState
ist) of
                (Term
ty:[Term]
_) -> let ty' :: Term
ty' = Context -> Env -> Term -> Term
normaliseC (IState -> Context
tt_ctxt IState
ist) [] Term
ty in
                              PPOption
-> IState -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
putTy PPOption
ppo IState
ist Int
i [] (IState -> Term -> PTerm
delab IState
ist (IState -> Term -> Term
errReverse IState
ist Term
ty'))
    putTy :: PPOption -> IState -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
    putTy :: PPOption
-> IState -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
putTy PPOption
ppo IState
ist Int
0 [(Name, Bool)]
bnd PTerm
sc = forall {p}.
p -> IState -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
putGoal PPOption
ppo IState
ist [(Name, Bool)]
bnd PTerm
sc
    putTy PPOption
ppo IState
ist Int
i [(Name, Bool)]
bnd (PPi Plicity
p Name
n FC
_ PTerm
t PTerm
sc)
               = let current :: Doc OutputAnnotation
current = case Name
n of
                                   MN Int
_ Text
_ -> forall a. FilePath -> Doc a
text FilePath
""
                                   UN Text
nm | (Char
'_':Char
'_':FilePath
_) <- Text -> FilePath
str Text
nm -> forall a. FilePath -> Doc a
text FilePath
""
                                   Name
_ -> forall {a}. RigCount -> Bool -> Doc a
countOf (Plicity -> RigCount
pcount Plicity
p)
                                            (LanguageExt
LinearTypes forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` IState -> [LanguageExt]
idris_language_extensions IState
ist) forall a. Doc a -> Doc a -> Doc a
<+>
                                        Name -> Bool -> Doc OutputAnnotation
bindingOf Name
n Bool
False
                                            forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon
                                            forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a -> Doc a
align ([(Name, Bool)] -> IState -> PTerm -> Doc OutputAnnotation
tPretty [(Name, Bool)]
bnd IState
ist PTerm
t)
                                            forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
line
                 in
                    Doc OutputAnnotation
current forall a. Doc a -> Doc a -> Doc a
<> PPOption
-> IState -> Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
putTy PPOption
ppo IState
ist (Int
iforall a. Num a => a -> a -> a
-Int
1) ((Name
n,Bool
False)forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
    putTy PPOption
ppo IState
ist Int
_ [(Name, Bool)]
bnd PTerm
sc = forall {p}.
p -> IState -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
putGoal PPOption
ppo IState
ist ((Name
n,Bool
False)forall a. a -> [a] -> [a]
:[(Name, Bool)]
bnd) PTerm
sc
    putGoal :: p -> IState -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
putGoal p
ppo IState
ist [(Name, Bool)]
bnd PTerm
g
               = forall a. FilePath -> Doc a
text FilePath
"--------------------------------------" forall a. Doc a -> Doc a -> Doc a
<$>
                 forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe FilePath
-> Maybe FilePath
-> OutputAnnotation
AnnName Name
n forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing) (forall a. FilePath -> Doc a
text forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> FilePath
show Name
n) forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon forall a. Doc a -> Doc a -> Doc a
<+>
                 forall a. Doc a -> Doc a
align ([(Name, Bool)] -> IState -> PTerm -> Doc OutputAnnotation
tPretty [(Name, Bool)]
bnd IState
ist PTerm
g)

    -- Only display count if linear types extension is enabled
    countOf :: RigCount -> Bool -> Doc a
countOf RigCount
Rig0 Bool
True = forall a. FilePath -> Doc a
text FilePath
"0"
    countOf RigCount
Rig1 Bool
True = forall a. FilePath -> Doc a
text FilePath
"1"
    countOf RigCount
_ Bool
_ = forall a. FilePath -> Doc a
text FilePath
" "

    tPretty :: [(Name, Bool)] -> IState -> PTerm -> Doc OutputAnnotation
tPretty [(Name, Bool)]
bnd IState
ist PTerm
t = PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm (IState -> PPOption
ppOptionIst IState
ist) [(Name, Bool)]
bnd [] (IState -> [FixDecl]
idris_infixes IState
ist) PTerm
t


process FilePath
fn (Check PTerm
t)
   = do (Term
tm, Term
ty) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabREPL (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS PTerm
t
        Context
ctxt <- Idris Context
getContext
        IState
ist <- Idris IState
getIState
        let ty' :: Term
ty' = if IOption -> Bool
opt_evaltypes (IState -> IOption
idris_options IState
ist)
                     then Context -> Env -> Term -> Term
normaliseC Context
ctxt [] Term
ty
                     else Term
ty
        case Term
tm of
           TType UExp
_ ->
             Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
iPrintTermWithType (IState -> PTerm -> Doc OutputAnnotation
prettyIst IState
ist (FC -> PTerm
PType FC
emptyFC)) Doc OutputAnnotation
type1Doc
           Term
_ -> Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
iPrintTermWithType (IState -> Term -> Doc OutputAnnotation
pprintDelab IState
ist Term
tm)
                                   (IState -> Term -> Doc OutputAnnotation
pprintDelab IState
ist Term
ty')

process FilePath
fn (Core PTerm
t)
   = case PTerm
t of
       PRef FC
_ [FC]
_ Name
n ->
         do IState
ist <- Idris IState
getIState
            case Name -> Context -> [Def]
lookupDef Name
n (IState -> Context
tt_ctxt IState
ist) of
              [CaseOp CaseInfo
_ Term
_ [(Term, Bool)]
_ [Either Term (Term, Term)]
_ [([Name], Term, Term)]
_ CaseDefs
_] -> Bool -> Name -> Idris [Doc OutputAnnotation]
pprintDef Bool
True Name
n forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Doc OutputAnnotation -> Idris ()
iRenderResult forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. [Doc a] -> Doc a
vsep
              [Def]
_ -> PTerm -> Idris ()
coreTerm PTerm
t
       PTerm
t -> PTerm -> Idris ()
coreTerm PTerm
t
   where coreTerm :: PTerm -> Idris ()
coreTerm PTerm
t =
           do (Term
tm, Term
ty) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabREPL (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS PTerm
t
              Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
iPrintTermWithType ([Name] -> Term -> Doc OutputAnnotation
pprintTT [] Term
tm) ([Name] -> Term -> Doc OutputAnnotation
pprintTT [] Term
ty)

process FilePath
fn (DocStr (Left Name
n) HowMuchDocs
w)
  | UN Text
ty <- Name
n, Text
ty forall a. Eq a => a -> a -> Bool
== FilePath -> Text
T.pack FilePath
"Type" = Idris IState
getIState forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Doc OutputAnnotation -> Idris ()
iRenderResult forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. IState -> Doc OutputAnnotation
pprintTypeDoc
  | Bool
otherwise = do
        IState
ist <- Idris IState
getIState
        let docs :: [(Name, (Docstring DocTerm, [(Name, Docstring DocTerm)]))]
docs = forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n (IState -> Ctxt (Docstring DocTerm, [(Name, Docstring DocTerm)])
idris_docstrings IState
ist) forall a. [a] -> [a] -> [a]
++
                   forall a b. (a -> b) -> [a] -> [b]
map (\(Name
n,Docstring DocTerm
d)-> (Name
n, (Docstring DocTerm
d, [])))
                       (forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName (Name -> Name
modDocN Name
n) (IState -> Ctxt (Docstring DocTerm)
idris_moduledocs IState
ist))
        case [(Name, (Docstring DocTerm, [(Name, Docstring DocTerm)]))]
docs of
          [] -> FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ FilePath
"No documentation for " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Name
n
          [(Name, (Docstring DocTerm, [(Name, Docstring DocTerm)]))]
ns -> do [Doc OutputAnnotation]
toShow <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall {b}.
IState
-> (Name, b)
-> StateT IState (ExceptT Err IO) (Doc OutputAnnotation)
showDoc IState
ist) [(Name, (Docstring DocTerm, [(Name, Docstring DocTerm)]))]
ns
                   Doc OutputAnnotation -> Idris ()
iRenderResult (forall a. [Doc a] -> Doc a
vsep [Doc OutputAnnotation]
toShow)
    where showDoc :: IState
-> (Name, b)
-> StateT IState (ExceptT Err IO) (Doc OutputAnnotation)
showDoc IState
ist (Name
n, b
d) = do Docs
doc <- Name -> HowMuchDocs -> Idris Docs
getDocs Name
n HowMuchDocs
w
                                  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ IState -> Docs -> Doc OutputAnnotation
pprintDocs IState
ist Docs
doc

          modDocN :: Name -> Name
modDocN (NS (UN Text
n) [Text]
ns) = Name -> [Text] -> Name
NS Name
modDocName (Text
nforall a. a -> [a] -> [a]
:[Text]
ns)
          modDocN (UN Text
n)         = Name -> [Text] -> Name
NS Name
modDocName [Text
n]
          modDocN Name
_              = Int -> FilePath -> Name
sMN Int
1 FilePath
"NotFoundForSure"

process FilePath
fn (DocStr (Right Const
c) HowMuchDocs
_) -- constants only have overviews
   = do IState
ist <- Idris IState
getIState
        Doc OutputAnnotation -> Idris ()
iRenderResult forall a b. (a -> b) -> a -> b
$ IState -> Const -> FilePath -> Doc OutputAnnotation
pprintConstDocs IState
ist Const
c (Const -> FilePath
constDocs Const
c)

process FilePath
fn Command
Universes
                     = do IState
i <- Idris IState
getIState
                          let cs :: Set ConstraintFC
cs = IState -> Set ConstraintFC
idris_constraints IState
i
                          let cslist :: [ConstraintFC]
cslist = forall a. Set a -> [a]
S.toAscList Set ConstraintFC
cs
--                        iputStrLn $ showSep "\n" (map show cs)
                          FilePath -> Idris ()
iputStrLn forall a b. (a -> b) -> a -> b
$ FilePath -> [FilePath] -> FilePath
showSep FilePath
"\n" (forall a b. (a -> b) -> [a] -> [b]
map forall a. Show a => a -> FilePath
show [ConstraintFC]
cslist)
                          let n :: Int
n = forall (t :: * -> *) a. Foldable t => t a -> Int
length [ConstraintFC]
cslist
                          FilePath -> Idris ()
iputStrLn forall a b. (a -> b) -> a -> b
$ FilePath
"(" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Int
n forall a. [a] -> [a] -> [a]
++ FilePath
" constraints)"
                          case Set ConstraintFC -> TC ()
ucheck Set ConstraintFC
cs of
                            Error Err
e -> FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ IState -> Err -> FilePath
pshow IState
i Err
e
                            OK ()
_ -> FilePath -> Idris ()
iPrintResult FilePath
"Universes OK"
process FilePath
fn (Defn Name
n)
                    = do IState
i <- Idris IState
getIState
                         let head :: Doc a
head = forall a. FilePath -> Doc a
text FilePath
"Compiled patterns:" forall a. Doc a -> Doc a -> Doc a
<$>
                                    forall a. FilePath -> Doc a
text (forall a. Show a => a -> FilePath
show (Name -> Context -> [Def]
lookupDef Name
n (IState -> Context
tt_ctxt IState
i)))
                         let defs :: Doc a
defs =
                              case forall a. Name -> Ctxt a -> [a]
lookupCtxt Name
n (IState -> Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
idris_patdefs IState
i) of
                                [] -> forall a. Doc a
empty
                                [([([(Name, Term)], Term, Term)]
d, [PTerm]
_)] -> forall a. FilePath -> Doc a
text FilePath
"Original definiton:" forall a. Doc a -> Doc a -> Doc a
<$>
                                            forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (forall {a} {a}. IState -> (a, Term, Term) -> Doc a
printCase IState
i) [([(Name, Term)], Term, Term)]
d)
                         let tot :: Doc OutputAnnotation
tot =
                              case Name -> Context -> [Totality]
lookupTotal Name
n (IState -> Context
tt_ctxt IState
i) of
                                 [Totality
t] -> Totality -> IState -> Doc OutputAnnotation
showTotal Totality
t IState
i
                                 [Totality]
_ -> forall a. Doc a
empty
                         Doc OutputAnnotation -> Idris ()
iRenderResult forall a b. (a -> b) -> a -> b
$ forall a. [Doc a] -> Doc a
vsep [forall a. Doc a
head, forall a. Doc a
defs, Doc OutputAnnotation
tot]
    where printCase :: IState -> (a, Term, Term) -> Doc a
printCase IState
i (a
_, Term
lhs, Term
rhs)
             = let i' :: IState
i' = IState
i { idris_options :: IOption
idris_options = (IState -> IOption
idris_options IState
i) { opt_showimp :: Bool
opt_showimp = Bool
True } }
               in forall a. FilePath -> Doc a
text (IState -> PTerm -> FilePath
showTm IState
i' (IState -> Term -> PTerm
delab IState
i Term
lhs)) forall a. Doc a -> Doc a -> Doc a
<+> forall a. FilePath -> Doc a
text FilePath
"=" forall a. Doc a -> Doc a -> Doc a
<+>
                  forall a. FilePath -> Doc a
text (IState -> PTerm -> FilePath
showTm IState
i' (IState -> Term -> PTerm
delab IState
i Term
rhs))
process FilePath
fn (TotCheck Name
n)
   = do IState
i <- Idris IState
getIState
        case Name -> Context -> [(Name, Totality)]
lookupNameTotal Name
n (IState -> Context
tt_ctxt IState
i) of
           []  -> FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ FilePath
"Unknown operator " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Name
n
           [(Name, Totality)]
ts  -> do IState
ist <- Idris IState
getIState
                     Bool
c <- Idris Bool
colourise
                     let ppo :: PPOption
ppo =  IState -> PPOption
ppOptionIst IState
ist
                     let showN :: Name -> Doc OutputAnnotation
showN Name
n = forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe FilePath
-> Maybe FilePath
-> OutputAnnotation
AnnName Name
n forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. FilePath -> Doc a
text forall a b. (a -> b) -> a -> b
$
                                   Maybe IState
-> [(Name, Bool)] -> PPOption -> Bool -> Name -> FilePath
showName (forall a. a -> Maybe a
Just IState
ist) [] PPOption
ppo Bool
False Name
n
                     Doc OutputAnnotation -> Idris ()
iRenderResult forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. [Doc a] -> Doc a
vsep forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                      forall a b. (a -> b) -> [a] -> [b]
map (\(Name
n, Totality
t) -> forall a. Int -> Doc a -> Doc a
hang Int
4 forall a b. (a -> b) -> a -> b
$ Name -> Doc OutputAnnotation
showN Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. FilePath -> Doc a
text FilePath
"is" forall a. Doc a -> Doc a -> Doc a
<+> Totality -> IState -> Doc OutputAnnotation
showTotal Totality
t IState
i) forall a b. (a -> b) -> a -> b
$
                      [(Name, Totality)]
ts

process FilePath
fn (DebugUnify PTerm
l PTerm
r)
   = do (Term
ltm, Term
_) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS PTerm
l
        (Term
rtm, Term
_) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS PTerm
r
        Context
ctxt <- Idris Context
getContext
        case Context
-> Env
-> (Term, Maybe Provenance)
-> (Term, Maybe Provenance)
-> [Name]
-> [Name]
-> [Name]
-> [FailContext]
-> TC ([(Name, Term)], Fails)
unify Context
ctxt [] (Term
ltm, forall a. Maybe a
Nothing) (Term
rtm, forall a. Maybe a
Nothing) [] [] [] [] of
             OK ([(Name, Term)], Fails)
ans -> FilePath -> Idris ()
iputStrLn (forall a. Show a => a -> FilePath
show ([(Name, Term)], Fails)
ans)
             Error Err
e -> FilePath -> Idris ()
iputStrLn (forall a. Show a => a -> FilePath
show Err
e)

process FilePath
fn (DebugInfo Name
n)
   = do IState
i <- Idris IState
getIState
        let oi :: [(Name, OptInfo)]
oi = forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n (IState -> Ctxt OptInfo
idris_optimisation IState
i)
        forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Name, OptInfo)]
oi)) forall a b. (a -> b) -> a -> b
$ FilePath -> Idris ()
iputStrLn (forall a. Show a => a -> FilePath
show [(Name, OptInfo)]
oi)
        let si :: [[Bool]]
si = forall a. Name -> Ctxt a -> [a]
lookupCtxt Name
n (IState -> Ctxt [Bool]
idris_statics IState
i)
        forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Bool]]
si)) forall a b. (a -> b) -> a -> b
$ FilePath -> Idris ()
iputStrLn (forall a. Show a => a -> FilePath
show [[Bool]]
si)
        let di :: [TypeInfo]
di = forall a. Name -> Ctxt a -> [a]
lookupCtxt Name
n (IState -> Ctxt TypeInfo
idris_datatypes IState
i)
        forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TypeInfo]
di)) forall a b. (a -> b) -> a -> b
$ FilePath -> Idris ()
iputStrLn (forall a. Show a => a -> FilePath
show [TypeInfo]
di)
        let imps :: [[PArg]]
imps = forall a. Name -> Ctxt a -> [a]
lookupCtxt Name
n (IState -> Ctxt [PArg]
idris_implicits IState
i)
        forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[PArg]]
imps)) forall a b. (a -> b) -> a -> b
$ FilePath -> Idris ()
iputStrLn (forall a. Show a => a -> FilePath
show [[PArg]]
imps)
        let d :: [(Def, Accessibility)]
d = Name -> Bool -> Context -> [(Def, Accessibility)]
lookupDefAcc Name
n Bool
False (IState -> Context
tt_ctxt IState
i)
        forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Def, Accessibility)]
d)) forall a b. (a -> b) -> a -> b
$ FilePath -> Idris ()
iputStrLn forall a b. (a -> b) -> a -> b
$ FilePath
"Definition: " forall a. [a] -> [a] -> [a]
++ (forall a. Show a => a -> FilePath
show (forall a. [a] -> a
head [(Def, Accessibility)]
d))
        IState
i <- Idris IState
getIState
        let cg' :: [(Name, CGInfo)]
cg' = forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n (IState -> Ctxt CGInfo
idris_callgraph IState
i)
        Totality
sc <- Name -> Idris Totality
checkSizeChange Name
n
        FilePath -> Idris ()
iputStrLn forall a b. (a -> b) -> a -> b
$ FilePath
"Size change: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Totality
sc
        let fn :: [(Name, FnInfo)]
fn = forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n (IState -> Ctxt FnInfo
idris_fninfo IState
i)
        forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Name, CGInfo)]
cg')) forall a b. (a -> b) -> a -> b
$ do FilePath -> Idris ()
iputStrLn FilePath
"Call graph:\n"
                                   FilePath -> Idris ()
iputStrLn (forall a. Show a => a -> FilePath
show [(Name, CGInfo)]
cg')
        forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Name, FnInfo)]
fn)) forall a b. (a -> b) -> a -> b
$ FilePath -> Idris ()
iputStrLn (forall a. Show a => a -> FilePath
show [(Name, FnInfo)]
fn)
process FilePath
fn (Search [PkgName]
pkgs PTerm
t) = [PkgName] -> PTerm -> Idris ()
searchByType [PkgName]
pkgs PTerm
t
process FilePath
fn (CaseSplitAt Bool
updatefile Int
l Name
n)
    = FilePath -> Bool -> Int -> Name -> Idris ()
caseSplitAt FilePath
fn Bool
updatefile Int
l Name
n
process FilePath
fn (AddClauseFrom Bool
updatefile Int
l Name
n)
    = FilePath -> Bool -> Int -> Name -> Idris ()
addClauseFrom FilePath
fn Bool
updatefile Int
l Name
n
process FilePath
fn (AddProofClauseFrom Bool
updatefile Int
l Name
n)
    = FilePath -> Bool -> Int -> Name -> Idris ()
addProofClauseFrom FilePath
fn Bool
updatefile Int
l Name
n
process FilePath
fn (AddMissing Bool
updatefile Int
l Name
n)
    = FilePath -> Bool -> Int -> Name -> Idris ()
addMissing FilePath
fn Bool
updatefile Int
l Name
n
process FilePath
fn (MakeWith Bool
updatefile Int
l Name
n)
    = FilePath -> Bool -> Int -> Name -> Idris ()
makeWith FilePath
fn Bool
updatefile Int
l Name
n
process FilePath
fn (MakeCase Bool
updatefile Int
l Name
n)
    = FilePath -> Bool -> Int -> Name -> Idris ()
makeCase FilePath
fn Bool
updatefile Int
l Name
n
process FilePath
fn (MakeLemma Bool
updatefile Int
l Name
n)
    = FilePath -> Bool -> Int -> Name -> Idris ()
makeLemma FilePath
fn Bool
updatefile Int
l Name
n
process FilePath
fn (DoProofSearch Bool
updatefile Bool
rec Int
l Name
n [Name]
hints)
    = FilePath
-> Bool -> Bool -> Int -> Name -> [Name] -> Maybe Int -> Idris ()
doProofSearch FilePath
fn Bool
updatefile Bool
rec Int
l Name
n [Name]
hints forall a. Maybe a
Nothing
process FilePath
fn (Spec PTerm
t)
                    = do (Term
tm, Term
ty) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS PTerm
t
                         Context
ctxt <- Idris Context
getContext
                         IState
ist <- Idris IState
getIState
                         let tm' :: Term
tm' = Context -> Env -> Term -> Term
simplify Context
ctxt [] {- (idris_statics ist) -} Term
tm
                         FilePath -> Idris ()
iPrintResult (forall a. Show a => a -> FilePath
show (IState -> Term -> PTerm
delab IState
ist Term
tm'))

process FilePath
fn (RmProof Name
n')
  = do IState
i <- Idris IState
getIState
       Name
n <- Name -> Idris Name
resolveProof Name
n'
       let proofs :: [(Name, (Bool, [FilePath]))]
proofs = IState -> [(Name, (Bool, [FilePath]))]
proof_list IState
i
       case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
n [(Name, (Bool, [FilePath]))]
proofs of
            Maybe (Bool, [FilePath])
Nothing -> FilePath -> Idris ()
iputStrLn FilePath
"No proof to remove"
            Just (Bool, [FilePath])
_  -> do Name -> Idris ()
removeProof Name
n
                          Name -> Idris ()
insertMetavar Name
n
                          FilePath -> Idris ()
iputStrLn forall a b. (a -> b) -> a -> b
$ FilePath
"Removed proof " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Name
n
                          where
                            insertMetavar :: Name -> Idris ()
                            insertMetavar :: Name -> Idris ()
insertMetavar Name
n =
                              do IState
i <- Idris IState
getIState
                                 let ms :: [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
ms = IState -> [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
idris_metavars IState
i
                                 IState -> Idris ()
putIState forall a b. (a -> b) -> a -> b
$ IState
i { idris_metavars :: [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
idris_metavars = (Name
n, (forall a. Maybe a
Nothing, Int
0, [], Bool
False, Bool
False)) forall a. a -> [a] -> [a]
: [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
ms }

process FilePath
fn' (AddProof Maybe Name
prf)
  = do FilePath
fn <- do
         let fn'' :: FilePath
fn'' = forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Eq a => a -> a -> Bool
/= Char
' ') FilePath
fn'
         Bool
ex <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO Bool
doesFileExist FilePath
fn''
         let fnExt :: FilePath
fnExt = FilePath
fn'' FilePath -> FilePath -> FilePath
<.> FilePath
"idr"
         Bool
exExt <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO Bool
doesFileExist FilePath
fnExt
         if Bool
ex
            then forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
fn''
            else if Bool
exExt
                    then forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
fnExt
                    else forall a. FilePath -> Idris a
ifail forall a b. (a -> b) -> a -> b
$ FilePath
"Neither \""forall a. [a] -> [a] -> [a]
++FilePath
fn''forall a. [a] -> [a] -> [a]
++FilePath
"\" nor \""forall a. [a] -> [a] -> [a]
++FilePath
fnExtforall a. [a] -> [a] -> [a]
++FilePath
"\" exist"
       let fb :: FilePath
fb = FilePath
fn forall a. [a] -> [a] -> [a]
++ FilePath
"~"
       forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath -> IO ()
copyFile FilePath
fn FilePath
fb -- make a backup in case something goes wrong!
       FilePath
prog <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO FilePath
readSource FilePath
fb
       IState
i <- Idris IState
getIState
       let proofs :: [(Name, (Bool, [FilePath]))]
proofs = IState -> [(Name, (Bool, [FilePath]))]
proof_list IState
i
       Name
n' <- case Maybe Name
prf of
                Maybe Name
Nothing -> case [(Name, (Bool, [FilePath]))]
proofs of
                             [] -> forall a. FilePath -> Idris a
ifail FilePath
"No proof to add"
                             ((Name
x, (Bool, [FilePath])
_) : [(Name, (Bool, [FilePath]))]
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return Name
x
                Just Name
nm -> forall (m :: * -> *) a. Monad m => a -> m a
return Name
nm
       Name
n <- Name -> Idris Name
resolveProof Name
n'
       case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
n [(Name, (Bool, [FilePath]))]
proofs of
            Maybe (Bool, [FilePath])
Nothing -> FilePath -> Idris ()
iputStrLn FilePath
"No proof to add"
            Just (Bool
mode, [FilePath]
prf) ->
              do let script :: FilePath
script = if Bool
mode
                                 then Bool -> Name -> [FilePath] -> FilePath
showRunElab (FilePath -> Bool
lit FilePath
fn) Name
n [FilePath]
prf
                                 else Bool -> Name -> [FilePath] -> FilePath
showProof (FilePath -> Bool
lit FilePath
fn) Name
n [FilePath]
prf
                 let prog' :: [FilePath]
prog' = FilePath -> [FilePath] -> [FilePath]
insertScript FilePath
script [FilePath]
ls
                 forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath -> IO ()
writeSource FilePath
fn ([FilePath] -> FilePath
unlines [FilePath]
prog')
                 Name -> Idris ()
removeProof Name
n
                 FilePath -> Idris ()
iputStrLn forall a b. (a -> b) -> a -> b
$ FilePath
"Added proof " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Name
n
             where ls :: [FilePath]
ls = (FilePath -> [FilePath]
lines FilePath
prog)

process FilePath
fn (ShowProof Name
n')
  = do IState
i <- Idris IState
getIState
       Name
n <- Name -> Idris Name
resolveProof Name
n'
       let proofs :: [(Name, (Bool, [FilePath]))]
proofs = IState -> [(Name, (Bool, [FilePath]))]
proof_list IState
i
       case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
n [(Name, (Bool, [FilePath]))]
proofs of
            Maybe (Bool, [FilePath])
Nothing -> FilePath -> Idris ()
iPrintError FilePath
"No proof to show"
            Just (Bool
m, [FilePath]
p)  -> FilePath -> Idris ()
iPrintResult forall a b. (a -> b) -> a -> b
$ if Bool
m
                                             then Bool -> Name -> [FilePath] -> FilePath
showRunElab Bool
False Name
n [FilePath]
p
                                             else Bool -> Name -> [FilePath] -> FilePath
showProof Bool
False Name
n [FilePath]
p

process FilePath
fn (Prove Bool
mode Name
n')
     = do Context
ctxt <- Idris Context
getContext
          IState
ist <- Idris IState
getIState
          let ns :: [Name]
ns = Name -> Context -> [Name]
lookupNames Name
n' Context
ctxt
          let metavars :: [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
metavars = forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (\Name
n -> do (Maybe Name, Int, [Name], Bool, Bool)
c <- forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Name
n (IState -> [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
idris_metavars IState
ist); forall (m :: * -> *) a. Monad m => a -> m a
return (Name
n, (Maybe Name, Int, [Name], Bool, Bool)
c)) [Name]
ns
          Name
n <- case [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
metavars of
              [] -> forall a. Err -> Idris a
ierror (forall t. FilePath -> Err' t
Msg forall a b. (a -> b) -> a -> b
$ FilePath
"Cannot find metavariable " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Name
n')
              [(Name
n, (Maybe Name
_,Int
_,[Name]
_,Bool
False,Bool
_))] -> forall (m :: * -> *) a. Monad m => a -> m a
return Name
n
              [(Name
_, (Maybe Name
_,Int
_,[Name]
_,Bool
_,Bool
False))] -> forall a. Err -> Idris a
ierror (forall t. FilePath -> Err' t
Msg FilePath
"Can't prove this hole as it depends on other holes")
              [(Name
_, (Maybe Name
_,Int
_,[Name]
_,Bool
True,Bool
_))]  -> forall a. Err -> Idris a
ierror (forall t. FilePath -> Err' t
Msg FilePath
"Declarations not solvable using prover")
              [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
ns -> forall a. Err -> Idris a
ierror (forall t. [Name] -> Err' t
CantResolveAlts (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
ns))
          ElabInfo -> Bool -> Bool -> Name -> Idris ()
prover (FilePath -> ElabInfo
toplevelWith FilePath
fn) Bool
mode (FilePath -> Bool
lit FilePath
fn) Name
n
          -- recheck totality
          IState
i <- Idris IState
getIState
          (FC, Name) -> Idris ()
totcheck (FilePath -> FC
fileFC FilePath
"(input)", Name
n)
          forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ (FC
f,Name
n) -> Name -> Totality -> Idris ()
setTotality Name
n Totality
Unchecked) (IState -> [(FC, Name)]
idris_totcheck IState
i)
          forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (FC, Name) -> Idris Totality
checkDeclTotality (IState -> [(FC, Name)]
idris_totcheck IState
i)
          Idris ()
warnTotality
process FilePath
fn (WHNF PTerm
t)
                    = do (Term
tm, Term
ty) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS PTerm
t
                         Context
ctxt <- Idris Context
getContext
                         IState
ist <- Idris IState
getIState
                         let tm' :: Term
tm' = Context -> Env -> Term -> Term
whnf Context
ctxt [] Term
tm
                         let tmArgs' :: Term
tmArgs' = Context -> Env -> Term -> Term
whnfArgs Context
ctxt [] Term
tm
                         FilePath -> Idris ()
iPrintResult forall a b. (a -> b) -> a -> b
$ FilePath
"WHNF: " forall a. [a] -> [a] -> [a]
++ (forall a. Show a => a -> FilePath
show (IState -> Term -> PTerm
delab IState
ist Term
tm'))
                         FilePath -> Idris ()
iPrintResult forall a b. (a -> b) -> a -> b
$ FilePath
"WHNF args: " forall a. [a] -> [a] -> [a]
++ (forall a. Show a => a -> FilePath
show (IState -> Term -> PTerm
delab IState
ist Term
tmArgs'))
process FilePath
fn (TestInline PTerm
t)
                           = do (Term
tm, Term
ty) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS PTerm
t
                                Context
ctxt <- Idris Context
getContext
                                IState
ist <- Idris IState
getIState
                                let tm' :: Term
tm' = IState -> Term -> Term
inlineTerm IState
ist Term
tm
                                Bool
c <- Idris Bool
colourise
                                FilePath -> Idris ()
iPrintResult (IState -> PTerm -> FilePath
showTm IState
ist (IState -> Term -> PTerm
delab IState
ist Term
tm'))
process FilePath
fn (Execute PTerm
tm)
                   = forall a. Idris a -> (Err -> Idris a) -> Idris a
idrisCatch
                       (do IState
ist <- Idris IState
getIState
                           (Term
m_in, Term
_) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS (FC -> PTerm -> PTerm
elabExec FC
fc PTerm
tm)
                           Term
m <- forall term. Optimisable term => term -> Idris term
applyOpts Term
m_in
                           (FilePath
tmpn, Handle
tmph) <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO (FilePath, Handle)
tempfile FilePath
""
                           forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ Handle -> IO ()
hClose Handle
tmph
                           Codegen
t <- Idris Codegen
codegen
                           -- gcc adds .exe when it builds windows programs
                           FilePath
progName <- forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Bool
isWindows then FilePath
tmpn forall a. [a] -> [a] -> [a]
++ FilePath
".exe" else FilePath
tmpn
                           CodegenInfo
ir <- Codegen -> FilePath -> Maybe Term -> Idris CodegenInfo
compile Codegen
t FilePath
tmpn (forall a. a -> Maybe a
Just Term
m)
                           forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ Codegen -> FilePath -> CodegenInfo -> IO ()
generate Codegen
t (forall a b. (a, b) -> a
fst (forall a. [a] -> a
head (IState -> [(FilePath, Bool)]
idris_imported IState
ist))) CodegenInfo
ir
                           case IState -> OutputMode
idris_outputmode IState
ist of
                             RawOutput Handle
h ->
                               do ExitCode
res <- forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ FilePath -> [FilePath] -> IO ExitCode
rawSystem FilePath
progName []
                                  case ExitCode
res of
                                    ExitCode
ExitSuccess -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
                                    ExitFailure Int
err ->
                                      forall a. FilePath -> Idris a
ifail forall a b. (a -> b) -> a -> b
$ FilePath
"Compiled program " forall a. [a] -> [a] -> [a]
++
                                              if Int
err forall a. Ord a => a -> a -> Bool
< Int
0
                                              then FilePath
"was killed by signal " forall a. [a] -> [a] -> [a]
++
                                                   forall a. Show a => a -> FilePath
show (Int
0 forall a. Num a => a -> a -> a
- Int
err)
                                              else FilePath
"terminated with exit code " forall a. [a] -> [a] -> [a]
++
                                                   forall a. Show a => a -> FilePath
show Int
err
                             IdeMode Integer
n Handle
h -> forall a. IO a -> Idris a
runIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> FilePath -> IO ()
hPutStrLn Handle
h forall a b. (a -> b) -> a -> b
$
                                             forall a. SExpable a => FilePath -> a -> Integer -> FilePath
IdeMode.convSExp FilePath
"run-program" FilePath
tmpn Integer
n)
                       (\Err
e -> Idris IState
getIState forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Doc OutputAnnotation -> Idris ()
iRenderError forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip IState -> Err -> Doc OutputAnnotation
pprintErr Err
e)
  where fc :: FC
fc = FilePath -> FC
fileFC FilePath
"main"
process FilePath
fn (Compile Codegen
codegen FilePath
f)
      | forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower (FilePath -> FilePath
takeExtension FilePath
f) forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [FilePath
".idr", FilePath
".lidr", FilePath
".idc"] =
          FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ FilePath
"Invalid filename for compiler output \"" forall a. [a] -> [a] -> [a]
++ FilePath
f forall a. [a] -> [a] -> [a]
++FilePath
"\""
      | Bool
otherwise = do [Opt]
opts <- Idris [Opt]
getCmdLine
                       let iface :: Bool
iface = Opt
Interface forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Opt]
opts
                       let mainname :: Name
mainname = Name -> [FilePath] -> Name
sNS (FilePath -> Name
sUN FilePath
"main") [FilePath
"Main"]

                       Maybe Term
m <- if Bool
iface then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing else
                            do (Term
m', Term
_) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"compiler")) ElabMode
ERHS
                                            (FC -> PTerm -> [PArg] -> PTerm
PApp FC
fc (FC -> [FC] -> Name -> PTerm
PRef FC
fc [] (FilePath -> Name
sUN FilePath
"run__IO"))
                                            [forall {t}. t -> PArg' t
pexp forall a b. (a -> b) -> a -> b
$ FC -> [FC] -> Name -> PTerm
PRef FC
fc [] Name
mainname])
                               forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just Term
m')
                       CodegenInfo
ir <- Codegen -> FilePath -> Maybe Term -> Idris CodegenInfo
compile Codegen
codegen FilePath
f Maybe Term
m
                       IState
i <- Idris IState
getIState
                       let ir' :: CodegenInfo
ir' = CodegenInfo
ir {interfaces :: Bool
interfaces = Bool
iface}
                       forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ Codegen -> FilePath -> CodegenInfo -> IO ()
generate Codegen
codegen (forall a b. (a, b) -> a
fst (forall a. [a] -> a
head (IState -> [(FilePath, Bool)]
idris_imported IState
i))) CodegenInfo
ir'
  where fc :: FC
fc = FilePath -> FC
fileFC FilePath
"main"
process FilePath
fn (LogLvl Int
i) = Int -> Idris ()
setLogLevel Int
i
process FilePath
fn (LogCategory [LogCat]
cs) = [LogCat] -> Idris ()
setLogCats [LogCat]
cs
-- Elaborate as if LHS of a pattern (debug command)
process FilePath
fn (Pattelab PTerm
t)
     = do (Term
tm, Term
ty) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ELHS PTerm
t
          FilePath -> Idris ()
iPrintResult forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> FilePath
show Term
tm forall a. [a] -> [a] -> [a]
++ FilePath
"\n\n : " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Term
ty

process FilePath
fn (Missing Name
n)
    = do IState
i <- Idris IState
getIState
         PPOption
ppOpts <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IState -> PPOption
ppOptionIst Idris IState
getIState
         case forall a. Name -> Ctxt a -> [a]
lookupCtxt Name
n (IState -> Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
idris_patdefs IState
i) of
           [] -> FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ FilePath
"Unknown name " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Name
n
           [([([(Name, Term)], Term, Term)]
_, [PTerm]
tms)] ->
             Doc OutputAnnotation -> Idris ()
iRenderResult (forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm PPOption
ppOpts
                                                   []
                                                   []
                                                   (IState -> [FixDecl]
idris_infixes IState
i))
                                      [PTerm]
tms))
           [([([(Name, Term)], Term, Term)], [PTerm])]
_ -> FilePath -> Idris ()
iPrintError FilePath
"Ambiguous name"
process FilePath
fn (DynamicLink FilePath
l)
                           = do IState
i <- Idris IState
getIState
                                let importdirs :: [FilePath]
importdirs = IOption -> [FilePath]
opt_importdirs (IState -> IOption
idris_options IState
i)
                                    lib :: FilePath
lib = FilePath -> FilePath
trim FilePath
l
                                Maybe DynamicLib
handle <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath -> IO (Maybe DynamicLib)
tryLoadLib [FilePath]
importdirs FilePath
lib
                                case Maybe DynamicLib
handle of
                                  Maybe DynamicLib
Nothing -> FilePath -> Idris ()
iPrintError forall a b. (a -> b) -> a -> b
$ FilePath
"Could not load dynamic lib \"" forall a. [a] -> [a] -> [a]
++ FilePath
l forall a. [a] -> [a] -> [a]
++ FilePath
"\""
                                  Just DynamicLib
x -> do let libs :: [DynamicLib]
libs = IState -> [DynamicLib]
idris_dynamic_libs IState
i
                                               if DynamicLib
x forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [DynamicLib]
libs
                                                  then do Int -> FilePath -> Idris ()
logParser Int
1 (FilePath
"Tried to load duplicate library " forall a. [a] -> [a] -> [a]
++ DynamicLib -> FilePath
lib_name DynamicLib
x)
                                                          forall (m :: * -> *) a. Monad m => a -> m a
return ()
                                                  else IState -> Idris ()
putIState forall a b. (a -> b) -> a -> b
$ IState
i { idris_dynamic_libs :: [DynamicLib]
idris_dynamic_libs = DynamicLib
xforall a. a -> [a] -> [a]
:[DynamicLib]
libs }
    where trim :: FilePath -> FilePath
trim = forall a. [a] -> [a]
reverse forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. [a] -> [a]
reverse forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace
process FilePath
fn Command
ListDynamic
                       = do IState
i <- Idris IState
getIState
                            FilePath -> Idris ()
iputStrLn FilePath
"Dynamic libraries:"
                            [DynamicLib] -> Idris ()
showLibs forall a b. (a -> b) -> a -> b
$ IState -> [DynamicLib]
idris_dynamic_libs IState
i
    where showLibs :: [DynamicLib] -> Idris ()
showLibs []                = forall (m :: * -> *) a. Monad m => a -> m a
return ()
          showLibs ((Lib FilePath
name DL
_):[DynamicLib]
ls) = do FilePath -> Idris ()
iputStrLn forall a b. (a -> b) -> a -> b
$ FilePath
"\t" forall a. [a] -> [a] -> [a]
++ FilePath
name; [DynamicLib] -> Idris ()
showLibs [DynamicLib]
ls
process FilePath
fn Command
Metavars
                 = do IState
ist <- Idris IState
getIState
                      let mvs :: [Name]
mvs = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst (IState -> [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
idris_metavars IState
ist) forall a. Eq a => [a] -> [a] -> [a]
\\ [Name]
primDefs
                      case [Name]
mvs of
                        [] -> FilePath -> Idris ()
iPrintError FilePath
"No global holes to solve"
                        [Name]
_ -> FilePath -> Idris ()
iPrintResult forall a b. (a -> b) -> a -> b
$ FilePath
"Global holes:\n\t" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show [Name]
mvs
process FilePath
fn Command
NOP      = forall (m :: * -> *) a. Monad m => a -> m a
return ()

process FilePath
fn (SetOpt   Opt
ErrContext)  = Bool -> Idris ()
setErrContext Bool
True
process FilePath
fn (UnsetOpt Opt
ErrContext)  = Bool -> Idris ()
setErrContext Bool
False
process FilePath
fn (SetOpt Opt
ShowImpl)      = Bool -> Idris ()
setImpShow Bool
True
process FilePath
fn (UnsetOpt Opt
ShowImpl)    = Bool -> Idris ()
setImpShow Bool
False
process FilePath
fn (SetOpt Opt
ShowOrigErr)   = Bool -> Idris ()
setShowOrigErr Bool
True
process FilePath
fn (UnsetOpt Opt
ShowOrigErr) = Bool -> Idris ()
setShowOrigErr Bool
False
process FilePath
fn (SetOpt Opt
AutoSolve)     = Bool -> Idris ()
setAutoSolve Bool
True
process FilePath
fn (UnsetOpt Opt
AutoSolve)   = Bool -> Idris ()
setAutoSolve Bool
False
process FilePath
fn (SetOpt Opt
NoBanner)      = Bool -> Idris ()
setNoBanner Bool
True
process FilePath
fn (UnsetOpt Opt
NoBanner)    = Bool -> Idris ()
setNoBanner Bool
False
process FilePath
fn (SetOpt Opt
WarnReach)     = forall s (m :: * -> *) a.
MonadState s m =>
Field s a -> (a -> a) -> m ()
fmodifyState Field IState [Opt]
opts_idrisCmdline forall a b. (a -> b) -> a -> b
$ forall a. Eq a => [a] -> [a]
nub forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Opt
WarnReachforall a. a -> [a] -> [a]
:)
process FilePath
fn (UnsetOpt Opt
WarnReach)   = forall s (m :: * -> *) a.
MonadState s m =>
Field s a -> (a -> a) -> m ()
fmodifyState Field IState [Opt]
opts_idrisCmdline forall a b. (a -> b) -> a -> b
$ forall a. Eq a => a -> [a] -> [a]
delete Opt
WarnReach
process FilePath
fn (SetOpt Opt
EvalTypes)     = Bool -> Idris ()
setEvalTypes Bool
True
process FilePath
fn (UnsetOpt Opt
EvalTypes)   = Bool -> Idris ()
setEvalTypes Bool
False

process FilePath
fn (SetOpt Opt
DesugarNats)   = Bool -> Idris ()
setDesugarNats Bool
True
process FilePath
fn (UnsetOpt Opt
DesugarNats) = Bool -> Idris ()
setDesugarNats Bool
False

process FilePath
fn (SetOpt Opt
_) = FilePath -> Idris ()
iPrintError FilePath
"Not a valid option"
process FilePath
fn (UnsetOpt Opt
_) = FilePath -> Idris ()
iPrintError FilePath
"Not a valid option"
process FilePath
fn (SetColour ColourType
ty IdrisColour
c) = ColourType -> IdrisColour -> Idris ()
setColour ColourType
ty IdrisColour
c
process FilePath
fn Command
ColourOn
                    = do IState
ist <- Idris IState
getIState
                         IState -> Idris ()
putIState forall a b. (a -> b) -> a -> b
$ IState
ist { idris_colourRepl :: Bool
idris_colourRepl = Bool
True }
process FilePath
fn Command
ColourOff
                     = do IState
ist <- Idris IState
getIState
                          IState -> Idris ()
putIState forall a b. (a -> b) -> a -> b
$ IState
ist { idris_colourRepl :: Bool
idris_colourRepl = Bool
False }
process FilePath
fn Command
ListErrorHandlers =
  do IState
ist <- Idris IState
getIState
     FilePath -> Idris ()
iPrintResult forall a b. (a -> b) -> a -> b
$ case IState -> [Name]
idris_errorhandlers IState
ist of
       []       -> FilePath
"No registered error handlers"
       [Name]
handlers -> FilePath
"Registered error handlers: " forall a. [a] -> [a] -> [a]
++ (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. a -> [a] -> [a]
intersperse FilePath
", " forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (a -> b) -> [a] -> [b]
map forall a. Show a => a -> FilePath
show) [Name]
handlers
process FilePath
fn (SetConsoleWidth ConsoleWidth
w) = ConsoleWidth -> Idris ()
setWidth ConsoleWidth
w
process FilePath
fn (SetPrinterDepth Maybe Int
d) = Maybe Int -> Idris ()
setDepth Maybe Int
d
process FilePath
fn (Apropos [PkgName]
pkgs FilePath
a) =
  do IState
orig <- Idris IState
getIState
     forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PkgName]
pkgs)) forall a b. (a -> b) -> a -> b
$
       FilePath -> Idris ()
iputStrLn forall a b. (a -> b) -> a -> b
$ FilePath
"Searching packages: " forall a. [a] -> [a] -> [a]
++ FilePath -> [FilePath] -> FilePath
showSep FilePath
", " (forall a b. (a -> b) -> [a] -> [b]
map forall a. Show a => a -> FilePath
show [PkgName]
pkgs)
     forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ PkgName -> Idris ()
loadPkgIndex [PkgName]
pkgs
     IState
ist <- Idris IState
getIState
     let mods :: [(FilePath, Docstring DocTerm)]
mods = IState -> Text -> [(FilePath, Docstring DocTerm)]
aproposModules IState
ist (FilePath -> Text
T.pack FilePath
a)
     let names :: [Name]
names = IState -> Text -> [Name]
apropos IState
ist (FilePath -> Text
T.pack FilePath
a)
     let aproposInfo :: [(Name, PTerm, Maybe (Docstring DocTerm))]
aproposInfo = [ (Name
n,
                          IState -> Name -> PTerm
delabTy IState
ist Name
n,
                          forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. Docstring a -> Docstring a
overview forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (a, b) -> a
fst) (forall a. Name -> Ctxt a -> Maybe a
lookupCtxtExact Name
n (IState -> Ctxt (Docstring DocTerm, [(Name, Docstring DocTerm)])
idris_docstrings IState
ist)))
                       | Name
n <- forall a. Ord a => [a] -> [a]
sort [Name]
names, Name -> Bool
isUN Name
n ]
     if (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(FilePath, Docstring DocTerm)]
mods)) Bool -> Bool -> Bool
|| (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Name, PTerm, Maybe (Docstring DocTerm))]
aproposInfo))
        then Doc OutputAnnotation -> Idris ()
iRenderResult forall a b. (a -> b) -> a -> b
$ forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (\(FilePath
m, Docstring DocTerm
d) -> forall a. FilePath -> Doc a
text FilePath
"Module" forall a. Doc a -> Doc a -> Doc a
<+> forall a. FilePath -> Doc a
text FilePath
m forall a. Doc a -> Doc a -> Doc a
<$>
                                                   IState -> Docstring DocTerm -> Doc OutputAnnotation
ppD IState
ist Docstring DocTerm
d forall a. Doc a -> Doc a -> Doc a
<> forall a. Doc a
line) [(FilePath, Docstring DocTerm)]
mods) forall a. Doc a -> Doc a -> Doc a
<$>
                             forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (IState
-> (Name, PTerm, Maybe (Docstring DocTerm)) -> Doc OutputAnnotation
prettyDocumentedIst IState
ist) [(Name, PTerm, Maybe (Docstring DocTerm))]
aproposInfo)
        else Doc OutputAnnotation -> Idris ()
iRenderError forall a b. (a -> b) -> a -> b
$ forall a. FilePath -> Doc a
text FilePath
"No results found"
  where isUN :: Name -> Bool
isUN (UN Text
_) = Bool
True
        isUN (NS Name
n [Text]
_) = Name -> Bool
isUN Name
n
        isUN Name
_ = Bool
False
        ppD :: IState -> Docstring DocTerm -> Doc OutputAnnotation
ppD IState
ist = forall a.
(a -> FilePath -> Doc OutputAnnotation)
-> Docstring a -> Doc OutputAnnotation
renderDocstring ((Term -> Doc OutputAnnotation)
-> (Term -> Term) -> DocTerm -> FilePath -> Doc OutputAnnotation
renderDocTerm (IState -> Term -> Doc OutputAnnotation
pprintDelab IState
ist) (Context -> Env -> Term -> Term
normaliseAll (IState -> Context
tt_ctxt IState
ist) []))


process FilePath
fn (WhoCalls Name
n) =
  do [(Name, [Name])]
calls <- Name -> Idris [(Name, [Name])]
whoCalls Name
n
     IState
ist <- Idris IState
getIState
     Doc OutputAnnotation -> Idris ()
iRenderResult forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. [Doc a] -> Doc a
vsep forall a b. (a -> b) -> a -> b
$
       forall a b. (a -> b) -> [a] -> [b]
map (\(Name
n, [Name]
ns) ->
             forall a. FilePath -> Doc a
text FilePath
"Callers of" forall a. Doc a -> Doc a -> Doc a
<+> Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
True [] Name
n forall a. Doc a -> Doc a -> Doc a
<$>
             forall a. Int -> Doc a -> Doc a
indent Int
1 (forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map ((forall a. FilePath -> Doc a
text FilePath
"*" forall a. Doc a -> Doc a -> Doc a
<+>) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Doc a -> Doc a
align forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
True []) [Name]
ns)))
           [(Name, [Name])]
calls

process FilePath
fn (CallsWho Name
n) =
  do [(Name, [Name])]
calls <- Name -> Idris [(Name, [Name])]
callsWho Name
n
     IState
ist <- Idris IState
getIState
     Doc OutputAnnotation -> Idris ()
iRenderResult forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. [Doc a] -> Doc a
vsep forall a b. (a -> b) -> a -> b
$
       forall a b. (a -> b) -> [a] -> [b]
map (\(Name
n, [Name]
ns) ->
             Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
True [] Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. FilePath -> Doc a
text FilePath
"calls:" forall a. Doc a -> Doc a -> Doc a
<$>
             forall a. Int -> Doc a -> Doc a
indent Int
1 (forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map ((forall a. FilePath -> Doc a
text FilePath
"*" forall a. Doc a -> Doc a -> Doc a
<+>) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Doc a -> Doc a
align forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
True []) [Name]
ns)))
           [(Name, [Name])]
calls

process FilePath
fn (Browse [FilePath]
ns) =
  do [[FilePath]]
underNSs <- [FilePath] -> Idris [[FilePath]]
namespacesInNS [FilePath]
ns
     [Name]
names <- [FilePath] -> Idris [Name]
namesInNS [FilePath]
ns
     if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[FilePath]]
underNSs Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Name]
names
        then FilePath -> Idris ()
iPrintError FilePath
"Invalid or empty namespace"
        else do IState
ist <- Idris IState
getIState
                Doc OutputAnnotation -> Idris ()
iRenderResult forall a b. (a -> b) -> a -> b
$
                  forall a. FilePath -> Doc a
text FilePath
"Namespaces:" forall a. Doc a -> Doc a -> Doc a
<$>
                  forall a. Int -> Doc a -> Doc a
indent Int
2 (forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. FilePath -> Doc a
text forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> [FilePath] -> FilePath
showSep FilePath
".") [[FilePath]]
underNSs)) forall a. Doc a -> Doc a -> Doc a
<$>
                  forall a. FilePath -> Doc a
text FilePath
"Names:" forall a. Doc a -> Doc a -> Doc a
<$>
                  forall a. Int -> Doc a -> Doc a
indent Int
2 (forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (\Name
n -> Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
False [] Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon forall a. Doc a -> Doc a -> Doc a
<+>
                                             (forall a. Doc a -> Doc a
group forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Doc a -> Doc a
align forall a b. (a -> b) -> a -> b
$ IState -> Name -> Doc OutputAnnotation
pprintDelabTy IState
ist Name
n))
                                      [Name]
names))

-- IdrisDoc
process FilePath
fn (MakeDoc FilePath
s) =
  do     IState
istate        <- Idris IState
getIState
         let names :: [FilePath]
names      = FilePath -> [FilePath]
words FilePath
s
             parse :: FilePath -> Either FilePath Name
parse FilePath
n    | Right Name
x <- forall st res.
Parser st res
-> st -> FilePath -> FilePath -> Either ParseError res
runparser forall (m :: * -> *). (Parsing m, MonadState IState m) => m Name
name IState
istate FilePath
fn FilePath
n = forall a b. b -> Either a b
Right Name
x
             parse FilePath
n    = forall a b. a -> Either a b
Left FilePath
n
             ([FilePath]
bad, [Name]
nss) = forall a b. [Either a b] -> ([a], [b])
partitionEithers forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map FilePath -> Either FilePath Name
parse [FilePath]
names
         FilePath
cd            <- forall a. IO a -> Idris a
runIO IO FilePath
getCurrentDirectory
         let outputDir :: FilePath
outputDir  = FilePath
cd FilePath -> FilePath -> FilePath
</> FilePath
"doc"
         Either FilePath ()
result        <- if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FilePath]
bad then forall a. IO a -> Idris a
runIO forall a b. (a -> b) -> a -> b
$ IState -> [Name] -> FilePath -> IO (Either FilePath ())
generateDocs IState
istate [Name]
nss FilePath
outputDir
                                      else forall (m :: * -> *) a. Monad m => a -> m a
return forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ FilePath
"Illegal name: " forall a. [a] -> [a] -> [a]
++ forall a. [a] -> a
head [FilePath]
bad
         case Either FilePath ()
result of Right ()
_   -> FilePath -> Idris ()
iputStrLn FilePath
"IdrisDoc generated"
                        Left  FilePath
err -> FilePath -> Idris ()
iPrintError FilePath
err
process FilePath
fn (PrintDef Name
n) =
  do [Doc OutputAnnotation]
result <- Bool -> Name -> Idris [Doc OutputAnnotation]
pprintDef Bool
False Name
n
     case [Doc OutputAnnotation]
result of
       [] -> FilePath -> Idris ()
iPrintError FilePath
"Not found"
       [Doc OutputAnnotation]
outs -> Doc OutputAnnotation -> Idris ()
iRenderResult forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. [Doc a] -> Doc a
vsep forall a b. (a -> b) -> a -> b
$ [Doc OutputAnnotation]
outs

-- Show relevant transformation rules for the name 'n'
process FilePath
fn (TransformInfo Name
n)
   = do IState
i <- Idris IState
getIState
        let ts :: [[(Term, Term)]]
ts = forall a. Name -> Ctxt a -> [a]
lookupCtxt Name
n (IState -> Ctxt [(Term, Term)]
idris_transforms IState
i)
        let res :: [[Doc OutputAnnotation]]
res = forall a b. (a -> b) -> [a] -> [b]
map (IState -> [(Term, Term)] -> [Doc OutputAnnotation]
showTrans IState
i) [[(Term, Term)]]
ts
        Doc OutputAnnotation -> Idris ()
iRenderResult forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. [Doc a] -> Doc a
vsep forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Doc OutputAnnotation]]
res
    where showTrans :: IState -> [(Term, Term)] -> [Doc OutputAnnotation]
          showTrans :: IState -> [(Term, Term)] -> [Doc OutputAnnotation]
showTrans IState
i [] = []
          showTrans IState
i ((Term
lhs, Term
rhs) : [(Term, Term)]
ts)
              = let ppTm :: Term -> Doc OutputAnnotation
ppTm Term
tm = forall a. a -> Doc a -> Doc a
annotate ([(Name, Bool)] -> Term -> OutputAnnotation
AnnTerm [] Term
tm) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                                 PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm (IState -> PPOption
ppOptionIst IState
i) [] [] [] forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                                 IState -> Term -> PTerm
delab IState
i forall a b. (a -> b) -> a -> b
$ Term
tm
                    ts' :: [Doc OutputAnnotation]
ts' = IState -> [(Term, Term)] -> [Doc OutputAnnotation]
showTrans IState
i [(Term, Term)]
ts in
                    Term -> Doc OutputAnnotation
ppTm Term
lhs forall a. Doc a -> Doc a -> Doc a
<+> forall a. FilePath -> Doc a
text FilePath
" ==> " forall a. Doc a -> Doc a -> Doc a
<+> Term -> Doc OutputAnnotation
ppTm Term
rhs forall a. a -> [a] -> [a]
: [Doc OutputAnnotation]
ts'

process FilePath
fn (PPrint OutputFmt
fmt Int
width (PRef FC
_ [FC]
_ Name
n))
   = do [Doc OutputAnnotation]
outs <- Bool -> Name -> Idris [Doc OutputAnnotation]
pprintDef Bool
False Name
n
        FilePath -> Idris ()
iPrintResult forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< OutputFmt -> Int -> Doc OutputAnnotation -> Idris FilePath
renderExternal OutputFmt
fmt Int
width (forall a. [Doc a] -> Doc a
vsep [Doc OutputAnnotation]
outs)


process FilePath
fn (PPrint OutputFmt
fmt Int
width PTerm
t)
   = do (Term
tm, Term
ty) <- ElabInfo -> ElabMode -> PTerm -> Idris (Term, Term)
elabVal (FC -> ElabInfo
recinfo (FilePath -> FC
fileFC FilePath
"toplevel")) ElabMode
ERHS PTerm
t
        IState
ist <- Idris IState
getIState
        FilePath -> Idris ()
iPrintResult forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< OutputFmt -> Int -> Doc OutputAnnotation -> Idris FilePath
renderExternal OutputFmt
fmt Int
width (IState -> Term -> Doc OutputAnnotation
pprintDelab IState
ist Term
tm)


process FilePath
fn Command
Quit = FilePath -> Idris ()
iPrintError FilePath
"Command ':quit' is currently unsupported"
process FilePath
fn Command
Reload = FilePath -> Idris ()
iPrintError FilePath
"Command ':reload' is currently unsupported"
process FilePath
fn Command
Watch = FilePath -> Idris ()
iPrintError FilePath
"Command ':watch' is currently unsupported"
process FilePath
fn (Load FilePath
_ Maybe Int
_) = FilePath -> Idris ()
iPrintError FilePath
"Command ':load' is currently unsupported"
process FilePath
fn Command
Edit = FilePath -> Idris ()
iPrintError FilePath
"Command ':edit' is currently unsupported"
process FilePath
fn Command
Proofs = FilePath -> Idris ()
iPrintError FilePath
"Command ':proofs' is currently unsupported"
process FilePath
fn (Verbosity Int
_)
   = FilePath -> Idris ()
iPrintError FilePath
"Command ':verbosity' is currently unsupported"


showTotal :: Totality -> IState -> Doc OutputAnnotation
showTotal :: Totality -> IState -> Doc OutputAnnotation
showTotal t :: Totality
t@(Partial (Other [Name]
ns)) IState
i
   = forall a. FilePath -> Doc a
text FilePath
"possibly not total due to:" forall a. Doc a -> Doc a -> Doc a
<$>
     forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (IState -> Name -> Doc OutputAnnotation
showTotalN IState
i) [Name]
ns)
showTotal t :: Totality
t@(Partial (Mutual [Name]
ns)) IState
i
   = forall a. FilePath -> Doc a
text FilePath
"possibly not total due to recursive path:" forall a. Doc a -> Doc a -> Doc a
<$>
     forall a. Doc a -> Doc a
align (forall a. Doc a -> Doc a
group (forall a. [Doc a] -> Doc a
vsep (forall a. Doc a -> [Doc a] -> [Doc a]
punctuate forall a. Doc a
comma
       (forall a b. (a -> b) -> [a] -> [b]
map (\Name
n -> forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe FilePath
-> Maybe FilePath
-> OutputAnnotation
AnnName Name
n forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing) forall a b. (a -> b) -> a -> b
$
                   forall a. FilePath -> Doc a
text (forall a. Show a => a -> FilePath
show Name
n))
            [Name]
ns))))
showTotal Totality
t IState
i = forall a. FilePath -> Doc a
text (forall a. Show a => a -> FilePath
show Totality
t)

showTotalN :: IState -> Name -> Doc OutputAnnotation
showTotalN :: IState -> Name -> Doc OutputAnnotation
showTotalN IState
ist Name
n = case Name -> Context -> [Totality]
lookupTotal Name
n (IState -> Context
tt_ctxt IState
ist) of
                        [Totality
t] -> Name -> Doc OutputAnnotation
showN Name
n forall a. Doc a -> Doc a -> Doc a
<> forall a. FilePath -> Doc a
text FilePath
", which is" forall a. Doc a -> Doc a -> Doc a
<+> Totality -> IState -> Doc OutputAnnotation
showTotal Totality
t IState
ist
                        [Totality]
_ -> forall a. Doc a
empty
    where
       ppo :: PPOption
ppo = IState -> PPOption
ppOptionIst IState
ist
       showN :: Name -> Doc OutputAnnotation
showN Name
n = forall a. a -> Doc a -> Doc a
annotate (Name
-> Maybe NameOutput
-> Maybe FilePath
-> Maybe FilePath
-> OutputAnnotation
AnnName Name
n forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. FilePath -> Doc a
text forall a b. (a -> b) -> a -> b
$
                 Maybe IState
-> [(Name, Bool)] -> PPOption -> Bool -> Name -> FilePath
showName (forall a. a -> Maybe a
Just IState
ist) [] PPOption
ppo Bool
False Name
n

displayHelp :: FilePath
displayHelp = let vstr :: FilePath
vstr = Version -> FilePath
showVersion Version
getIdrisVersionNoGit in
              FilePath
"\nIdris version " forall a. [a] -> [a] -> [a]
++ FilePath
vstr forall a. [a] -> [a] -> [a]
++ FilePath
"\n" forall a. [a] -> [a] -> [a]
++
              FilePath
"--------------" forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (\Char
x -> Char
'-') FilePath
vstr forall a. [a] -> [a] -> [a]
++ FilePath
"\n\n" forall a. [a] -> [a] -> [a]
++
              forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall {a}. Show a => ([FilePath], a, FilePath) -> FilePath
cmdInfo [([FilePath], CmdArg, FilePath)]
helphead forall a. [a] -> [a] -> [a]
++
              forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall {a}. Show a => ([FilePath], a, FilePath) -> FilePath
cmdInfo [([FilePath], CmdArg, FilePath)]
help
  where cmdInfo :: ([FilePath], a, FilePath) -> FilePath
cmdInfo ([FilePath]
cmds, a
args, FilePath
text) = FilePath
"   " forall a. [a] -> [a] -> [a]
++ Int -> Int -> FilePath -> FilePath -> FilePath -> FilePath
col Int
16 Int
12 (FilePath -> [FilePath] -> FilePath
showSep FilePath
" " [FilePath]
cmds) (forall a. Show a => a -> FilePath
show a
args) FilePath
text
        col :: Int -> Int -> FilePath -> FilePath -> FilePath -> FilePath
col Int
c1 Int
c2 FilePath
l FilePath
m FilePath
r =
            FilePath
l forall a. [a] -> [a] -> [a]
++ forall a. Int -> [a] -> [a]
take (Int
c1 forall a. Num a => a -> a -> a
- forall (t :: * -> *) a. Foldable t => t a -> Int
length FilePath
l) (forall a. a -> [a]
repeat Char
' ') forall a. [a] -> [a] -> [a]
++
            FilePath
m forall a. [a] -> [a] -> [a]
++ forall a. Int -> [a] -> [a]
take (Int
c2 forall a. Num a => a -> a -> a
- forall (t :: * -> *) a. Foldable t => t a -> Int
length FilePath
m) (forall a. a -> [a]
repeat Char
' ') forall a. [a] -> [a] -> [a]
++ FilePath
r forall a. [a] -> [a] -> [a]
++ FilePath
"\n"

pprintDef :: Bool -> Name -> Idris [Doc OutputAnnotation]
pprintDef :: Bool -> Name -> Idris [Doc OutputAnnotation]
pprintDef Bool
asCore Name
n =
  do IState
ist <- Idris IState
getIState
     Context
ctxt <- Idris Context
getContext
     let ambiguous :: Bool
ambiguous = forall (t :: * -> *) a. Foldable t => t a -> Int
length (Name -> Context -> [Name]
lookupNames Name
n Context
ctxt) forall a. Ord a => a -> a -> Bool
> Int
1
         patdefs :: Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
patdefs = IState -> Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
idris_patdefs IState
ist
         tyinfo :: Ctxt TypeInfo
tyinfo = IState -> Ctxt TypeInfo
idris_datatypes IState
ist
     if Bool
asCore
       then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (IState
-> (Name, ([([(Name, Term)], Term, Term)], [PTerm]))
-> Doc OutputAnnotation
ppCoreDef IState
ist) (forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
patdefs)
       else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (Bool
-> IState
-> (Name, ([([(Name, Term)], Term, Term)], [PTerm]))
-> Doc OutputAnnotation
ppDef Bool
ambiguous IState
ist) (forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
patdefs) forall a. [a] -> [a] -> [a]
++
                     forall a b. (a -> b) -> [a] -> [b]
map (Bool -> IState -> (Name, TypeInfo) -> Doc OutputAnnotation
ppTy Bool
ambiguous IState
ist) (forall a. Name -> Ctxt a -> [(Name, a)]
lookupCtxtName Name
n Ctxt TypeInfo
tyinfo) forall a. [a] -> [a] -> [a]
++
                     forall a b. (a -> b) -> [a] -> [b]
map (Bool -> IState -> Name -> Doc OutputAnnotation
ppCon Bool
ambiguous IState
ist) (forall a. (a -> Bool) -> [a] -> [a]
filter (forall a b c. (a -> b -> c) -> b -> a -> c
flip Name -> Context -> Bool
isDConName Context
ctxt) (Name -> Context -> [Name]
lookupNames Name
n Context
ctxt))
  where ppCoreDef :: IState -> (Name, ([([(Name, Term)], Term, Term)], [PTerm])) -> Doc OutputAnnotation
        ppCoreDef :: IState
-> (Name, ([([(Name, Term)], Term, Term)], [PTerm]))
-> Doc OutputAnnotation
ppCoreDef IState
ist (Name
n, ([([(Name, Term)], Term, Term)]
clauses, [PTerm]
missing)) =
          case Name -> Context -> [Term]
lookupTy Name
n (IState -> Context
tt_ctxt IState
ist) of
            [] -> forall a. HasCallStack => FilePath -> a
error FilePath
"Attempted pprintDef of TT of thing that doesn't exist"
            (Term
ty:[Term]
_) -> Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
True [] Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon forall a. Doc a -> Doc a -> Doc a
<+>
                      forall a. Doc a -> Doc a
align (forall a. a -> Doc a -> Doc a
annotate ([(Name, Bool)] -> Term -> OutputAnnotation
AnnTerm [] Term
ty) ([Name] -> Term -> Doc OutputAnnotation
pprintTT [] Term
ty)) forall a. Doc a -> Doc a -> Doc a
<$>
                      forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (\([(Name, Term)]
vars, Term
lhs, Term
rhs) ->  [(Name, Term)] -> Term -> Term -> Doc OutputAnnotation
pprintTTClause [(Name, Term)]
vars Term
lhs Term
rhs) [([(Name, Term)], Term, Term)]
clauses)
        ppDef :: Bool -> IState -> (Name, ([([(Name, Term)], Term, Term)], [PTerm])) -> Doc OutputAnnotation
        ppDef :: Bool
-> IState
-> (Name, ([([(Name, Term)], Term, Term)], [PTerm]))
-> Doc OutputAnnotation
ppDef Bool
amb IState
ist (Name
n, ([([(Name, Term)], Term, Term)]
clauses, [PTerm]
missing)) =
          Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
amb [] Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon forall a. Doc a -> Doc a -> Doc a
<+>
          forall a. Doc a -> Doc a
align (IState -> Name -> Doc OutputAnnotation
pprintDelabTy IState
ist Name
n) forall a. Doc a -> Doc a -> Doc a
<$>
          IState -> [([(Name, Term)], Term, Term)] -> Doc OutputAnnotation
ppClauses IState
ist [([(Name, Term)], Term, Term)]
clauses forall a. Doc a -> Doc a -> Doc a
<> forall {p} {a}. p -> Doc a
ppMissing [PTerm]
missing
        ppClauses :: IState -> [([(Name, Term)], Term, Term)] -> Doc OutputAnnotation
ppClauses IState
ist [] = forall a. FilePath -> Doc a
text FilePath
"No clauses."
        ppClauses IState
ist [([(Name, Term)], Term, Term)]
cs = forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map ([(Name, Term)], Term, Term) -> Doc OutputAnnotation
pp [([(Name, Term)], Term, Term)]
cs)
          where pp :: ([(Name, Term)], Term, Term) -> Doc OutputAnnotation
pp ([(Name, Term)]
varTys, Term
lhs, Term
rhs) =
                  let vars :: [Name]
vars = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(Name, Term)]
varTys
                      ppTm :: Term -> Doc OutputAnnotation
ppTm Term
t = forall a. a -> Doc a -> Doc a
annotate ([(Name, Bool)] -> Term -> OutputAnnotation
AnnTerm (forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
vars (forall a. a -> [a]
repeat Bool
False)) Term
t) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                               PPOption
-> [(Name, Bool)]
-> [Name]
-> [FixDecl]
-> PTerm
-> Doc OutputAnnotation
pprintPTerm (IState -> PPOption
ppOptionIst IState
ist)
                                     (forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
vars (forall a. a -> [a]
repeat Bool
False))
                                     [] (IState -> [FixDecl]
idris_infixes IState
ist) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
                               IState -> [(Name, Term)] -> Term -> PTerm
delabWithEnv IState
ist [(Name, Term)]
varTys forall a b. (a -> b) -> a -> b
$
                               Term
t
                  in forall a. Doc a -> Doc a
group forall a b. (a -> b) -> a -> b
$ Term -> Doc OutputAnnotation
ppTm Term
lhs forall a. Doc a -> Doc a -> Doc a
<+> forall a. FilePath -> Doc a
text FilePath
"=" forall a. Doc a -> Doc a -> Doc a
<$> (forall a. Doc a -> Doc a
group forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Doc a -> Doc a
align forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Int -> Doc a -> Doc a
hang Int
2 forall a b. (a -> b) -> a -> b
$ Term -> Doc OutputAnnotation
ppTm Term
rhs)
        ppMissing :: p -> Doc a
ppMissing p
_ = forall a. Doc a
empty

        ppTy :: Bool -> IState -> (Name, TypeInfo) -> Doc OutputAnnotation
        ppTy :: Bool -> IState -> (Name, TypeInfo) -> Doc OutputAnnotation
ppTy Bool
amb IState
ist (Name
n, TI [Name]
constructors Bool
isCodata DataOpts
_ [Int]
_ [Name]
_ Bool
_)
          = FilePath -> Doc OutputAnnotation
kwd FilePath
key forall a. Doc a -> Doc a -> Doc a
<+> Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
amb [] Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon forall a. Doc a -> Doc a -> Doc a
<+>
            forall a. Doc a -> Doc a
align (IState -> Name -> Doc OutputAnnotation
pprintDelabTy IState
ist Name
n) forall a. Doc a -> Doc a -> Doc a
<+> FilePath -> Doc OutputAnnotation
kwd FilePath
"where" forall a. Doc a -> Doc a -> Doc a
<$>
            forall a. Int -> Doc a -> Doc a
indent Int
2 (forall a. [Doc a] -> Doc a
vsep (forall a b. (a -> b) -> [a] -> [b]
map (Bool -> IState -> Name -> Doc OutputAnnotation
ppCon Bool
False IState
ist) [Name]
constructors))
          where
            key :: FilePath
key | Bool
isCodata = FilePath
"codata"
                | Bool
otherwise = FilePath
"data"
            kwd :: FilePath -> Doc OutputAnnotation
kwd = forall a. a -> Doc a -> Doc a
annotate OutputAnnotation
AnnKeyword forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. FilePath -> Doc a
text
        ppCon :: Bool -> IState -> Name -> Doc OutputAnnotation
ppCon Bool
amb IState
ist Name
n = Bool -> Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
prettyName Bool
True Bool
amb [] Name
n forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a
colon forall a. Doc a -> Doc a -> Doc a
<+> forall a. Doc a -> Doc a
align (IState -> Name -> Doc OutputAnnotation
pprintDelabTy IState
ist Name
n)


helphead :: [([FilePath], CmdArg, FilePath)]
helphead =
  [ ([FilePath
"Command"], CmdArg
SpecialHeaderArg, FilePath
"Purpose"),
    ([FilePath
""], CmdArg
NoArg, FilePath
"")
  ]


replSettings :: Maybe FilePath -> Settings Idris
replSettings :: Maybe FilePath -> Settings Idris
replSettings Maybe FilePath
hFile = forall (m :: * -> *). CompletionFunc m -> Settings m -> Settings m
setComplete CompletionFunc Idris
replCompletion forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => Settings m
defaultSettings {
                       historyFile :: Maybe FilePath
historyFile = Maybe FilePath
hFile
                     }