{-# LANGUAGE NondecreasingIndentation #-}
{-# OPTIONS_GHC -fno-cse #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Agda.Interaction.InteractionTop
  ( module Agda.Interaction.InteractionTop
  )
  where

import Prelude hiding (null)

import Control.Concurrent
import Control.Concurrent.Async
import Control.Concurrent.STM.TChan
import Control.Concurrent.STM.TVar
import qualified Control.Exception  as E

import Control.Monad
import Control.Monad.Except         ( MonadError(..), ExceptT(..), runExceptT )
import Control.Monad.IO.Class       ( MonadIO(..) )
import Control.Monad.Fail           ( MonadFail )
import Control.Monad.State          ( MonadState(..), gets, modify, runStateT )
import Control.Monad.STM
import Control.Monad.State          ( StateT )
import Control.Monad.Trans          ( lift )

import qualified Data.Char as Char
import Data.Function (on)
import qualified Data.List as List
import qualified Data.Map as Map
import Data.Maybe

import System.Directory
import System.FilePath

import Agda.TypeChecking.Monad as TCM
  hiding (initState, setCommandLineOptions)
import qualified Agda.TypeChecking.Monad as TCM
import qualified Agda.TypeChecking.Pretty as TCP
import Agda.TypeChecking.Rules.Term (checkExpr, isType_)
import Agda.TypeChecking.Errors
import Agda.TypeChecking.Warnings (runPM, warning)

import Agda.Syntax.Fixity
import Agda.Syntax.Position
import Agda.Syntax.Parser
import Agda.Syntax.Common
import Agda.Syntax.Concrete as C
import Agda.Syntax.Concrete.Glyph
import Agda.Syntax.Abstract as A
import Agda.Syntax.Abstract.Pretty
import Agda.Syntax.Info (mkDefInfo)
import Agda.Syntax.Translation.ConcreteToAbstract
import Agda.Syntax.Translation.AbstractToConcrete hiding (withScope)
import Agda.Syntax.Scope.Base
import Agda.Syntax.TopLevelModuleName

import Agda.Interaction.Base
import Agda.Interaction.ExitCode
import Agda.Interaction.FindFile
import Agda.Interaction.Options
import Agda.Interaction.Options.Lenses as Lenses
import Agda.Interaction.MakeCase
import Agda.Interaction.SearchAbout
import Agda.Interaction.Response hiding (Function, ExtendedLambda)
import qualified Agda.Interaction.Response as R
import qualified Agda.Interaction.BasicOps as B
import Agda.Interaction.Highlighting.Precise hiding (Error, Postulate, singleton)
import Agda.Interaction.Imports  ( Mode, pattern ScopeCheck, pattern TypeCheck )
import qualified Agda.Interaction.Imports as Imp
import Agda.Interaction.Highlighting.Generate

import Agda.Compiler.Backend

import Agda.Mimer.Mimer as Mimer
import qualified Control.DeepSeq as DeepSeq

import Agda.Utils.Either
import Agda.Utils.FileName
import Agda.Utils.Function
import Agda.Utils.Hash
import Agda.Utils.IO (showIOException)
import Agda.Utils.Lens
import qualified Agda.Utils.Maybe.Strict as Strict
import Agda.Utils.Monad
import Agda.Utils.Null
import Agda.Syntax.Common.Pretty hiding (Mode)
import qualified Agda.Utils.ProfileOptions as Profile
import Agda.Utils.Singleton
import Agda.Utils.String
import Agda.Utils.Time
import Agda.Utils.Tuple
import Agda.Utils.WithDefault (lensCollapseDefault, lensKeepDefault)

import Agda.Utils.Impossible
import Agda.TypeChecking.Opacity (saturateOpaqueBlocks)

------------------------------------------------------------------------
-- The CommandM monad

type CommandM = StateT CommandState TCM

-- | Restore both 'TCState' and 'CommandState'.

localStateCommandM :: CommandM a -> CommandM a
localStateCommandM :: forall a. CommandM a -> CommandM a
localStateCommandM CommandM a
m = do
  CommandState
cSt <- StateT CommandState TCM CommandState
forall s (m :: * -> *). MonadState s m => m s
get
  TCState
tcSt <- StateT CommandState TCM TCState
forall (m :: * -> *). MonadTCState m => m TCState
getTC
  a
x <- CommandM a
m
  TCState -> StateT CommandState TCM ()
forall (m :: * -> *). MonadTCState m => TCState -> m ()
putTC TCState
tcSt
  CommandState -> StateT CommandState TCM ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put CommandState
cSt
  a -> CommandM a
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x

-- | Restore 'TCState', do not touch 'CommandState'.

liftLocalState :: TCM a -> CommandM a
liftLocalState :: forall a. TCM a -> CommandM a
liftLocalState = TCM a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM a -> StateT CommandState TCM a)
-> (TCM a -> TCM a) -> TCM a -> StateT CommandState TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCM a -> TCM a
forall a. TCM a -> TCM a
localTCState

-- | Build an opposite action to 'lift' for state monads.

revLift
    :: MonadState st m
    => (forall c . m c -> st -> k (c, st))      -- ^ run
    -> (forall b . k b -> m b)                  -- ^ lift
    -> (forall x . (m a -> k x) -> k x) -> m a  -- ^ reverse lift in double negative position
revLift :: forall st (m :: * -> *) (k :: * -> *) a.
MonadState st m =>
(forall c. m c -> st -> k (c, st))
-> (forall b. k b -> m b) -> (forall x. (m a -> k x) -> k x) -> m a
revLift forall c. m c -> st -> k (c, st)
run forall b. k b -> m b
lift' forall x. (m a -> k x) -> k x
f = do
    st
st <- m st
forall s (m :: * -> *). MonadState s m => m s
get
    (a
a, st
st') <- k (a, st) -> m (a, st)
forall b. k b -> m b
lift' (k (a, st) -> m (a, st)) -> k (a, st) -> m (a, st)
forall a b. (a -> b) -> a -> b
$ (m a -> k (a, st)) -> k (a, st)
forall x. (m a -> k x) -> k x
f (m a -> st -> k (a, st)
forall c. m c -> st -> k (c, st)
`run` st
st)
    st -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put st
st'
    a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

revLiftTC
    :: MonadTCState m
    => (forall c . m c -> TCState -> k (c, TCState))  -- ^ run
    -> (forall b . k b -> m b)                        -- ^ lift
    -> (forall x . (m a -> k x) -> k x) -> m a        -- ^ reverse lift in double negative position
revLiftTC :: forall (m :: * -> *) (k :: * -> *) a.
MonadTCState m =>
(forall c. m c -> TCState -> k (c, TCState))
-> (forall b. k b -> m b) -> (forall x. (m a -> k x) -> k x) -> m a
revLiftTC forall c. m c -> TCState -> k (c, TCState)
run forall b. k b -> m b
lift' forall x. (m a -> k x) -> k x
f = do
    TCState
st <- m TCState
forall (m :: * -> *). MonadTCState m => m TCState
getTC
    (a
a, TCState
st') <- k (a, TCState) -> m (a, TCState)
forall b. k b -> m b
lift' (k (a, TCState) -> m (a, TCState))
-> k (a, TCState) -> m (a, TCState)
forall a b. (a -> b) -> a -> b
$ (m a -> k (a, TCState)) -> k (a, TCState)
forall x. (m a -> k x) -> k x
f (m a -> TCState -> k (a, TCState)
forall c. m c -> TCState -> k (c, TCState)
`run` TCState
st)
    TCState -> m ()
forall (m :: * -> *). MonadTCState m => TCState -> m ()
putTC TCState
st'
    a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a

-- | Opposite of 'liftIO' for 'CommandM'.
--
-- This function should only be applied to computations that are
-- guaranteed not to raise any errors (except for 'IOException's).

commandMToIO :: (forall x . (CommandM a -> IO x) -> IO x) -> CommandM a
commandMToIO :: forall a. (forall x. (CommandM a -> IO x) -> IO x) -> CommandM a
commandMToIO forall x. (CommandM a -> IO x) -> IO x
ci_i = (forall c.
 StateT CommandState TCM c -> CommandState -> TCM (c, CommandState))
-> (forall a. TCM a -> CommandM a)
-> (forall {x}. (CommandM a -> TCM x) -> TCM x)
-> CommandM a
forall st (m :: * -> *) (k :: * -> *) a.
MonadState st m =>
(forall c. m c -> st -> k (c, st))
-> (forall b. k b -> m b) -> (forall x. (m a -> k x) -> k x) -> m a
revLift StateT CommandState TCM c -> CommandState -> TCM (c, CommandState)
forall c.
StateT CommandState TCM c -> CommandState -> TCM (c, CommandState)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT TCM b -> StateT CommandState TCM b
forall a. TCM a -> CommandM a
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((forall {x}. (CommandM a -> TCM x) -> TCM x) -> CommandM a)
-> (forall {x}. (CommandM a -> TCM x) -> TCM x) -> CommandM a
forall a b. (a -> b) -> a -> b
$ \CommandM a -> TCM x
ct -> (forall c. TCM c -> TCState -> IO (c, TCState))
-> (forall b. IO b -> TCM b)
-> (forall {x}. (TCM x -> IO x) -> IO x)
-> TCM x
forall (m :: * -> *) (k :: * -> *) a.
MonadTCState m =>
(forall c. m c -> TCState -> k (c, TCState))
-> (forall b. k b -> m b) -> (forall x. (m a -> k x) -> k x) -> m a
revLiftTC TCM c -> TCState -> IO (c, TCState)
forall c. TCM c -> TCState -> IO (c, TCState)
runSafeTCM IO b -> TCM b
forall b. IO b -> TCM b
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO ((forall {x}. (TCM x -> IO x) -> IO x) -> TCM x)
-> (forall {x}. (TCM x -> IO x) -> IO x) -> TCM x
forall a b. (a -> b) -> a -> b
$ (CommandM a -> IO x) -> IO x
forall x. (CommandM a -> IO x) -> IO x
ci_i ((CommandM a -> IO x) -> IO x)
-> ((TCM x -> IO x) -> CommandM a -> IO x)
-> (TCM x -> IO x)
-> IO x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((TCM x -> IO x) -> (CommandM a -> TCM x) -> CommandM a -> IO x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CommandM a -> TCM x
ct)

-- | Lift a TCM action transformer to a CommandM action transformer.

liftCommandMT :: (forall x . TCM x -> TCM x) -> CommandM a -> CommandM a
liftCommandMT :: forall a. (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
liftCommandMT forall a. TCM a -> TCM a
f CommandM a
m = (forall c.
 StateT CommandState TCM c -> CommandState -> TCM (c, CommandState))
-> (forall a. TCM a -> CommandM a)
-> (forall {x}. (CommandM a -> TCM x) -> TCM x)
-> CommandM a
forall st (m :: * -> *) (k :: * -> *) a.
MonadState st m =>
(forall c. m c -> st -> k (c, st))
-> (forall b. k b -> m b) -> (forall x. (m a -> k x) -> k x) -> m a
revLift StateT CommandState TCM c -> CommandState -> TCM (c, CommandState)
forall c.
StateT CommandState TCM c -> CommandState -> TCM (c, CommandState)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT TCM b -> StateT CommandState TCM b
forall a. TCM a -> CommandM a
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((forall {x}. (CommandM a -> TCM x) -> TCM x) -> CommandM a)
-> (forall {x}. (CommandM a -> TCM x) -> TCM x) -> CommandM a
forall a b. (a -> b) -> a -> b
$ TCM x -> TCM x
forall a. TCM a -> TCM a
f (TCM x -> TCM x)
-> ((CommandM a -> TCM x) -> TCM x)
-> (CommandM a -> TCM x)
-> TCM x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((CommandM a -> TCM x) -> CommandM a -> TCM x
forall a b. (a -> b) -> a -> b
$ CommandM a
m)

-- | Ditto, but restore state.

liftCommandMTLocalState :: (forall x . TCM x -> TCM x) -> CommandM a -> CommandM a
liftCommandMTLocalState :: forall a. (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
liftCommandMTLocalState forall a. TCM a -> TCM a
f = (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
forall a. (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
liftCommandMT TCM x -> TCM x
forall a. TCM a -> TCM a
f (CommandM a -> CommandM a)
-> (CommandM a -> CommandM a) -> CommandM a -> CommandM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CommandM a -> CommandM a
forall a. CommandM a -> CommandM a
localStateCommandM

-- | Put a response by the callback function given by 'stInteractionOutputCallback'.

putResponse :: Response -> CommandM ()
putResponse :: Response -> StateT CommandState TCM ()
putResponse = TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> (Response -> TCM ()) -> Response -> StateT CommandState TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response -> TCM ()
appInteractionOutputCallback


-- | A Lens for 'theInteractionPoints'.

modifyTheInteractionPoints :: ([InteractionId] -> [InteractionId]) -> CommandM ()
modifyTheInteractionPoints :: ([InteractionId] -> [InteractionId]) -> StateT CommandState TCM ()
modifyTheInteractionPoints [InteractionId] -> [InteractionId]
f = (CommandState -> CommandState) -> StateT CommandState TCM ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((CommandState -> CommandState) -> StateT CommandState TCM ())
-> (CommandState -> CommandState) -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ \ CommandState
s ->
  CommandState
s { theInteractionPoints = f (theInteractionPoints s) }


-- * Operations for manipulating 'oldInteractionScopes'.

-- | A Lens for 'oldInteractionScopes'.
modifyOldInteractionScopes :: (OldInteractionScopes -> OldInteractionScopes) -> CommandM ()
modifyOldInteractionScopes :: (OldInteractionScopes -> OldInteractionScopes)
-> StateT CommandState TCM ()
modifyOldInteractionScopes OldInteractionScopes -> OldInteractionScopes
f = (CommandState -> CommandState) -> StateT CommandState TCM ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((CommandState -> CommandState) -> StateT CommandState TCM ())
-> (CommandState -> CommandState) -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ \ CommandState
s ->
  CommandState
s { oldInteractionScopes = f $ oldInteractionScopes s }

insertOldInteractionScope :: InteractionId -> ScopeInfo -> CommandM ()
insertOldInteractionScope :: InteractionId -> ScopeInfo -> StateT CommandState TCM ()
insertOldInteractionScope InteractionId
ii ScopeInfo
scope = do
  TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String -> Int -> String -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> String -> m ()
reportSLn String
"interaction.scope" Int
20 (String -> TCM ()) -> String -> TCM ()
forall a b. (a -> b) -> a -> b
$ String
"inserting old interaction scope " String -> String -> String
forall a. [a] -> [a] -> [a]
++ InteractionId -> String
forall a. Show a => a -> String
show InteractionId
ii
  (OldInteractionScopes -> OldInteractionScopes)
-> StateT CommandState TCM ()
modifyOldInteractionScopes ((OldInteractionScopes -> OldInteractionScopes)
 -> StateT CommandState TCM ())
-> (OldInteractionScopes -> OldInteractionScopes)
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId
-> ScopeInfo -> OldInteractionScopes -> OldInteractionScopes
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert InteractionId
ii ScopeInfo
scope

removeOldInteractionScope :: InteractionId -> CommandM ()
removeOldInteractionScope :: InteractionId -> StateT CommandState TCM ()
removeOldInteractionScope InteractionId
ii = do
  TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String -> Int -> String -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> String -> m ()
reportSLn String
"interaction.scope" Int
20 (String -> TCM ()) -> String -> TCM ()
forall a b. (a -> b) -> a -> b
$ String
"removing old interaction scope " String -> String -> String
forall a. [a] -> [a] -> [a]
++ InteractionId -> String
forall a. Show a => a -> String
show InteractionId
ii
  (OldInteractionScopes -> OldInteractionScopes)
-> StateT CommandState TCM ()
modifyOldInteractionScopes ((OldInteractionScopes -> OldInteractionScopes)
 -> StateT CommandState TCM ())
-> (OldInteractionScopes -> OldInteractionScopes)
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId -> OldInteractionScopes -> OldInteractionScopes
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete InteractionId
ii

getOldInteractionScope :: InteractionId -> CommandM ScopeInfo
getOldInteractionScope :: InteractionId -> CommandM ScopeInfo
getOldInteractionScope InteractionId
ii = do
  Maybe ScopeInfo
ms <- (CommandState -> Maybe ScopeInfo)
-> StateT CommandState TCM (Maybe ScopeInfo)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((CommandState -> Maybe ScopeInfo)
 -> StateT CommandState TCM (Maybe ScopeInfo))
-> (CommandState -> Maybe ScopeInfo)
-> StateT CommandState TCM (Maybe ScopeInfo)
forall a b. (a -> b) -> a -> b
$ InteractionId -> OldInteractionScopes -> Maybe ScopeInfo
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup InteractionId
ii (OldInteractionScopes -> Maybe ScopeInfo)
-> (CommandState -> OldInteractionScopes)
-> CommandState
-> Maybe ScopeInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CommandState -> OldInteractionScopes
oldInteractionScopes
  case Maybe ScopeInfo
ms of
    Maybe ScopeInfo
Nothing    -> String -> CommandM ScopeInfo
forall a. String -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> CommandM ScopeInfo) -> String -> CommandM ScopeInfo
forall a b. (a -> b) -> a -> b
$ String
"not an old interaction point: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ InteractionId -> String
forall a. Show a => a -> String
show InteractionId
ii
    Just ScopeInfo
scope -> ScopeInfo -> CommandM ScopeInfo
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return ScopeInfo
scope

-- | Do setup and error handling for a command.

handleCommand_ :: CommandM () -> CommandM ()
handleCommand_ :: StateT CommandState TCM () -> StateT CommandState TCM ()
handleCommand_ = (forall a. CommandM a -> CommandM a)
-> StateT CommandState TCM ()
-> StateT CommandState TCM ()
-> StateT CommandState TCM ()
handleCommand CommandM a -> CommandM a
forall a. a -> a
forall a. CommandM a -> CommandM a
id (() -> StateT CommandState TCM ()
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return ())

handleCommand :: (forall a. CommandM a -> CommandM a) -> CommandM () -> CommandM () -> CommandM ()
handleCommand :: (forall a. CommandM a -> CommandM a)
-> StateT CommandState TCM ()
-> StateT CommandState TCM ()
-> StateT CommandState TCM ()
handleCommand forall a. CommandM a -> CommandM a
wrap StateT CommandState TCM ()
onFail StateT CommandState TCM ()
cmd = StateT CommandState TCM () -> StateT CommandState TCM ()
handleNastyErrors (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ StateT CommandState TCM () -> StateT CommandState TCM ()
forall a. CommandM a -> CommandM a
wrap (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
    TCState
oldState <- StateT CommandState TCM TCState
forall (m :: * -> *). MonadTCState m => m TCState
getTC

    -- -- Andreas, 2016-11-18 OLD CODE:
    -- -- onFail and handleErr are executed in "new" command state (not TCState).
    -- -- But it seems that if an exception is raised, it is identical to the old state,
    -- -- see code for catchErr.
    -- res <- (`catchErr` (return . Just)) $ Nothing <$ cmd
    -- maybe (return ()) (\ e -> onFail >> handleErr e) res

    -- Andreas, 2016-11-18 NEW CODE: execute onFail and handleErr in handler
    -- which means (looking at catchErr) they run in state s rathern than s'.
    -- Yet, it looks like s == s' in case the command failed.
    StateT CommandState TCM ()
cmd StateT CommandState TCM ()
-> (TCErr -> StateT CommandState TCM ())
-> StateT CommandState TCM ()
forall a. CommandM a -> (TCErr -> CommandM a) -> CommandM a
`catchErr` \ TCErr
e -> do
      StateT CommandState TCM ()
onFail
      Maybe HighlightingMethod -> TCErr -> StateT CommandState TCM ()
handleErr Maybe HighlightingMethod
forall a. Maybe a
Nothing TCErr
e
      -- Andreas, 2016-11-18, issue #2174
      -- Reset TCState after error is handled, to get rid of metas created during failed command
      TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
        PersistentTCState
newPersistentState <- Lens' TCState PersistentTCState -> TCMT IO PersistentTCState
forall (m :: * -> *) a. ReadTCState m => Lens' TCState a -> m a
useTC (PersistentTCState -> f PersistentTCState) -> TCState -> f TCState
Lens' TCState PersistentTCState
lensPersistentState
        TCState -> TCM ()
forall (m :: * -> *). MonadTCState m => TCState -> m ()
putTC TCState
oldState
        (PersistentTCState -> f PersistentTCState) -> TCState -> f TCState
Lens' TCState PersistentTCState
lensPersistentState Lens' TCState PersistentTCState -> PersistentTCState -> TCM ()
forall (m :: * -> *) a.
MonadTCState m =>
Lens' TCState a -> a -> m ()
`setTCLens` PersistentTCState
newPersistentState

  where
    -- Preserves state so we can do unsolved meta highlighting
    catchErr :: CommandM a -> (TCErr -> CommandM a) -> CommandM a
    catchErr :: forall a. CommandM a -> (TCErr -> CommandM a) -> CommandM a
catchErr CommandM a
m TCErr -> CommandM a
h = do
      CommandState
s       <- StateT CommandState TCM CommandState
forall s (m :: * -> *). MonadState s m => m s
get
      (a
x, CommandState
s') <- TCM (a, CommandState) -> StateT CommandState TCM (a, CommandState)
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (a, CommandState)
 -> StateT CommandState TCM (a, CommandState))
-> TCM (a, CommandState)
-> StateT CommandState TCM (a, CommandState)
forall a b. (a -> b) -> a -> b
$ do CommandM a -> CommandState -> TCM (a, CommandState)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT CommandM a
m CommandState
s
         TCM (a, CommandState)
-> (TCErr -> TCM (a, CommandState)) -> TCM (a, CommandState)
forall a. TCM a -> (TCErr -> TCM a) -> TCM a
`catchError_` \ TCErr
e ->
           CommandM a -> CommandState -> TCM (a, CommandState)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT (TCErr -> CommandM a
h TCErr
e) CommandState
s
      CommandState -> StateT CommandState TCM ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put CommandState
s'
      a -> CommandM a
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x

    -- Handle every possible kind of error (#637), except for
    -- AsyncCancelled, which is used to abort Agda.
    handleNastyErrors :: CommandM () -> CommandM ()
    handleNastyErrors :: StateT CommandState TCM () -> StateT CommandState TCM ()
handleNastyErrors StateT CommandState TCM ()
m = (forall x. (StateT CommandState TCM () -> IO x) -> IO x)
-> StateT CommandState TCM ()
forall a. (forall x. (CommandM a -> IO x) -> IO x) -> CommandM a
commandMToIO ((forall x. (StateT CommandState TCM () -> IO x) -> IO x)
 -> StateT CommandState TCM ())
-> (forall x. (StateT CommandState TCM () -> IO x) -> IO x)
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ \ StateT CommandState TCM () -> IO x
toIO -> do
      let handle :: SomeException -> IO (Either AsyncCancelled x)
handle SomeException
e =
            x -> Either AsyncCancelled x
forall a b. b -> Either a b
Right (x -> Either AsyncCancelled x)
-> IO x -> IO (Either AsyncCancelled x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
              StateT CommandState TCM () -> IO x
toIO (StateT CommandState TCM () -> IO x)
-> StateT CommandState TCM () -> IO x
forall a b. (a -> b) -> a -> b
$ Maybe HighlightingMethod -> TCErr -> StateT CommandState TCM ()
handleErr (HighlightingMethod -> Maybe HighlightingMethod
forall a. a -> Maybe a
Just HighlightingMethod
Direct) (TCErr -> StateT CommandState TCM ())
-> TCErr -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$
                Range -> Doc -> TCErr
Exception Range
forall a. Range' a
noRange (Doc -> TCErr) -> Doc -> TCErr
forall a b. (a -> b) -> a -> b
$ String -> Doc
forall a. String -> Doc a
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ SomeException -> String
forall e. Exception e => e -> String
showIOException SomeException
e

          asyncHandler :: AsyncCancelled -> m (Either AsyncCancelled b)
asyncHandler e :: AsyncCancelled
e@AsyncCancelled
AsyncCancelled = Either AsyncCancelled b -> m (Either AsyncCancelled b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (AsyncCancelled -> Either AsyncCancelled b
forall a b. a -> Either a b
Left AsyncCancelled
e)

          generalHandler :: SomeException -> IO (Either AsyncCancelled x)
generalHandler (SomeException
e :: E.SomeException) = SomeException -> IO (Either AsyncCancelled x)
handle SomeException
e

      Either AsyncCancelled x
r <- ((x -> Either AsyncCancelled x
forall a b. b -> Either a b
Right (x -> Either AsyncCancelled x)
-> IO x -> IO (Either AsyncCancelled x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT CommandState TCM () -> IO x
toIO StateT CommandState TCM ()
m) IO (Either AsyncCancelled x)
-> (AsyncCancelled -> IO (Either AsyncCancelled x))
-> IO (Either AsyncCancelled x)
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`E.catch` AsyncCancelled -> IO (Either AsyncCancelled x)
forall {m :: * -> *} {b}.
Monad m =>
AsyncCancelled -> m (Either AsyncCancelled b)
asyncHandler)
             IO (Either AsyncCancelled x)
-> (SomeException -> IO (Either AsyncCancelled x))
-> IO (Either AsyncCancelled x)
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`E.catch` SomeException -> IO (Either AsyncCancelled x)
generalHandler
      case Either AsyncCancelled x
r of
        Right x
x -> x -> IO x
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return x
x
        Left AsyncCancelled
e  -> AsyncCancelled -> IO x
forall e a. Exception e => e -> IO a
E.throwIO AsyncCancelled
e

    -- Displays an error and instructs Emacs to jump to the site of the
    -- error. Because this function may switch the focus to another file
    -- the status information is also updated.
    handleErr :: Maybe HighlightingMethod -> TCErr -> StateT CommandState TCM ()
handleErr Maybe HighlightingMethod
method TCErr
e = do

      -- TODO: make a better predicate for this
      Bool
noError <- TCMT IO Bool -> StateT CommandState TCM Bool
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO Bool -> StateT CommandState TCM Bool)
-> TCMT IO Bool -> StateT CommandState TCM Bool
forall a b. (a -> b) -> a -> b
$ String -> Bool
forall a. Null a => a -> Bool
null (String -> Bool) -> TCMT IO String -> TCMT IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCErr -> TCMT IO String
forall (tcm :: * -> *). MonadTCM tcm => TCErr -> tcm String
renderError TCErr
e
      Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
noError do

        HighlightingInfoBuilder
unsolved <- TCMT IO HighlightingInfoBuilder
-> StateT CommandState TCM HighlightingInfoBuilder
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO HighlightingInfoBuilder
 -> StateT CommandState TCM HighlightingInfoBuilder)
-> TCMT IO HighlightingInfoBuilder
-> StateT CommandState TCM HighlightingInfoBuilder
forall a b. (a -> b) -> a -> b
$ TCMT IO HighlightingInfoBuilder
computeUnsolvedInfo
        HighlightingInfoBuilder
err     <- TCMT IO HighlightingInfoBuilder
-> StateT CommandState TCM HighlightingInfoBuilder
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO HighlightingInfoBuilder
 -> StateT CommandState TCM HighlightingInfoBuilder)
-> TCMT IO HighlightingInfoBuilder
-> StateT CommandState TCM HighlightingInfoBuilder
forall a b. (a -> b) -> a -> b
$ TCErr -> TCMT IO HighlightingInfoBuilder
errorHighlighting TCErr
e
        ModuleToSource
modFile <- TCMT IO ModuleToSource -> StateT CommandState TCM ModuleToSource
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO ModuleToSource -> StateT CommandState TCM ModuleToSource)
-> TCMT IO ModuleToSource -> StateT CommandState TCM ModuleToSource
forall a b. (a -> b) -> a -> b
$ Lens' TCState ModuleToSource -> TCMT IO ModuleToSource
forall (m :: * -> *) a. ReadTCState m => Lens' TCState a -> m a
useTC (ModuleToSource -> f ModuleToSource) -> TCState -> f TCState
Lens' TCState ModuleToSource
stModuleToSource
        HighlightingMethod
method  <- case Maybe HighlightingMethod
method of
          Maybe HighlightingMethod
Nothing -> TCMT IO HighlightingMethod
-> StateT CommandState TCM HighlightingMethod
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO HighlightingMethod
 -> StateT CommandState TCM HighlightingMethod)
-> TCMT IO HighlightingMethod
-> StateT CommandState TCM HighlightingMethod
forall a b. (a -> b) -> a -> b
$ Lens' TCEnv HighlightingMethod -> TCMT IO HighlightingMethod
forall (m :: * -> *) a. MonadTCEnv m => Lens' TCEnv a -> m a
viewTC (HighlightingMethod -> f HighlightingMethod) -> TCEnv -> f TCEnv
Lens' TCEnv HighlightingMethod
eHighlightingMethod
          Just HighlightingMethod
m  -> HighlightingMethod -> StateT CommandState TCM HighlightingMethod
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return HighlightingMethod
m
        let info :: HighlightingInfo
info = HighlightingInfoBuilder -> HighlightingInfo
forall a b. Convert a b => a -> b
convert (HighlightingInfoBuilder -> HighlightingInfo)
-> HighlightingInfoBuilder -> HighlightingInfo
forall a b. (a -> b) -> a -> b
$ HighlightingInfoBuilder
err HighlightingInfoBuilder
-> HighlightingInfoBuilder -> HighlightingInfoBuilder
forall a. Semigroup a => a -> a -> a
<> HighlightingInfoBuilder
unsolved
                     -- Errors take precedence over unsolved things.

        Bool
showImpl <- TCMT IO Bool -> StateT CommandState TCM Bool
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO Bool -> StateT CommandState TCM Bool)
-> TCMT IO Bool -> StateT CommandState TCM Bool
forall a b. (a -> b) -> a -> b
$ PragmaOptions -> Bool
optShowImplicit (PragmaOptions -> Bool) -> TCMT IO PragmaOptions -> TCMT IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Lens' TCState PragmaOptions -> TCMT IO PragmaOptions
forall (m :: * -> *) a. ReadTCState m => Lens' TCState a -> m a
useTC (PragmaOptions -> f PragmaOptions) -> TCState -> f TCState
Lens' TCState PragmaOptions
stPragmaOptions
        Bool
showIrr <- TCMT IO Bool -> StateT CommandState TCM Bool
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO Bool -> StateT CommandState TCM Bool)
-> TCMT IO Bool -> StateT CommandState TCM Bool
forall a b. (a -> b) -> a -> b
$ PragmaOptions -> Bool
optShowIrrelevant (PragmaOptions -> Bool) -> TCMT IO PragmaOptions -> TCMT IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Lens' TCState PragmaOptions -> TCMT IO PragmaOptions
forall (m :: * -> *) a. ReadTCState m => Lens' TCState a -> m a
useTC (PragmaOptions -> f PragmaOptions) -> TCState -> f TCState
Lens' TCState PragmaOptions
stPragmaOptions
        do
          (Response -> StateT CommandState TCM ())
-> [Response] -> StateT CommandState TCM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Response -> StateT CommandState TCM ()
putResponse ([Response] -> StateT CommandState TCM ())
-> [Response] -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$
            [ DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_DisplayInfo (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> Response)
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> Response
forall a b. (a -> b) -> a -> b
$ Info_Error
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
Info_Error_boot tcErr tcWarning
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Error (Info_Error
 -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors)
-> Info_Error
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall a b. (a -> b) -> a -> b
$ TCErr -> Info_Error
forall tcErr tcWarning. tcErr -> Info_Error_boot tcErr tcWarning
Info_GenericError TCErr
e ] [Response] -> [Response] -> [Response]
forall a. [a] -> [a] -> [a]
++
            Range -> [Response]
tellEmacsToJumpToError (TCErr -> Range
forall a. HasRange a => a -> Range
getRange TCErr
e) [Response] -> [Response] -> [Response]
forall a. [a] -> [a] -> [a]
++
            [ HighlightingInfo
-> RemoveTokenBasedHighlighting
-> HighlightingMethod
-> ModuleToSource
-> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
HighlightingInfo
-> RemoveTokenBasedHighlighting
-> HighlightingMethod
-> ModuleToSource
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_HighlightingInfo HighlightingInfo
info RemoveTokenBasedHighlighting
KeepHighlighting
                                    HighlightingMethod
method ModuleToSource
modFile ] [Response] -> [Response] -> [Response]
forall a. [a] -> [a] -> [a]
++
            [ Status -> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
Status -> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_Status (Status -> Response) -> Status -> Response
forall a b. (a -> b) -> a -> b
$ Status { sChecked :: Bool
sChecked = Bool
False
                                   , sShowImplicitArguments :: Bool
sShowImplicitArguments = Bool
showImpl
                                   , sShowIrrelevantArguments :: Bool
sShowIrrelevantArguments = Bool
showIrr
                                   } ]
          StateT CommandState TCM Bool
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (CommandLineOptions -> Bool
optExitOnError (CommandLineOptions -> Bool)
-> StateT CommandState TCM CommandLineOptions
-> StateT CommandState TCM Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT CommandState TCM CommandLineOptions
forall (m :: * -> *). HasOptions m => m CommandLineOptions
commandLineOptions) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$
            IO () -> StateT CommandState TCM ()
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> StateT CommandState TCM ())
-> IO () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ AgdaError -> IO ()
forall a. AgdaError -> IO a
exitAgdaWith AgdaError
TCMError

-- | Run an 'IOTCM' value, catch the exceptions, emit output
--
--   If an error happens the state of 'CommandM' does not change,
--   but stPersistent may change (which contains successfully
--   loaded interfaces for example).

runInteraction :: IOTCM -> CommandM ()
runInteraction :: IOTCM -> StateT CommandState TCM ()
runInteraction IOTCM
iotcm =
  (forall a. CommandM a -> CommandM a)
-> StateT CommandState TCM ()
-> StateT CommandState TCM ()
-> StateT CommandState TCM ()
handleCommand CommandM a -> CommandM a
forall a. CommandM a -> CommandM a
inEmacs StateT CommandState TCM ()
onFail (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
    AbsolutePath
currentAbs <- IO AbsolutePath -> StateT CommandState TCM AbsolutePath
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO AbsolutePath -> StateT CommandState TCM AbsolutePath)
-> IO AbsolutePath -> StateT CommandState TCM AbsolutePath
forall a b. (a -> b) -> a -> b
$ String -> IO AbsolutePath
absolute String
current
    Maybe CurrentFile
cf  <- (CommandState -> Maybe CurrentFile)
-> StateT CommandState TCM (Maybe CurrentFile)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets CommandState -> Maybe CurrentFile
theCurrentFile
    Interaction' Range
cmd <- if Interaction' Range -> Bool
independent Interaction' Range
cmd then Interaction' Range -> StateT CommandState TCM (Interaction' Range)
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return Interaction' Range
cmd else do
      Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (AbsolutePath -> Maybe AbsolutePath
forall a. a -> Maybe a
Just AbsolutePath
currentAbs Maybe AbsolutePath -> Maybe AbsolutePath -> Bool
forall a. Eq a => a -> a -> Bool
/= (CurrentFile -> AbsolutePath
currentFilePath (CurrentFile -> AbsolutePath)
-> Maybe CurrentFile -> Maybe AbsolutePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe CurrentFile
cf)) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
        let mode :: Mode
mode = Mode
TypeCheck
        String
-> [String]
-> Bool
-> Mode
-> (CheckResult -> StateT CommandState TCM ())
-> StateT CommandState TCM ()
forall a.
String
-> [String]
-> Bool
-> Mode
-> (CheckResult -> CommandM a)
-> CommandM a
cmd_load' String
current [] Bool
True Mode
mode ((CheckResult -> StateT CommandState TCM ())
 -> StateT CommandState TCM ())
-> (CheckResult -> StateT CommandState TCM ())
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ \CheckResult
_ -> () -> StateT CommandState TCM ()
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
      CurrentFile
cf <- CurrentFile -> Maybe CurrentFile -> CurrentFile
forall a. a -> Maybe a -> a
fromMaybe CurrentFile
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe CurrentFile -> CurrentFile)
-> StateT CommandState TCM (Maybe CurrentFile)
-> StateT CommandState TCM CurrentFile
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CommandState -> Maybe CurrentFile)
-> StateT CommandState TCM (Maybe CurrentFile)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets CommandState -> Maybe CurrentFile
theCurrentFile
      Interaction' Range -> StateT CommandState TCM (Interaction' Range)
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return (Interaction' Range
 -> StateT CommandState TCM (Interaction' Range))
-> Interaction' Range
-> StateT CommandState TCM (Interaction' Range)
forall a b. (a -> b) -> a -> b
$ case IOTCM
iotcm (TopLevelModuleName -> Maybe TopLevelModuleName
forall a. a -> Maybe a
Just (CurrentFile -> TopLevelModuleName
currentFileModule CurrentFile
cf)) of
        IOTCM String
_ HighlightingLevel
_ HighlightingMethod
_ Interaction' Range
cmd -> Interaction' Range
cmd

    StateT CommandState TCM () -> StateT CommandState TCM ()
forall a. CommandM a -> CommandM a
withCurrentFile (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ Interaction' Range -> StateT CommandState TCM ()
interpret Interaction' Range
cmd

    Maybe CurrentFile
cf' <- (CommandState -> Maybe CurrentFile)
-> StateT CommandState TCM (Maybe CurrentFile)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets CommandState -> Maybe CurrentFile
theCurrentFile
    Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Interaction' Range -> Bool
updateInteractionPointsAfter Interaction' Range
cmd
            Bool -> Bool -> Bool
&&
          AbsolutePath -> Maybe AbsolutePath
forall a. a -> Maybe a
Just AbsolutePath
currentAbs Maybe AbsolutePath -> Maybe AbsolutePath -> Bool
forall a. Eq a => a -> a -> Bool
== (CurrentFile -> AbsolutePath
currentFilePath (CurrentFile -> AbsolutePath)
-> Maybe CurrentFile -> Maybe AbsolutePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe CurrentFile
cf')) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
        Response -> StateT CommandState TCM ()
putResponse (Response -> StateT CommandState TCM ())
-> ([InteractionId] -> Response)
-> [InteractionId]
-> StateT CommandState TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [InteractionId] -> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
[InteractionId]
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_InteractionPoints ([InteractionId] -> StateT CommandState TCM ())
-> StateT CommandState TCM [InteractionId]
-> StateT CommandState TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (CommandState -> [InteractionId])
-> StateT CommandState TCM [InteractionId]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets CommandState -> [InteractionId]
theInteractionPoints

  where
    -- The ranges in cmd might be incorrect because of the use of
    -- Nothing here. That is taken care of above.
    IOTCM String
current HighlightingLevel
highlighting HighlightingMethod
highlightingMethod Interaction' Range
cmd = IOTCM
iotcm Maybe TopLevelModuleName
forall a. Maybe a
Nothing

    inEmacs :: forall a. CommandM a -> CommandM a
    inEmacs :: forall a. CommandM a -> CommandM a
inEmacs = (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
forall a. (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
liftCommandMT ((forall a. TCM a -> TCM a) -> CommandM a -> CommandM a)
-> (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
forall a b. (a -> b) -> a -> b
$ TCEnv -> TCMT IO x -> TCMT IO x
forall (m :: * -> *) a. MonadTCEnv m => TCEnv -> m a -> m a
withEnv (TCEnv -> TCMT IO x -> TCMT IO x)
-> TCEnv -> TCMT IO x -> TCMT IO x
forall a b. (a -> b) -> a -> b
$ TCEnv
initEnv
            { envHighlightingLevel  = highlighting
            , envHighlightingMethod = highlightingMethod
            }

    -- If an independent command fails we should reset theCurrentFile (Issue853).
    onFail :: StateT CommandState TCM ()
onFail | Interaction' Range -> Bool
independent Interaction' Range
cmd = (CommandState -> CommandState) -> StateT CommandState TCM ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((CommandState -> CommandState) -> StateT CommandState TCM ())
-> (CommandState -> CommandState) -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ \ CommandState
s -> CommandState
s { theCurrentFile = Nothing }
           | Bool
otherwise       = () -> StateT CommandState TCM ()
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

------------------------------------------------------------------------
-- Command queues

-- | If the next command from the command queue is anything but an
-- actual command, then the command is returned.
--
-- If the command is an 'IOTCM' command, then the following happens:
-- The given computation is applied to the command and executed. If an
-- abort command is encountered (and acted upon), then the computation
-- is interrupted, the persistent state and all options are restored,
-- and some commands are sent to the frontend. If the computation was
-- not interrupted, then its result is returned.

-- TODO: It might be nice if some of the changes to the persistent
-- state inflicted by the interrupted computation were preserved.

maybeAbort :: (IOTCM -> CommandM a) -> CommandM (Command' (Maybe a))
maybeAbort :: forall a. (IOTCM -> CommandM a) -> CommandM (Command' (Maybe a))
maybeAbort IOTCM -> CommandM a
m = do
  CommandState
commandState <- StateT CommandState TCM CommandState
forall s (m :: * -> *). MonadState s m => m s
get
  let q :: CommandQueue
q = CommandState -> CommandQueue
commandQueue CommandState
commandState
  (Integer
n, Command
cmd) <- IO (Integer, Command) -> StateT CommandState TCM (Integer, Command)
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Integer, Command)
 -> StateT CommandState TCM (Integer, Command))
-> IO (Integer, Command)
-> StateT CommandState TCM (Integer, Command)
forall a b. (a -> b) -> a -> b
$ STM (Integer, Command) -> IO (Integer, Command)
forall a. STM a -> IO a
atomically (STM (Integer, Command) -> IO (Integer, Command))
-> STM (Integer, Command) -> IO (Integer, Command)
forall a b. (a -> b) -> a -> b
$ TChan (Integer, Command) -> STM (Integer, Command)
forall a. TChan a -> STM a
readTChan (CommandQueue -> TChan (Integer, Command)
commands CommandQueue
q)
  case Command
cmd of
    Command
Done      -> Command' (Maybe a) -> CommandM (Command' (Maybe a))
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return Command' (Maybe a)
forall a. Command' a
Done
    Error String
e   -> Command' (Maybe a) -> CommandM (Command' (Maybe a))
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Command' (Maybe a)
forall a. String -> Command' a
Error String
e)
    Command IOTCM
c -> do
      TCState
tcState <- StateT CommandState TCM TCState
forall (m :: * -> *). MonadTCState m => m TCState
getTC
      TCEnv
tcEnv   <- StateT CommandState TCM TCEnv
forall (m :: * -> *). MonadTCEnv m => m TCEnv
askTC
      Either ((a, CommandState), TCState) Integer
result  <- IO (Either ((a, CommandState), TCState) Integer)
-> StateT
     CommandState TCM (Either ((a, CommandState), TCState) Integer)
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either ((a, CommandState), TCState) Integer)
 -> StateT
      CommandState TCM (Either ((a, CommandState), TCState) Integer))
-> IO (Either ((a, CommandState), TCState) Integer)
-> StateT
     CommandState TCM (Either ((a, CommandState), TCState) Integer)
forall a b. (a -> b) -> a -> b
$ IO ((a, CommandState), TCState)
-> IO Integer -> IO (Either ((a, CommandState), TCState) Integer)
forall a b. IO a -> IO b -> IO (Either a b)
race
                   (TCEnv
-> TCState
-> TCMT IO (a, CommandState)
-> IO ((a, CommandState), TCState)
forall (m :: * -> *) a.
MonadIO m =>
TCEnv -> TCState -> TCMT m a -> m (a, TCState)
runTCM TCEnv
tcEnv TCState
tcState (TCMT IO (a, CommandState) -> IO ((a, CommandState), TCState))
-> TCMT IO (a, CommandState) -> IO ((a, CommandState), TCState)
forall a b. (a -> b) -> a -> b
$
                    CommandM a -> CommandState -> TCMT IO (a, CommandState)
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT (IOTCM -> CommandM a
m IOTCM
c) CommandState
commandState)
                   (Integer -> CommandQueue -> IO Integer
waitForAbort Integer
n CommandQueue
q)
      case Either ((a, CommandState), TCState) Integer
result of
        Left ((a
x, CommandState
commandState'), TCState
tcState') -> do
          TCState -> StateT CommandState TCM ()
forall (m :: * -> *). MonadTCState m => TCState -> m ()
putTC TCState
tcState'
          CommandState -> StateT CommandState TCM ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put CommandState
commandState'
          case IOTCM
c Maybe TopLevelModuleName
forall a. Maybe a
Nothing of
            IOTCM String
_ HighlightingLevel
_ HighlightingMethod
_ Interaction' Range
Cmd_exit -> do
              Response -> StateT CommandState TCM ()
putResponse Response
forall tcErr tcWarning warningsAndNonFatalErrors.
Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_DoneExiting
              Command' (Maybe a) -> CommandM (Command' (Maybe a))
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return Command' (Maybe a)
forall a. Command' a
Done
            IOTCM' Range
_ -> Command' (Maybe a) -> CommandM (Command' (Maybe a))
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> Command' (Maybe a)
forall a. a -> Command' a
Command (a -> Maybe a
forall a. a -> Maybe a
Just a
x))
        Right Integer
a -> do
          IO () -> StateT CommandState TCM ()
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> StateT CommandState TCM ())
-> IO () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ CommandQueue -> Integer -> IO ()
popAbortedCommands CommandQueue
q Integer
a
          TCState -> StateT CommandState TCM ()
forall (m :: * -> *). MonadTCState m => TCState -> m ()
putTC (TCState -> StateT CommandState TCM ())
-> TCState -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ TCState
initState
            { stPersistentState = stPersistentState tcState
            , stPreScopeState   =
                (stPreScopeState initState)
                  { stPrePragmaOptions =
                      stPrePragmaOptions
                        (stPreScopeState tcState)
                  }
            }
          CommandState -> StateT CommandState TCM ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (CommandState -> StateT CommandState TCM ())
-> CommandState -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ (CommandQueue -> CommandState
initCommandState (CommandState -> CommandQueue
commandQueue CommandState
commandState))
            { optionsOnReload = optionsOnReload commandState
            }
          Response -> StateT CommandState TCM ()
putResponse Response
forall tcErr tcWarning warningsAndNonFatalErrors.
Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_DoneAborting
          StateT CommandState TCM ()
displayStatus
          Command' (Maybe a) -> CommandM (Command' (Maybe a))
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> Command' (Maybe a)
forall a. a -> Command' a
Command Maybe a
forall a. Maybe a
Nothing)
  where

  -- Returns if the currently executing command should be aborted.
  -- The "abort number" is returned.

  waitForAbort
    :: Integer       -- The number of the currently executing command.
    -> CommandQueue  -- The command queue.
    -> IO Integer
  waitForAbort :: Integer -> CommandQueue -> IO Integer
waitForAbort Integer
n CommandQueue
q = do
    STM Integer -> IO Integer
forall a. STM a -> IO a
atomically (STM Integer -> IO Integer) -> STM Integer -> IO Integer
forall a b. (a -> b) -> a -> b
$ do
      Maybe Integer
a <- TVar (Maybe Integer) -> STM (Maybe Integer)
forall a. TVar a -> STM a
readTVar (CommandQueue -> TVar (Maybe Integer)
abort CommandQueue
q)
      case Maybe Integer
a of
        Just Integer
a' | Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
a' -> Integer -> STM Integer
forall a. a -> STM a
forall (m :: * -> *) a. Monad m => a -> m a
return Integer
a'
        Maybe Integer
_                 -> STM Integer
forall a. STM a
retry

  -- Removes every command for which the command number is at most
  -- the given number (the "abort number") from the command queue.
  --
  -- New commands could be added to the end of the queue while this
  -- computation is running. This does not lead to a race condition,
  -- because those commands have higher command numbers, so they will
  -- not be removed.

  popAbortedCommands :: CommandQueue -> Integer -> IO ()
  popAbortedCommands :: CommandQueue -> Integer -> IO ()
popAbortedCommands CommandQueue
q Integer
n = do
    Bool
done <- STM Bool -> IO Bool
forall a. STM a -> IO a
atomically (STM Bool -> IO Bool) -> STM Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ do
      Maybe (Integer, Command)
cmd <- TChan (Integer, Command) -> STM (Maybe (Integer, Command))
forall a. TChan a -> STM (Maybe a)
tryReadTChan (CommandQueue -> TChan (Integer, Command)
commands CommandQueue
q)
      case Maybe (Integer, Command)
cmd of
        Maybe (Integer, Command)
Nothing -> Bool -> STM Bool
forall a. a -> STM a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
        Just (Integer, Command)
c  ->
          if (Integer, Command) -> Integer
forall a b. (a, b) -> a
fst (Integer, Command)
c Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
n then
            Bool -> STM Bool
forall a. a -> STM a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
           else do
            TChan (Integer, Command) -> (Integer, Command) -> STM ()
forall a. TChan a -> a -> STM ()
unGetTChan (CommandQueue -> TChan (Integer, Command)
commands CommandQueue
q) (Integer, Command)
c
            Bool -> STM Bool
forall a. a -> STM a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
    Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
done (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
      CommandQueue -> Integer -> IO ()
popAbortedCommands CommandQueue
q Integer
n

-- | Creates a command queue, and forks a thread that writes commands
-- to the queue. The queue is returned.

initialiseCommandQueue
  :: IO Command
     -- ^ Returns the next command.
  -> IO CommandQueue
initialiseCommandQueue :: IO Command -> IO CommandQueue
initialiseCommandQueue IO Command
next = do
  TChan (Integer, Command)
commands <- IO (TChan (Integer, Command))
forall a. IO (TChan a)
newTChanIO
  TVar (Maybe Integer)
abort    <- Maybe Integer -> IO (TVar (Maybe Integer))
forall a. a -> IO (TVar a)
newTVarIO Maybe Integer
forall a. Maybe a
Nothing

  let -- Read commands. The argument is the number of the previous
      -- command (other than abort commands) that was read, if any.
      readCommands :: Integer -> IO ()
readCommands Integer
n = do
        Command
c <- IO Command
next
        case Command
c of
          Command IOTCM
c | IOTCM String
_ HighlightingLevel
_ HighlightingMethod
_ Interaction' Range
Cmd_abort <- IOTCM
c Maybe TopLevelModuleName
forall a. Maybe a
Nothing -> do
            STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ TVar (Maybe Integer) -> Maybe Integer -> STM ()
forall a. TVar a -> a -> STM ()
writeTVar TVar (Maybe Integer)
abort (Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
n)
            Integer -> IO ()
readCommands Integer
n
          Command
_ -> do
            let n' :: Integer
n' = (Integer -> Integer
forall a. Enum a => a -> a
succ Integer
n)
            STM () -> IO ()
forall a. STM a -> IO a
atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ TChan (Integer, Command) -> (Integer, Command) -> STM ()
forall a. TChan a -> a -> STM ()
writeTChan TChan (Integer, Command)
commands (Integer
n', Command
c)
            case Command
c of
              Command
Done -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
              Command
_    -> Integer -> IO ()
readCommands Integer
n'

  ThreadId
_ <- IO () -> IO ThreadId
forkIO (Integer -> IO ()
readCommands Integer
0)

  CommandQueue -> IO CommandQueue
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CommandQueue { TVar (Maybe Integer)
TChan (Integer, Command)
commands :: TChan (Integer, Command)
abort :: TVar (Maybe Integer)
commands :: TChan (Integer, Command)
abort :: TVar (Maybe Integer)
.. })

---------------------------------------------------------

-- | Can the command run even if the relevant file has not been loaded
--   into the state?

independent :: Interaction -> Bool
independent :: Interaction' Range -> Bool
independent (Cmd_load {})                   = Bool
True
independent (Cmd_compile {})                = Bool
True
independent (Cmd_load_highlighting_info {}) = Bool
True
independent Cmd_tokenHighlighting {}        = Bool
True
independent Interaction' Range
Cmd_show_version                = Bool
True
independent Interaction' Range
_                               = Bool
False

-- | Should 'Resp_InteractionPoints' be issued after the command has
-- run?

updateInteractionPointsAfter :: Interaction -> Bool
updateInteractionPointsAfter :: Interaction' Range -> Bool
updateInteractionPointsAfter Cmd_load{}                          = Bool
True
updateInteractionPointsAfter Cmd_compile{}                       = Bool
True
updateInteractionPointsAfter Cmd_constraints{}                   = Bool
False
updateInteractionPointsAfter Cmd_metas{}                         = Bool
False
updateInteractionPointsAfter Cmd_no_metas{}                      = Bool
False
updateInteractionPointsAfter Cmd_show_module_contents_toplevel{} = Bool
False
updateInteractionPointsAfter Cmd_search_about_toplevel{}         = Bool
False
updateInteractionPointsAfter Cmd_solveAll{}                      = Bool
True
updateInteractionPointsAfter Cmd_solveOne{}                      = Bool
True
updateInteractionPointsAfter Cmd_infer_toplevel{}                = Bool
False
updateInteractionPointsAfter Cmd_compute_toplevel{}              = Bool
False
updateInteractionPointsAfter Cmd_load_highlighting_info{}        = Bool
False
updateInteractionPointsAfter Cmd_tokenHighlighting{}             = Bool
False
updateInteractionPointsAfter Cmd_highlight{}                     = Bool
True
updateInteractionPointsAfter ShowImplicitArgs{}                  = Bool
False
updateInteractionPointsAfter ToggleImplicitArgs{}                = Bool
False
updateInteractionPointsAfter ShowIrrelevantArgs{}                = Bool
False
updateInteractionPointsAfter ToggleIrrelevantArgs{}              = Bool
False
updateInteractionPointsAfter Cmd_give{}                          = Bool
True
updateInteractionPointsAfter Cmd_refine{}                        = Bool
True
updateInteractionPointsAfter Cmd_intro{}                         = Bool
True
updateInteractionPointsAfter Cmd_refine_or_intro{}               = Bool
True
updateInteractionPointsAfter Cmd_autoOne{}                       = Bool
True
updateInteractionPointsAfter Cmd_autoAll{}                       = Bool
True
updateInteractionPointsAfter Cmd_context{}                       = Bool
False
updateInteractionPointsAfter Cmd_helper_function{}               = Bool
False
updateInteractionPointsAfter Cmd_infer{}                         = Bool
False
updateInteractionPointsAfter Cmd_goal_type{}                     = Bool
False
updateInteractionPointsAfter Cmd_elaborate_give{}                = Bool
True
updateInteractionPointsAfter Cmd_goal_type_context{}             = Bool
False
updateInteractionPointsAfter Cmd_goal_type_context_infer{}       = Bool
False
updateInteractionPointsAfter Cmd_goal_type_context_check{}       = Bool
False
updateInteractionPointsAfter Cmd_show_module_contents{}          = Bool
False
updateInteractionPointsAfter Cmd_make_case{}                     = Bool
True
updateInteractionPointsAfter Cmd_compute{}                       = Bool
False
updateInteractionPointsAfter Cmd_why_in_scope{}                  = Bool
False
updateInteractionPointsAfter Cmd_why_in_scope_toplevel{}         = Bool
False
updateInteractionPointsAfter Cmd_show_version{}                  = Bool
False
updateInteractionPointsAfter Cmd_abort{}                         = Bool
False
updateInteractionPointsAfter Cmd_exit{}                          = Bool
False

-- | Interpret an interaction

interpret :: Interaction -> CommandM ()

interpret :: Interaction' Range -> StateT CommandState TCM ()
interpret (Cmd_load String
m [String]
argv) =
  String
-> [String]
-> Bool
-> Mode
-> (CheckResult -> StateT CommandState TCM ())
-> StateT CommandState TCM ()
forall a.
String
-> [String]
-> Bool
-> Mode
-> (CheckResult -> CommandM a)
-> CommandM a
cmd_load' String
m [String]
argv Bool
True Mode
mode ((CheckResult -> StateT CommandState TCM ())
 -> StateT CommandState TCM ())
-> (CheckResult -> StateT CommandState TCM ())
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ \CheckResult
_ -> Interaction' Range -> StateT CommandState TCM ()
interpret (Interaction' Range -> StateT CommandState TCM ())
-> Interaction' Range -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ Rewrite -> Interaction' Range
forall range. Rewrite -> Interaction' range
Cmd_metas Rewrite
AsIs
  where
  mode :: Mode
mode = Mode
TypeCheck

interpret (Cmd_compile CompilerBackend
backend String
file [String]
argv) =
  String
-> [String]
-> Bool
-> Mode
-> (CheckResult -> StateT CommandState TCM ())
-> StateT CommandState TCM ()
forall a.
String
-> [String]
-> Bool
-> Mode
-> (CheckResult -> CommandM a)
-> CommandM a
cmd_load' String
file [String]
argv Bool
allowUnsolved Mode
mode ((CheckResult -> StateT CommandState TCM ())
 -> StateT CommandState TCM ())
-> (CheckResult -> StateT CommandState TCM ())
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ \ CheckResult
checkResult -> do
    [TCWarning]
mw <- TCM [TCWarning] -> StateT CommandState TCM [TCWarning]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM [TCWarning] -> StateT CommandState TCM [TCWarning])
-> TCM [TCWarning] -> StateT CommandState TCM [TCWarning]
forall a b. (a -> b) -> a -> b
$ [TCWarning] -> TCM [TCWarning]
forall (m :: * -> *). HasOptions m => [TCWarning] -> m [TCWarning]
applyFlagsToTCWarnings ([TCWarning] -> TCM [TCWarning]) -> [TCWarning] -> TCM [TCWarning]
forall a b. (a -> b) -> a -> b
$ CheckResult -> [TCWarning]
crWarnings CheckResult
checkResult
    case [TCWarning]
mw of
      [] -> do
        TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ case CompilerBackend
backend of
          CompilerBackend
LaTeX                    -> String -> IsMain -> CheckResult -> TCM ()
callBackend String
"LaTeX" IsMain
IsMain CheckResult
checkResult
          CompilerBackend
QuickLaTeX               -> String -> IsMain -> CheckResult -> TCM ()
callBackend String
"LaTeX" IsMain
IsMain CheckResult
checkResult
          OtherBackend String
"GHCNoMain" -> String -> IsMain -> CheckResult -> TCM ()
callBackend String
"GHC" IsMain
NotMain CheckResult
checkResult   -- for backwards compatibility
          OtherBackend String
b           -> String -> IsMain -> CheckResult -> TCM ()
callBackend String
b IsMain
IsMain CheckResult
checkResult
        DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> (WarningsAndNonFatalErrors
    -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors)
-> WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CompilerBackend
-> WarningsAndNonFatalErrors
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
CompilerBackend
-> warningsAndNonFatalErrors
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_CompilationOk CompilerBackend
backend (WarningsAndNonFatalErrors -> StateT CommandState TCM ())
-> StateT CommandState TCM WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCM WarningsAndNonFatalErrors
-> StateT CommandState TCM WarningsAndNonFatalErrors
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCM WarningsAndNonFatalErrors
B.getWarningsAndNonFatalErrors
      w :: [TCWarning]
w@(TCWarning
_:[TCWarning]
_) -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ Info_Error
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
Info_Error_boot tcErr tcWarning
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Error (Info_Error
 -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors)
-> Info_Error
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall a b. (a -> b) -> a -> b
$ [TCWarning] -> Info_Error
forall tcErr tcWarning.
[tcWarning] -> Info_Error_boot tcErr tcWarning
Info_CompilationError [TCWarning]
w
  where
  allowUnsolved :: Bool
allowUnsolved = CompilerBackend
backend CompilerBackend -> [CompilerBackend] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CompilerBackend
LaTeX, CompilerBackend
QuickLaTeX]
  mode :: Mode
mode | CompilerBackend
QuickLaTeX <- CompilerBackend
backend = Mode
ScopeCheck
       | Bool
otherwise             = Mode
TypeCheck

interpret Interaction' Range
Cmd_constraints =
    DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> ([OutputForm_boot TCErr Expr Expr]
    -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors)
-> [OutputForm_boot TCErr Expr Expr]
-> StateT CommandState TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [OutputForm_boot TCErr Expr Expr]
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
[OutputForm_boot tcErr Expr Expr]
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Constraints ([OutputForm_boot TCErr Expr Expr] -> StateT CommandState TCM ())
-> StateT CommandState TCM [OutputForm_boot TCErr Expr Expr]
-> StateT CommandState TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCM [OutputForm_boot TCErr Expr Expr]
-> StateT CommandState TCM [OutputForm_boot TCErr Expr Expr]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCM [OutputForm_boot TCErr Expr Expr]
B.getConstraints

interpret (Cmd_metas Rewrite
norm) = do
  Goals
ms <- TCMT IO Goals -> StateT CommandState TCM Goals
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO Goals -> StateT CommandState TCM Goals)
-> TCMT IO Goals -> StateT CommandState TCM Goals
forall a b. (a -> b) -> a -> b
$ Rewrite -> Rewrite -> TCMT IO Goals
B.getGoals' Rewrite
norm (Rewrite -> Rewrite -> Rewrite
forall a. Ord a => a -> a -> a
max Rewrite
Simplified Rewrite
norm)
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> (WarningsAndNonFatalErrors
    -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors)
-> WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Goals
-> WarningsAndNonFatalErrors
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
Goals_boot tcErr
-> warningsAndNonFatalErrors
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_AllGoalsWarnings Goals
ms (WarningsAndNonFatalErrors -> StateT CommandState TCM ())
-> StateT CommandState TCM WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCM WarningsAndNonFatalErrors
-> StateT CommandState TCM WarningsAndNonFatalErrors
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCM WarningsAndNonFatalErrors
B.getWarningsAndNonFatalErrors

interpret Interaction' Range
Cmd_no_metas = do
  [MetaId]
metas <- StateT CommandState TCM [MetaId]
forall (m :: * -> *). ReadTCState m => m [MetaId]
getOpenMetas
  Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([MetaId] -> Bool
forall a. Null a => a -> Bool
null [MetaId]
metas) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$
    TypeError -> StateT CommandState TCM ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> StateT CommandState TCM ())
-> TypeError -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String -> TypeError
GenericError String
"Unsolved meta-variables"

interpret (Cmd_show_module_contents_toplevel Rewrite
norm String
s) =
  StateT CommandState TCM () -> StateT CommandState TCM ()
forall a. CommandM a -> CommandM a
atTopLevel (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ Rewrite -> Range -> String -> StateT CommandState TCM ()
showModuleContents Rewrite
norm Range
forall a. Range' a
noRange String
s

interpret (Cmd_search_about_toplevel Rewrite
norm String
s) =
  StateT CommandState TCM () -> StateT CommandState TCM ()
forall a. CommandM a -> CommandM a
atTopLevel (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ Rewrite -> Range -> String -> StateT CommandState TCM ()
searchAbout Rewrite
norm Range
forall a. Range' a
noRange String
s

interpret (Cmd_solveAll Rewrite
norm)        = Rewrite -> Maybe InteractionId -> StateT CommandState TCM ()
solveInstantiatedGoals Rewrite
norm Maybe InteractionId
forall a. Maybe a
Nothing
interpret (Cmd_solveOne Rewrite
norm InteractionId
ii Range
_ String
_) = Rewrite -> Maybe InteractionId -> StateT CommandState TCM ()
solveInstantiatedGoals Rewrite
norm' (InteractionId -> Maybe InteractionId
forall a. a -> Maybe a
Just InteractionId
ii)
  -- `solveOne` is called via `agda2-maybe-normalised` which does not use
  -- AsIs < Simplified < Normalised but rather Simplified < Instantiated < Normalised
  -- So we remap the Rewrite modifiers to match solveAll's behaviour.
  -- NB: instantiate is called in getSolvedInteractionPoints no matter what.
  where norm' :: Rewrite
norm' = case Rewrite
norm of
                  Rewrite
Simplified   -> Rewrite
AsIs
                  Rewrite
Instantiated -> Rewrite
Simplified
                  Rewrite
_            -> Rewrite
norm

interpret (Cmd_infer_toplevel Rewrite
norm String
s) = do
  (Maybe CPUTime
time, Expr
expr) <- (Expr -> TCM Expr) -> String -> CommandM (Maybe CPUTime, Expr)
forall a. (Expr -> TCM a) -> String -> CommandM (Maybe CPUTime, a)
parseAndDoAtToplevel (Rewrite -> Expr -> TCM Expr
B.typeInCurrent Rewrite
norm) String
s
  CommandState
state <- StateT CommandState TCM CommandState
forall s (m :: * -> *). MonadState s m => m s
get
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ CommandState
-> Maybe CPUTime
-> Expr
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
CommandState
-> Maybe CPUTime
-> Expr
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_InferredType CommandState
state Maybe CPUTime
time Expr
expr

interpret (Cmd_compute_toplevel ComputeMode
cmode String
s) = do
  (Maybe CPUTime
time, Expr
expr) <- (Expr -> TCM Expr) -> String -> CommandM (Maybe CPUTime, Expr)
forall a. (Expr -> TCM a) -> String -> CommandM (Maybe CPUTime, a)
parseAndDoAtToplevel Expr -> TCM Expr
action (ComputeMode -> String -> String
B.computeWrapInput ComputeMode
cmode String
s)
  CommandState
state <- StateT CommandState TCM CommandState
forall s (m :: * -> *). MonadState s m => m s
get
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ CommandState
-> ComputeMode
-> Maybe CPUTime
-> Expr
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
CommandState
-> ComputeMode
-> Maybe CPUTime
-> Expr
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_NormalForm CommandState
state ComputeMode
cmode Maybe CPUTime
time Expr
expr
    where
    action :: Expr -> TCM Expr
action = TCM Expr -> TCM Expr
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
allowNonTerminatingReductions
           (TCM Expr -> TCM Expr) -> (Expr -> TCM Expr) -> Expr -> TCM Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (if ComputeMode -> Bool
B.computeIgnoreAbstract ComputeMode
cmode then TCM Expr -> TCM Expr
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
ignoreAbstractMode else TCM Expr -> TCM Expr
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
inConcreteMode)
           (TCM Expr -> TCM Expr) -> (Expr -> TCM Expr) -> Expr -> TCM Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ComputeMode -> Expr -> TCM Expr
B.evalInCurrent ComputeMode
cmode
-- interpret (Cmd_compute_toplevel cmode s) =
--   parseAndDoAtToplevel action Info_NormalForm $ computeWrapInput cmode s
--   where
--   action = allowNonTerminatingReductions
--          . (if computeIgnoreAbstract cmode then ignoreAbstractMode else inConcreteMode)
--          . (B.showComputed cmode <=< B.evalInCurrent)


interpret (ShowImplicitArgs Bool
showImpl) = do
  CommandLineOptions
opts <- TCM CommandLineOptions
-> StateT CommandState TCM CommandLineOptions
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCM CommandLineOptions
forall (m :: * -> *). HasOptions m => m CommandLineOptions
commandLineOptions
  CommandLineOptions -> StateT CommandState TCM ()
setCommandLineOpts (CommandLineOptions -> StateT CommandState TCM ())
-> CommandLineOptions -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$
    Lens' CommandLineOptions Bool -> LensSet CommandLineOptions Bool
forall o i. Lens' o i -> LensSet o i
set ((PragmaOptions -> f PragmaOptions)
-> CommandLineOptions -> f CommandLineOptions
forall a. LensPragmaOptions a => Lens' a PragmaOptions
Lens' CommandLineOptions PragmaOptions
lensPragmaOptions ((PragmaOptions -> f PragmaOptions)
 -> CommandLineOptions -> f CommandLineOptions)
-> ((Bool -> f Bool) -> PragmaOptions -> f PragmaOptions)
-> (Bool -> f Bool)
-> CommandLineOptions
-> f CommandLineOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WithDefault 'False -> f (WithDefault 'False))
-> PragmaOptions -> f PragmaOptions
forall (f :: * -> *).
Functor f =>
(WithDefault 'False -> f (WithDefault 'False))
-> PragmaOptions -> f PragmaOptions
lensOptShowImplicit ((WithDefault 'False -> f (WithDefault 'False))
 -> PragmaOptions -> f PragmaOptions)
-> ((Bool -> f Bool)
    -> WithDefault 'False -> f (WithDefault 'False))
-> (Bool -> f Bool)
-> PragmaOptions
-> f PragmaOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> f Bool) -> WithDefault 'False -> f (WithDefault 'False)
forall a (b :: Bool).
(Boolean a, Eq a, KnownBool b) =>
Lens' (WithDefault' a b) a
Lens' (WithDefault 'False) Bool
lensKeepDefault) Bool
showImpl CommandLineOptions
opts

interpret Interaction' Range
ToggleImplicitArgs = do
  CommandLineOptions
opts <- TCM CommandLineOptions
-> StateT CommandState TCM CommandLineOptions
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCM CommandLineOptions
forall (m :: * -> *). HasOptions m => m CommandLineOptions
commandLineOptions
  CommandLineOptions -> StateT CommandState TCM ()
setCommandLineOpts (CommandLineOptions -> StateT CommandState TCM ())
-> CommandLineOptions -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$
    Lens' CommandLineOptions Bool -> LensMap CommandLineOptions Bool
forall o i. Lens' o i -> LensMap o i
over ((PragmaOptions -> f PragmaOptions)
-> CommandLineOptions -> f CommandLineOptions
forall a. LensPragmaOptions a => Lens' a PragmaOptions
Lens' CommandLineOptions PragmaOptions
lensPragmaOptions ((PragmaOptions -> f PragmaOptions)
 -> CommandLineOptions -> f CommandLineOptions)
-> ((Bool -> f Bool) -> PragmaOptions -> f PragmaOptions)
-> (Bool -> f Bool)
-> CommandLineOptions
-> f CommandLineOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WithDefault 'False -> f (WithDefault 'False))
-> PragmaOptions -> f PragmaOptions
forall (f :: * -> *).
Functor f =>
(WithDefault 'False -> f (WithDefault 'False))
-> PragmaOptions -> f PragmaOptions
lensOptShowImplicit ((WithDefault 'False -> f (WithDefault 'False))
 -> PragmaOptions -> f PragmaOptions)
-> ((Bool -> f Bool)
    -> WithDefault 'False -> f (WithDefault 'False))
-> (Bool -> f Bool)
-> PragmaOptions
-> f PragmaOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> f Bool) -> WithDefault 'False -> f (WithDefault 'False)
forall a (b :: Bool).
(Boolean a, KnownBool b) =>
Lens' (WithDefault' a b) a
Lens' (WithDefault 'False) Bool
lensCollapseDefault) Bool -> Bool
not CommandLineOptions
opts

interpret (ShowIrrelevantArgs Bool
showIrr) = do
  CommandLineOptions
opts <- TCM CommandLineOptions
-> StateT CommandState TCM CommandLineOptions
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCM CommandLineOptions
forall (m :: * -> *). HasOptions m => m CommandLineOptions
commandLineOptions
  CommandLineOptions -> StateT CommandState TCM ()
setCommandLineOpts (CommandLineOptions -> StateT CommandState TCM ())
-> CommandLineOptions -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$
    Lens' CommandLineOptions Bool -> LensSet CommandLineOptions Bool
forall o i. Lens' o i -> LensSet o i
set ((PragmaOptions -> f PragmaOptions)
-> CommandLineOptions -> f CommandLineOptions
forall a. LensPragmaOptions a => Lens' a PragmaOptions
Lens' CommandLineOptions PragmaOptions
lensPragmaOptions ((PragmaOptions -> f PragmaOptions)
 -> CommandLineOptions -> f CommandLineOptions)
-> ((Bool -> f Bool) -> PragmaOptions -> f PragmaOptions)
-> (Bool -> f Bool)
-> CommandLineOptions
-> f CommandLineOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WithDefault 'False -> f (WithDefault 'False))
-> PragmaOptions -> f PragmaOptions
forall (f :: * -> *).
Functor f =>
(WithDefault 'False -> f (WithDefault 'False))
-> PragmaOptions -> f PragmaOptions
lensOptShowIrrelevant ((WithDefault 'False -> f (WithDefault 'False))
 -> PragmaOptions -> f PragmaOptions)
-> ((Bool -> f Bool)
    -> WithDefault 'False -> f (WithDefault 'False))
-> (Bool -> f Bool)
-> PragmaOptions
-> f PragmaOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> f Bool) -> WithDefault 'False -> f (WithDefault 'False)
forall a (b :: Bool).
(Boolean a, Eq a, KnownBool b) =>
Lens' (WithDefault' a b) a
Lens' (WithDefault 'False) Bool
lensKeepDefault) Bool
showIrr CommandLineOptions
opts

interpret Interaction' Range
ToggleIrrelevantArgs = do
  CommandLineOptions
opts <- TCM CommandLineOptions
-> StateT CommandState TCM CommandLineOptions
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCM CommandLineOptions
forall (m :: * -> *). HasOptions m => m CommandLineOptions
commandLineOptions
  CommandLineOptions -> StateT CommandState TCM ()
setCommandLineOpts (CommandLineOptions -> StateT CommandState TCM ())
-> CommandLineOptions -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$
    Lens' CommandLineOptions Bool -> LensMap CommandLineOptions Bool
forall o i. Lens' o i -> LensMap o i
over ((PragmaOptions -> f PragmaOptions)
-> CommandLineOptions -> f CommandLineOptions
forall a. LensPragmaOptions a => Lens' a PragmaOptions
Lens' CommandLineOptions PragmaOptions
lensPragmaOptions ((PragmaOptions -> f PragmaOptions)
 -> CommandLineOptions -> f CommandLineOptions)
-> ((Bool -> f Bool) -> PragmaOptions -> f PragmaOptions)
-> (Bool -> f Bool)
-> CommandLineOptions
-> f CommandLineOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WithDefault 'False -> f (WithDefault 'False))
-> PragmaOptions -> f PragmaOptions
forall (f :: * -> *).
Functor f =>
(WithDefault 'False -> f (WithDefault 'False))
-> PragmaOptions -> f PragmaOptions
lensOptShowIrrelevant ((WithDefault 'False -> f (WithDefault 'False))
 -> PragmaOptions -> f PragmaOptions)
-> ((Bool -> f Bool)
    -> WithDefault 'False -> f (WithDefault 'False))
-> (Bool -> f Bool)
-> PragmaOptions
-> f PragmaOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> f Bool) -> WithDefault 'False -> f (WithDefault 'False)
forall a (b :: Bool).
(Boolean a, KnownBool b) =>
Lens' (WithDefault' a b) a
Lens' (WithDefault 'False) Bool
lensCollapseDefault) Bool -> Bool
not CommandLineOptions
opts

interpret (Cmd_load_highlighting_info String
source) = do
  HighlightingLevel
l <- (TCEnv -> HighlightingLevel)
-> StateT CommandState TCM HighlightingLevel
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> HighlightingLevel
envHighlightingLevel
  Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (HighlightingLevel
l HighlightingLevel -> HighlightingLevel -> Bool
forall a. Eq a => a -> a -> Bool
/= HighlightingLevel
None) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
    -- Make sure that the include directories have
    -- been set.
    CommandLineOptions -> StateT CommandState TCM ()
setCommandLineOpts (CommandLineOptions -> StateT CommandState TCM ())
-> StateT CommandState TCM CommandLineOptions
-> StateT CommandState TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCM CommandLineOptions
-> StateT CommandState TCM CommandLineOptions
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCM CommandLineOptions
forall (m :: * -> *). HasOptions m => m CommandLineOptions
commandLineOptions
    [Response]
resp <- TCM [Response] -> StateT CommandState TCM [Response]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM [Response] -> StateT CommandState TCM [Response])
-> TCM [Response] -> StateT CommandState TCM [Response]
forall a b. (a -> b) -> a -> b
$ IO [Response] -> TCM [Response]
forall b. IO b -> TCM b
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Response] -> TCM [Response])
-> (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
    -> IO [Response])
-> Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
-> TCM [Response]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
-> IO [Response]
tellToUpdateHighlighting (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
 -> TCM [Response])
-> TCMT
     IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource))
-> TCM [Response]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
      Bool
ex        <- IO Bool -> TCMT IO Bool
forall b. IO b -> TCM b
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> TCMT IO Bool) -> IO Bool -> TCMT IO Bool
forall a b. (a -> b) -> a -> b
$ String -> IO Bool
doesFileExist String
source
      SourceFile
absSource <- IO SourceFile -> TCMT IO SourceFile
forall b. IO b -> TCM b
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO SourceFile -> TCMT IO SourceFile)
-> IO SourceFile -> TCMT IO SourceFile
forall a b. (a -> b) -> a -> b
$ AbsolutePath -> SourceFile
SourceFile (AbsolutePath -> SourceFile) -> IO AbsolutePath -> IO SourceFile
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> IO AbsolutePath
absolute String
source
      if Bool
ex
        then
           do
              Source
src <- SourceFile -> TCM Source
Imp.parseSource SourceFile
absSource
              let m :: TopLevelModuleName
m = Source -> TopLevelModuleName
Imp.srcModuleName Source
src
              TopLevelModuleName
-> SourceFile -> Maybe TopLevelModuleName -> TCM ()
checkModuleName TopLevelModuleName
m SourceFile
absSource Maybe TopLevelModuleName
forall a. Maybe a
Nothing
              Maybe ModuleInfo
mmi <- TopLevelModuleName -> TCMT IO (Maybe ModuleInfo)
forall (m :: * -> *).
ReadTCState m =>
TopLevelModuleName -> m (Maybe ModuleInfo)
getVisitedModule TopLevelModuleName
m
              case Maybe ModuleInfo
mmi of
                Maybe ModuleInfo
Nothing -> Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
-> TCMT
     IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource))
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
forall a. Maybe a
Nothing
                Just ModuleInfo
mi ->
                  if Text -> Hash
hashText (Source -> Text
Imp.srcText Source
src) Hash -> Hash -> Bool
forall a. Eq a => a -> a -> Bool
== Interface -> Hash
iSourceHash (ModuleInfo -> Interface
miInterface ModuleInfo
mi)
                    then do
                      ModuleToSource
modFile <- Lens' TCState ModuleToSource -> TCMT IO ModuleToSource
forall (m :: * -> *) a. ReadTCState m => Lens' TCState a -> m a
useTC (ModuleToSource -> f ModuleToSource) -> TCState -> f TCState
Lens' TCState ModuleToSource
stModuleToSource
                      HighlightingMethod
method  <- Lens' TCEnv HighlightingMethod -> TCMT IO HighlightingMethod
forall (m :: * -> *) a. MonadTCEnv m => Lens' TCEnv a -> m a
viewTC (HighlightingMethod -> f HighlightingMethod) -> TCEnv -> f TCEnv
Lens' TCEnv HighlightingMethod
eHighlightingMethod
                      Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
-> TCMT
     IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource))
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
 -> TCMT
      IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)))
-> Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
-> TCMT
     IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource))
forall a b. (a -> b) -> a -> b
$ (HighlightingInfo, HighlightingMethod, ModuleToSource)
-> Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
forall a. a -> Maybe a
Just (Interface -> HighlightingInfo
iHighlighting (Interface -> HighlightingInfo) -> Interface -> HighlightingInfo
forall a b. (a -> b) -> a -> b
$ ModuleInfo -> Interface
miInterface ModuleInfo
mi, HighlightingMethod
method, ModuleToSource
modFile)
                    else
                      Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
-> TCMT
     IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource))
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
forall a. Maybe a
Nothing
            TCMT
  IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource))
-> (TCErr
    -> TCMT
         IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)))
-> TCMT
     IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource))
forall a. TCM a -> (TCErr -> TCM a) -> TCM a
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \TCErr
_ -> Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
-> TCMT
     IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource))
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
forall a. Maybe a
Nothing
        else
          Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
-> TCMT
     IO (Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource))
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
forall a. Maybe a
Nothing
    (Response -> StateT CommandState TCM ())
-> [Response] -> StateT CommandState TCM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Response -> StateT CommandState TCM ()
putResponse [Response]
resp

interpret (Cmd_tokenHighlighting String
source Remove
remove) = do
  Maybe HighlightingInfo
info <- do HighlightingLevel
l <- (TCEnv -> HighlightingLevel)
-> StateT CommandState TCM HighlightingLevel
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> HighlightingLevel
envHighlightingLevel
             if HighlightingLevel
l HighlightingLevel -> HighlightingLevel -> Bool
forall a. Eq a => a -> a -> Bool
== HighlightingLevel
None
               then Maybe HighlightingInfo
-> StateT CommandState TCM (Maybe HighlightingInfo)
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe HighlightingInfo
forall a. Maybe a
Nothing
               else do
                 AbsolutePath
source' <- IO AbsolutePath -> StateT CommandState TCM AbsolutePath
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (String -> IO AbsolutePath
absolute String
source)
                 TCM (Maybe HighlightingInfo)
-> StateT CommandState TCM (Maybe HighlightingInfo)
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (Maybe HighlightingInfo)
 -> StateT CommandState TCM (Maybe HighlightingInfo))
-> TCM (Maybe HighlightingInfo)
-> StateT CommandState TCM (Maybe HighlightingInfo)
forall a b. (a -> b) -> a -> b
$ (HighlightingInfo -> Maybe HighlightingInfo
forall a. a -> Maybe a
Just (HighlightingInfo -> Maybe HighlightingInfo)
-> TCMT IO HighlightingInfo -> TCM (Maybe HighlightingInfo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AbsolutePath -> TCMT IO HighlightingInfo
generateTokenInfo AbsolutePath
source')
                           TCM (Maybe HighlightingInfo)
-> (TCErr -> TCM (Maybe HighlightingInfo))
-> TCM (Maybe HighlightingInfo)
forall a. TCM a -> (TCErr -> TCM a) -> TCM a
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \TCErr
_ ->
                        Maybe HighlightingInfo -> TCM (Maybe HighlightingInfo)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe HighlightingInfo
forall a. Maybe a
Nothing
      StateT CommandState TCM (Maybe HighlightingInfo)
-> StateT CommandState TCM ()
-> StateT CommandState TCM (Maybe HighlightingInfo)
forall e (m :: * -> *) a. MonadError e m => m a -> m () -> m a
`finally`
    case Remove
remove of
      Remove
Remove -> IO () -> StateT CommandState TCM ()
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> StateT CommandState TCM ())
-> IO () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String -> IO ()
removeFile String
source
      Remove
Keep   -> () -> StateT CommandState TCM ()
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
  case Maybe HighlightingInfo
info of
    Just HighlightingInfo
info' -> TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ RemoveTokenBasedHighlighting -> HighlightingInfo -> TCM ()
forall (m :: * -> *).
MonadTrace m =>
RemoveTokenBasedHighlighting -> HighlightingInfo -> m ()
printHighlightingInfo RemoveTokenBasedHighlighting
RemoveHighlighting HighlightingInfo
info'
    Maybe HighlightingInfo
Nothing    -> () -> StateT CommandState TCM ()
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

interpret (Cmd_highlight InteractionId
ii Range
rng String
s) = do
  HighlightingLevel
l <- (TCEnv -> HighlightingLevel)
-> StateT CommandState TCM HighlightingLevel
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> HighlightingLevel
envHighlightingLevel
  Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (HighlightingLevel
l HighlightingLevel -> HighlightingLevel -> Bool
forall a. Eq a => a -> a -> Bool
/= HighlightingLevel
None) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
    ScopeInfo
scope <- InteractionId -> CommandM ScopeInfo
getOldInteractionScope InteractionId
ii
    InteractionId -> StateT CommandState TCM ()
removeOldInteractionScope InteractionId
ii
    ExceptT Info_Error TCM () -> StateT CommandState TCM ()
handle (ExceptT Info_Error TCM () -> StateT CommandState TCM ())
-> ExceptT Info_Error TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
      Expr
parsed <- Info_Error -> TCM Expr -> ExceptT Info_Error TCM Expr
forall a. Info_Error -> TCM a -> ExceptT Info_Error TCM a
try (InteractionId -> Info_Error
forall tcErr tcWarning.
InteractionId -> Info_Error_boot tcErr tcWarning
Info_HighlightingParseError InteractionId
ii) (TCM Expr -> ExceptT Info_Error TCM Expr)
-> TCM Expr -> ExceptT Info_Error TCM Expr
forall a b. (a -> b) -> a -> b
$
             Range -> String -> TCM Expr
B.parseExpr Range
rng String
s
      Expr
expr <- Info_Error -> TCM Expr -> ExceptT Info_Error TCM Expr
forall a. Info_Error -> TCM a -> ExceptT Info_Error TCM a
try (InteractionId -> Info_Error
forall tcErr tcWarning.
InteractionId -> Info_Error_boot tcErr tcWarning
Info_HighlightingScopeCheckError InteractionId
ii) (TCM Expr -> ExceptT Info_Error TCM Expr)
-> TCM Expr -> ExceptT Info_Error TCM Expr
forall a b. (a -> b) -> a -> b
$
             ScopeInfo -> Expr -> ScopeM (AbsOfCon Expr)
forall c. ToAbstract c => ScopeInfo -> c -> ScopeM (AbsOfCon c)
concreteToAbstract ScopeInfo
scope Expr
parsed
      TCM () -> ExceptT Info_Error TCM ()
forall (m :: * -> *) a. Monad m => m a -> ExceptT Info_Error m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> ExceptT Info_Error TCM ())
-> TCM () -> ExceptT Info_Error TCM ()
forall a b. (a -> b) -> a -> b
$ RemoveTokenBasedHighlighting -> HighlightingInfo -> TCM ()
forall (m :: * -> *).
MonadTrace m =>
RemoveTokenBasedHighlighting -> HighlightingInfo -> m ()
printHighlightingInfo RemoveTokenBasedHighlighting
KeepHighlighting (HighlightingInfo -> TCM ()) -> TCMT IO HighlightingInfo -> TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
               Range -> String -> TCMT IO HighlightingInfo
generateTokenInfoFromString Range
rng String
s
      TCM () -> ExceptT Info_Error TCM ()
forall (m :: * -> *) a. Monad m => m a -> ExceptT Info_Error m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> ExceptT Info_Error TCM ())
-> TCM () -> ExceptT Info_Error TCM ()
forall a b. (a -> b) -> a -> b
$ Expr -> TCM ()
highlightExpr Expr
expr
  where
    handle :: ExceptT Info_Error TCM () -> CommandM ()
    handle :: ExceptT Info_Error TCM () -> StateT CommandState TCM ()
handle ExceptT Info_Error TCM ()
m = do
      Either Info_Error ()
res <- TCM (Either Info_Error ())
-> StateT CommandState TCM (Either Info_Error ())
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (Either Info_Error ())
 -> StateT CommandState TCM (Either Info_Error ()))
-> TCM (Either Info_Error ())
-> StateT CommandState TCM (Either Info_Error ())
forall a b. (a -> b) -> a -> b
$ ExceptT Info_Error TCM () -> TCM (Either Info_Error ())
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT ExceptT Info_Error TCM ()
m
      case Either Info_Error ()
res of
        Left Info_Error
err -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ Info_Error
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
Info_Error_boot tcErr tcWarning
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Error Info_Error
err
        Right ()
_ -> () -> StateT CommandState TCM ()
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    try :: Info_Error -> TCM a -> ExceptT Info_Error TCM a
    try :: forall a. Info_Error -> TCM a -> ExceptT Info_Error TCM a
try Info_Error
err TCM a
m = TCM (Either Info_Error a) -> ExceptT Info_Error TCM a
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT (TCM (Either Info_Error a) -> ExceptT Info_Error TCM a)
-> TCM (Either Info_Error a) -> ExceptT Info_Error TCM a
forall a b. (a -> b) -> a -> b
$ do
      ((TCErr -> Info_Error) -> Either TCErr a -> Either Info_Error a
forall a c b. (a -> c) -> Either a b -> Either c b
mapLeft (Info_Error -> TCErr -> Info_Error
forall a b. a -> b -> a
const Info_Error
err) (Either TCErr a -> Either Info_Error a)
-> TCMT IO (Either TCErr a) -> TCM (Either Info_Error a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCM a -> TCMT IO (Either TCErr a)
forall a. TCM a -> TCM (Either TCErr a)
freshTCM TCM a
m) TCM (Either Info_Error a)
-> (TCErr -> TCM (Either Info_Error a))
-> TCM (Either Info_Error a)
forall a. TCM a -> (TCErr -> TCM a) -> TCM a
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \ TCErr
_ -> Either Info_Error a -> TCM (Either Info_Error a)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Info_Error -> Either Info_Error a
forall a b. a -> Either a b
Left Info_Error
err)
      -- freshTCM to avoid scope checking creating new interaction points

interpret (Cmd_give   UseForce
force InteractionId
ii Range
rng String
s) = UseForce
-> InteractionId
-> Range
-> String
-> GiveRefine
-> StateT CommandState TCM ()
give_gen UseForce
force InteractionId
ii Range
rng String
s GiveRefine
Give
interpret (Cmd_refine InteractionId
ii Range
rng String
s) = UseForce
-> InteractionId
-> Range
-> String
-> GiveRefine
-> StateT CommandState TCM ()
give_gen UseForce
WithoutForce InteractionId
ii Range
rng String
s GiveRefine
Refine

interpret (Cmd_intro Bool
pmLambda InteractionId
ii Range
rng String
_) = do
  [String]
ss <- TCMT IO [String] -> StateT CommandState TCM [String]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO [String] -> StateT CommandState TCM [String])
-> TCMT IO [String] -> StateT CommandState TCM [String]
forall a b. (a -> b) -> a -> b
$ Bool -> InteractionId -> TCMT IO [String]
B.introTactic Bool
pmLambda InteractionId
ii
  (forall a. TCM a -> TCM a)
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a. (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
liftCommandMT (InteractionId -> TCMT IO x -> TCMT IO x
forall (m :: * -> *) a.
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m, MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ case [String]
ss of
    []    -> do
      DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Intro_NotFound
    [String
s]   -> UseForce
-> InteractionId
-> Range
-> String
-> GiveRefine
-> StateT CommandState TCM ()
give_gen UseForce
WithoutForce InteractionId
ii Range
rng String
s GiveRefine
Intro
    String
_:String
_:[String]
_ -> do
      DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ [String]
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
[String]
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Intro_ConstructorUnknown [String]
ss

interpret (Cmd_refine_or_intro Bool
pmLambda InteractionId
ii Range
r String
s) = Interaction' Range -> StateT CommandState TCM ()
interpret (Interaction' Range -> StateT CommandState TCM ())
-> Interaction' Range -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$
  let s' :: String
s' = String -> String
trim String
s
  in (if String -> Bool
forall a. Null a => a -> Bool
null String
s' then Bool -> InteractionId -> Range -> String -> Interaction' Range
forall range.
Bool -> InteractionId -> range -> String -> Interaction' range
Cmd_intro Bool
pmLambda else InteractionId -> Range -> String -> Interaction' Range
forall range.
InteractionId -> range -> String -> Interaction' range
Cmd_refine) InteractionId
ii Range
r String
s'

interpret (Cmd_autoOne Rewrite
norm InteractionId
ii Range
rng String
str) = do
  ScopeInfo
iscope <- InteractionId -> CommandM ScopeInfo
forall (m :: * -> *).
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m) =>
InteractionId -> m ScopeInfo
getInteractionScope InteractionId
ii
  (Maybe CPUTime
time, MimerResult
result) <- CommandM MimerResult -> CommandM (Maybe CPUTime, MimerResult)
forall a. CommandM a -> CommandM (Maybe CPUTime, a)
maybeTimed (CommandM MimerResult -> CommandM (Maybe CPUTime, MimerResult))
-> CommandM MimerResult -> CommandM (Maybe CPUTime, MimerResult)
forall a b. (a -> b) -> a -> b
$ Rewrite -> InteractionId -> Range -> String -> CommandM MimerResult
forall (tcm :: * -> *).
MonadTCM tcm =>
Rewrite -> InteractionId -> Range -> String -> tcm MimerResult
Mimer.mimer Rewrite
norm InteractionId
ii Range
rng String
str
  case MimerResult
result of
    MimerResult
MimerNoResult -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
String
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Auto String
"No solution found"
    MimerExpr String
str -> do
      InteractionId -> ScopeInfo -> StateT CommandState TCM ()
insertOldInteractionScope InteractionId
ii ScopeInfo
iscope
      Response -> StateT CommandState TCM ()
putResponse (Response -> StateT CommandState TCM ())
-> Response -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId -> GiveResult -> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
InteractionId
-> GiveResult
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_GiveAction InteractionId
ii (GiveResult -> Response) -> GiveResult -> Response
forall a b. (a -> b) -> a -> b
$ String -> GiveResult
Give_String String
str
      ([InteractionId] -> [InteractionId]) -> StateT CommandState TCM ()
modifyTheInteractionPoints (InteractionId -> [InteractionId] -> [InteractionId]
forall a. Eq a => a -> [a] -> [a]
List.delete InteractionId
ii)
      StateT CommandState TCM ()
-> (CPUTime -> StateT CommandState TCM ())
-> Maybe CPUTime
-> StateT CommandState TCM ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> StateT CommandState TCM ()
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> (CPUTime
    -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors)
-> CPUTime
-> StateT CommandState TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CPUTime
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
CPUTime
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Time) Maybe CPUTime
time
    MimerList [(Int, String)]
sols -> do
      DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
String
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Auto (String
 -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors)
-> String
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall a b. (a -> b) -> a -> b
$ [String] -> String
unlines ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$
        [ String
"Solutions:" ] [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
        [ String
"  " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
". " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s | (Int
i, String
s) <- [(Int, String)]
sols ]
    MimerClauses{} -> StateT CommandState TCM ()
forall a. HasCallStack => a
__IMPOSSIBLE__    -- Mimer can't do case splitting yet

interpret (Cmd_autoAll Rewrite
norm) = do
  [InteractionId]
iis <- StateT CommandState TCM [InteractionId]
forall (m :: * -> *). ReadTCState m => m [InteractionId]
getInteractionPoints
  InteractionId -> CommandM ScopeInfo
getOldScope <- do
    TCState
st <- StateT CommandState TCM TCState
forall (m :: * -> *). MonadTCState m => m TCState
getTC
    (InteractionId -> CommandM ScopeInfo)
-> StateT CommandState TCM (InteractionId -> CommandM ScopeInfo)
forall a. a -> StateT CommandState TCM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((InteractionId -> CommandM ScopeInfo)
 -> StateT CommandState TCM (InteractionId -> CommandM ScopeInfo))
-> (InteractionId -> CommandM ScopeInfo)
-> StateT CommandState TCM (InteractionId -> CommandM ScopeInfo)
forall a b. (a -> b) -> a -> b
$ \ InteractionId
ii -> TCM ScopeInfo -> CommandM ScopeInfo
forall a. TCM a -> CommandM a
liftLocalState (TCM ScopeInfo -> CommandM ScopeInfo)
-> TCM ScopeInfo -> CommandM ScopeInfo
forall a b. (a -> b) -> a -> b
$ TCState -> TCM ()
forall (m :: * -> *). MonadTCState m => TCState -> m ()
putTC TCState
st TCM () -> TCM ScopeInfo -> TCM ScopeInfo
forall a b. TCMT IO a -> TCMT IO b -> TCMT IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> InteractionId -> TCM ScopeInfo
forall (m :: * -> *).
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m) =>
InteractionId -> m ScopeInfo
getInteractionScope InteractionId
ii
  Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([InteractionId] -> Bool
forall a. Null a => a -> Bool
null [InteractionId]
iis) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
    let time :: Int
time = Int
1000 Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` [InteractionId] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [InteractionId]
iis
    TCState
st <- StateT CommandState TCM TCState
forall (m :: * -> *). MonadTCState m => m TCState
getTC
    [InteractionId]
solved <- ([[InteractionId]] -> [InteractionId])
-> StateT CommandState TCM [[InteractionId]]
-> StateT CommandState TCM [InteractionId]
forall a b.
(a -> b) -> StateT CommandState TCM a -> StateT CommandState TCM b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [[InteractionId]] -> [InteractionId]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (StateT CommandState TCM [[InteractionId]]
 -> StateT CommandState TCM [InteractionId])
-> StateT CommandState TCM [[InteractionId]]
-> StateT CommandState TCM [InteractionId]
forall a b. (a -> b) -> a -> b
$ [InteractionId]
-> (InteractionId -> StateT CommandState TCM [InteractionId])
-> StateT CommandState TCM [[InteractionId]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [InteractionId]
iis ((InteractionId -> StateT CommandState TCM [InteractionId])
 -> StateT CommandState TCM [[InteractionId]])
-> (InteractionId -> StateT CommandState TCM [InteractionId])
-> StateT CommandState TCM [[InteractionId]]
forall a b. (a -> b) -> a -> b
$ \ InteractionId
ii -> do
      Range
rng <- InteractionId -> StateT CommandState TCM Range
forall (m :: * -> *).
(MonadInteractionPoints m, MonadFail m, MonadError TCErr m) =>
InteractionId -> m Range
getInteractionRange InteractionId
ii
      MimerResult
res <- Rewrite -> InteractionId -> Range -> String -> CommandM MimerResult
forall (tcm :: * -> *).
MonadTCM tcm =>
Rewrite -> InteractionId -> Range -> String -> tcm MimerResult
Mimer.mimer Rewrite
norm InteractionId
ii Range
rng (String
"-t " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
time String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"ms")
      case MimerResult
res of
        MimerResult
MimerNoResult -> [InteractionId] -> StateT CommandState TCM [InteractionId]
forall a. a -> StateT CommandState TCM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
        MimerExpr String
str -> do
          InteractionId -> ScopeInfo -> StateT CommandState TCM ()
insertOldInteractionScope InteractionId
ii (ScopeInfo -> StateT CommandState TCM ())
-> CommandM ScopeInfo -> StateT CommandState TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< InteractionId -> CommandM ScopeInfo
getOldScope InteractionId
ii
          Response -> StateT CommandState TCM ()
putResponse (Response -> StateT CommandState TCM ())
-> Response -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId -> GiveResult -> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
InteractionId
-> GiveResult
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_GiveAction InteractionId
ii (GiveResult -> Response) -> GiveResult -> Response
forall a b. (a -> b) -> a -> b
$ String -> GiveResult
Give_String String
str
          [InteractionId] -> StateT CommandState TCM [InteractionId]
forall a. a -> StateT CommandState TCM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [InteractionId
ii]
        MimerList{} -> [InteractionId] -> StateT CommandState TCM [InteractionId]
forall a. a -> StateT CommandState TCM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []    -- Don't list solutions in autoAll
        MimerClauses{} -> StateT CommandState TCM [InteractionId]
forall a. HasCallStack => a
__IMPOSSIBLE__  -- Mimer can't do case splitting yet
    ([InteractionId] -> [InteractionId]) -> StateT CommandState TCM ()
modifyTheInteractionPoints ([InteractionId] -> [InteractionId] -> [InteractionId]
forall a. Eq a => [a] -> [a] -> [a]
List.\\ [InteractionId]
solved)

interpret (Cmd_context Rewrite
norm InteractionId
ii Range
_ String
_) =
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> ([ResponseContextEntry]
    -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors)
-> [ResponseContextEntry]
-> StateT CommandState TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InteractionId
-> [ResponseContextEntry]
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
InteractionId
-> [ResponseContextEntry]
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Context InteractionId
ii ([ResponseContextEntry] -> StateT CommandState TCM ())
-> StateT CommandState TCM [ResponseContextEntry]
-> StateT CommandState TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCM [ResponseContextEntry]
-> StateT CommandState TCM [ResponseContextEntry]
forall a. TCM a -> CommandM a
liftLocalState (Rewrite -> InteractionId -> TCM [ResponseContextEntry]
B.getResponseContext Rewrite
norm InteractionId
ii)

interpret (Cmd_helper_function Rewrite
norm InteractionId
ii Range
rng String
s) = do
  -- Create type of application of new helper function that would solve the goal.
  OutputConstraint' Expr Expr
helperType <- TCM (OutputConstraint' Expr Expr)
-> CommandM (OutputConstraint' Expr Expr)
forall a. TCM a -> CommandM a
liftLocalState (TCM (OutputConstraint' Expr Expr)
 -> CommandM (OutputConstraint' Expr Expr))
-> TCM (OutputConstraint' Expr Expr)
-> CommandM (OutputConstraint' Expr Expr)
forall a b. (a -> b) -> a -> b
$ InteractionId
-> TCM (OutputConstraint' Expr Expr)
-> TCM (OutputConstraint' Expr Expr)
forall (m :: * -> *) a.
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m, MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCM (OutputConstraint' Expr Expr)
 -> TCM (OutputConstraint' Expr Expr))
-> TCM (OutputConstraint' Expr Expr)
-> TCM (OutputConstraint' Expr Expr)
forall a b. (a -> b) -> a -> b
$ TCM (OutputConstraint' Expr Expr)
-> TCM (OutputConstraint' Expr Expr)
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (TCM (OutputConstraint' Expr Expr)
 -> TCM (OutputConstraint' Expr Expr))
-> TCM (OutputConstraint' Expr Expr)
-> TCM (OutputConstraint' Expr Expr)
forall a b. (a -> b) -> a -> b
$ Rewrite
-> InteractionId
-> Range
-> String
-> TCM (OutputConstraint' Expr Expr)
B.metaHelperType Rewrite
norm InteractionId
ii Range
rng String
s
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId
-> GoalDisplayInfo_boot TCErr
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
InteractionId
-> GoalDisplayInfo_boot tcErr
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_GoalSpecific InteractionId
ii (OutputConstraint' Expr Expr -> GoalDisplayInfo_boot TCErr
forall tcErr.
OutputConstraint' Expr Expr -> GoalDisplayInfo_boot tcErr
Goal_HelperFunction OutputConstraint' Expr Expr
helperType)

interpret (Cmd_infer Rewrite
norm InteractionId
ii Range
rng String
s) = do
  Expr
expr <- TCM Expr -> CommandM Expr
forall a. TCM a -> CommandM a
liftLocalState (TCM Expr -> CommandM Expr) -> TCM Expr -> CommandM Expr
forall a b. (a -> b) -> a -> b
$ InteractionId -> TCM Expr -> TCM Expr
forall (m :: * -> *) a.
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m, MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$ InteractionId -> Rewrite -> Expr -> TCM Expr
B.typeInMeta InteractionId
ii Rewrite
norm (Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< InteractionId -> Range -> String -> TCM Expr
B.parseExprIn InteractionId
ii Range
rng String
s
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId
-> GoalDisplayInfo_boot TCErr
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
InteractionId
-> GoalDisplayInfo_boot tcErr
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_GoalSpecific InteractionId
ii (Expr -> GoalDisplayInfo_boot TCErr
forall tcErr. Expr -> GoalDisplayInfo_boot tcErr
Goal_InferredType Expr
expr)

interpret (Cmd_goal_type Rewrite
norm InteractionId
ii Range
_ String
_) =
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId
-> GoalDisplayInfo_boot TCErr
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
InteractionId
-> GoalDisplayInfo_boot tcErr
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_GoalSpecific InteractionId
ii (Rewrite -> GoalDisplayInfo_boot TCErr
forall tcErr. Rewrite -> GoalDisplayInfo_boot tcErr
Goal_CurrentGoal Rewrite
norm)

interpret (Cmd_elaborate_give Rewrite
norm InteractionId
ii Range
rng String
s) =
  UseForce
-> InteractionId
-> Range
-> String
-> GiveRefine
-> StateT CommandState TCM ()
give_gen UseForce
WithoutForce InteractionId
ii Range
rng String
s (GiveRefine -> StateT CommandState TCM ())
-> GiveRefine -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ Rewrite -> GiveRefine
ElaborateGive Rewrite
norm

interpret (Cmd_goal_type_context Rewrite
norm InteractionId
ii Range
rng String
s) =
  GoalTypeAux
-> Rewrite
-> InteractionId
-> Range
-> String
-> StateT CommandState TCM ()
cmd_goal_type_context_and GoalTypeAux
GoalOnly Rewrite
norm InteractionId
ii Range
rng String
s

interpret (Cmd_goal_type_context_infer Rewrite
norm InteractionId
ii Range
rng String
s) = do
  -- In case of the empty expression to type, don't fail with
  -- a stupid parse error, but just fall back to
  -- Cmd_goal_type_context.
  GoalTypeAux
aux <- if (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
Char.isSpace String
s
            then GoalTypeAux -> StateT CommandState TCM GoalTypeAux
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return GoalTypeAux
GoalOnly
            else do
              TCM GoalTypeAux -> StateT CommandState TCM GoalTypeAux
forall a. TCM a -> CommandM a
liftLocalState (TCM GoalTypeAux -> StateT CommandState TCM GoalTypeAux)
-> TCM GoalTypeAux -> StateT CommandState TCM GoalTypeAux
forall a b. (a -> b) -> a -> b
$ InteractionId -> TCM GoalTypeAux -> TCM GoalTypeAux
forall (m :: * -> *) a.
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m, MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCM GoalTypeAux -> TCM GoalTypeAux)
-> TCM GoalTypeAux -> TCM GoalTypeAux
forall a b. (a -> b) -> a -> b
$ do
                Expr
parsed <- InteractionId -> Range -> String -> TCM Expr
B.parseExprIn InteractionId
ii Range
rng String
s
                (Expr
typ, [IPFace' Expr]
faces) <- InteractionId -> Rewrite -> Expr -> TCM (Expr, [IPFace' Expr])
B.typeAndFacesInMeta InteractionId
ii Rewrite
norm Expr
parsed
                GoalTypeAux -> TCM GoalTypeAux
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> [IPFace' Expr] -> GoalTypeAux
GoalAndHave Expr
typ [IPFace' Expr]
faces)
  GoalTypeAux
-> Rewrite
-> InteractionId
-> Range
-> String
-> StateT CommandState TCM ()
cmd_goal_type_context_and GoalTypeAux
aux Rewrite
norm InteractionId
ii Range
rng String
s

interpret (Cmd_goal_type_context_check Rewrite
norm InteractionId
ii Range
rng String
s) = do
  Term
term <- TCM Term -> CommandM Term
forall a. TCM a -> CommandM a
liftLocalState (TCM Term -> CommandM Term) -> TCM Term -> CommandM Term
forall a b. (a -> b) -> a -> b
$ InteractionId -> TCM Term -> TCM Term
forall (m :: * -> *) a.
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m, MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
    Expr
expr <- InteractionId -> Range -> String -> TCM Expr
B.parseExprIn InteractionId
ii Range
rng String
s
    OutputConstraint Expr InteractionId
goal <- Rewrite
-> InteractionId -> TCM (OutputConstraint Expr InteractionId)
B.typeOfMeta Rewrite
AsIs InteractionId
ii
    Term
term <- case OutputConstraint Expr InteractionId
goal of
      OfType InteractionId
_ Expr
ty -> Expr -> Type -> TCM Term
checkExpr Expr
expr (Type -> TCM Term) -> TCMT IO Type -> TCM Term
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Expr -> TCMT IO Type
isType_ Expr
ty
      OutputConstraint Expr InteractionId
_           -> TCM Term
forall a. HasCallStack => a
__IMPOSSIBLE__
    Rewrite -> Term -> TCM Term
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
B.normalForm Rewrite
norm Term
term
  GoalTypeAux
-> Rewrite
-> InteractionId
-> Range
-> String
-> StateT CommandState TCM ()
cmd_goal_type_context_and (Term -> GoalTypeAux
GoalAndElaboration Term
term) Rewrite
norm InteractionId
ii Range
rng String
s

interpret (Cmd_show_module_contents Rewrite
norm InteractionId
ii Range
rng String
s) =
  (forall a. TCM a -> TCM a)
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a. (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
liftCommandMT (InteractionId -> TCMT IO x -> TCMT IO x
forall (m :: * -> *) a.
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m, MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ Rewrite -> Range -> String -> StateT CommandState TCM ()
showModuleContents Rewrite
norm Range
rng String
s

interpret (Cmd_why_in_scope_toplevel String
s) =
  StateT CommandState TCM () -> StateT CommandState TCM ()
forall a. CommandM a -> CommandM a
atTopLevel (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String -> StateT CommandState TCM ()
whyInScope String
s

interpret (Cmd_why_in_scope InteractionId
ii Range
_range String
s) =
  (forall a. TCM a -> TCM a)
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a. (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
liftCommandMT (InteractionId -> TCMT IO x -> TCMT IO x
forall (m :: * -> *) a.
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m, MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String -> StateT CommandState TCM ()
whyInScope String
s

interpret (Cmd_make_case InteractionId
ii Range
rng String
s) = do
  (QName
f, CaseContext
casectxt, [Clause]
cs) <- TCMT IO (QName, CaseContext, [Clause])
-> StateT CommandState TCM (QName, CaseContext, [Clause])
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO (QName, CaseContext, [Clause])
 -> StateT CommandState TCM (QName, CaseContext, [Clause]))
-> TCMT IO (QName, CaseContext, [Clause])
-> StateT CommandState TCM (QName, CaseContext, [Clause])
forall a b. (a -> b) -> a -> b
$ InteractionId
-> Range -> String -> TCMT IO (QName, CaseContext, [Clause])
makeCase InteractionId
ii Range
rng String
s
  (forall a. TCM a -> TCM a)
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a. (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
liftCommandMT (InteractionId -> TCMT IO x -> TCMT IO x
forall (m :: * -> *) a.
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m, MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
    Telescope
tel <- TCM Telescope -> StateT CommandState TCM Telescope
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM Telescope -> StateT CommandState TCM Telescope)
-> TCM Telescope -> StateT CommandState TCM Telescope
forall a b. (a -> b) -> a -> b
$ ModuleName -> TCM Telescope
forall (m :: * -> *).
(Functor m, ReadTCState m) =>
ModuleName -> m Telescope
lookupSection (QName -> ModuleName
qnameModule QName
f) -- don't shadow the names in this telescope
    UnicodeOrAscii
unicode <- (TCState -> UnicodeOrAscii)
-> StateT CommandState TCM UnicodeOrAscii
forall (m :: * -> *) a. ReadTCState m => (TCState -> a) -> m a
getsTC ((TCState -> UnicodeOrAscii)
 -> StateT CommandState TCM UnicodeOrAscii)
-> (TCState -> UnicodeOrAscii)
-> StateT CommandState TCM UnicodeOrAscii
forall a b. (a -> b) -> a -> b
$ PragmaOptions -> UnicodeOrAscii
optUseUnicode (PragmaOptions -> UnicodeOrAscii)
-> (TCState -> PragmaOptions) -> TCState -> UnicodeOrAscii
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCState -> PragmaOptions
forall a. LensPragmaOptions a => a -> PragmaOptions
getPragmaOptions
    [Doc]
pcs      :: [Doc]      <- TCM [Doc] -> StateT CommandState TCM [Doc]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM [Doc] -> StateT CommandState TCM [Doc])
-> TCM [Doc] -> StateT CommandState TCM [Doc]
forall a b. (a -> b) -> a -> b
$ TCM [Doc] -> TCM [Doc]
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (TCM [Doc] -> TCM [Doc]) -> TCM [Doc] -> TCM [Doc]
forall a b. (a -> b) -> a -> b
$ Telescope -> TCM [Doc] -> TCM [Doc]
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
forall (m :: * -> *) a.
MonadAddContext m =>
Telescope -> m a -> m a
addContext Telescope
tel (TCM [Doc] -> TCM [Doc]) -> TCM [Doc] -> TCM [Doc]
forall a b. (a -> b) -> a -> b
$ (Clause -> TCMT IO Doc) -> [Clause] -> TCM [Doc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Clause -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA [Clause]
cs
    let [String]
pcs' :: [String]    = (Doc -> String) -> [Doc] -> [String]
forall a b. (a -> b) -> [a] -> [b]
List.map (UnicodeOrAscii -> CaseContext -> String -> String
extlam_dropName UnicodeOrAscii
unicode CaseContext
casectxt (String -> String) -> (Doc -> String) -> Doc -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> String
decorate) [Doc]
pcs
    TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"interaction.case" Int
60 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TCP.vcat
      [ TCMT IO Doc
"InteractionTop.Cmd_make_case"
      , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TCP.nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TCP.vcat
        [ TCMT IO Doc
"cs   = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TCP.<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TCP.vcat ((Clause -> TCMT IO Doc) -> [Clause] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map Clause -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA [Clause]
cs)
        , TCMT IO Doc
"pcs  = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TCP.<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TCP.vcat ((Doc -> TCMT IO Doc) -> [Doc] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map Doc -> TCMT IO Doc
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return [Doc]
pcs)
        , TCMT IO Doc
"pcs' = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TCP.<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TCP.vcat ((String -> TCMT IO Doc) -> [String] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
TCP.text [String]
pcs')
        ]
      ]
    TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"interaction.case" Int
90 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TCP.vcat
      [ TCMT IO Doc
"InteractionTop.Cmd_make_case"
      , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TCP.nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TCP.vcat
        [ TCMT IO Doc
"cs   = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TCP.<+> String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
TCP.text ([Clause] -> String
forall a. Show a => a -> String
show [Clause]
cs)
        ]
      ]
    Response -> StateT CommandState TCM ()
putResponse (Response -> StateT CommandState TCM ())
-> Response -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId -> MakeCaseVariant -> [String] -> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
InteractionId
-> MakeCaseVariant
-> [String]
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_MakeCase InteractionId
ii (CaseContext -> MakeCaseVariant
makeCaseVariant CaseContext
casectxt) [String]
pcs'


interpret (Cmd_compute ComputeMode
cmode InteractionId
ii Range
rng String
s) = do
  Expr
expr <- TCM Expr -> CommandM Expr
forall a. TCM a -> CommandM a
liftLocalState (TCM Expr -> CommandM Expr) -> TCM Expr -> CommandM Expr
forall a b. (a -> b) -> a -> b
$ do
    Expr
e <- InteractionId -> Range -> String -> TCM Expr
B.parseExprIn InteractionId
ii Range
rng (String -> TCM Expr) -> String -> TCM Expr
forall a b. (a -> b) -> a -> b
$ ComputeMode -> String -> String
B.computeWrapInput ComputeMode
cmode String
s
    InteractionId -> TCM Expr -> TCM Expr
forall (m :: * -> *) a.
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m, MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$ Bool -> (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall b a. IsBool b => b -> (a -> a) -> a -> a
applyWhen (ComputeMode -> Bool
B.computeIgnoreAbstract ComputeMode
cmode) TCM Expr -> TCM Expr
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
ignoreAbstractMode (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$ ComputeMode -> Expr -> TCM Expr
B.evalInCurrent ComputeMode
cmode Expr
e
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId
-> GoalDisplayInfo_boot TCErr
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
InteractionId
-> GoalDisplayInfo_boot tcErr
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_GoalSpecific InteractionId
ii (ComputeMode -> Expr -> GoalDisplayInfo_boot TCErr
forall tcErr. ComputeMode -> Expr -> GoalDisplayInfo_boot tcErr
Goal_NormalForm ComputeMode
cmode Expr
expr)

interpret Interaction' Range
Cmd_show_version = DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Version

interpret Interaction' Range
Cmd_abort = () -> StateT CommandState TCM ()
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
interpret Interaction' Range
Cmd_exit  = () -> StateT CommandState TCM ()
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return ()


decorate :: Doc -> String
decorate :: Doc -> String
decorate = Style -> Doc -> String
forall a. Style -> Doc a -> String
renderStyle (Style
style { mode = OneLineMode })

makeCaseVariant :: CaseContext -> MakeCaseVariant
makeCaseVariant :: CaseContext -> MakeCaseVariant
makeCaseVariant CaseContext
Nothing = MakeCaseVariant
R.Function
makeCaseVariant Just{}  = MakeCaseVariant
R.ExtendedLambda

-- very dirty hack, string manipulation by dropping the function name
-- and replacing the last " = " with " -> ". It's important not to replace
-- the equal sign in named implicit with an arrow!
extlam_dropName :: UnicodeOrAscii -> CaseContext -> String -> String
extlam_dropName :: UnicodeOrAscii -> CaseContext -> String -> String
extlam_dropName UnicodeOrAscii
_ CaseContext
Nothing String
x = String
x
extlam_dropName UnicodeOrAscii
glyphMode Just{}  String
x
    = [String] -> String
unwords ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [String] -> [String]
forall a. [a] -> [a]
reverse ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ [String] -> [String]
replEquals ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ [String] -> [String]
forall a. [a] -> [a]
reverse ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ Int -> [String] -> [String]
forall a. Int -> [a] -> [a]
drop Int
1 ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ String -> [String]
words String
x
  where
    arrow :: String
arrow = Doc -> String
forall a. Doc a -> String
render (Doc -> String) -> Doc -> String
forall a b. (a -> b) -> a -> b
$ SpecialCharacters -> Doc
_arrow (SpecialCharacters -> Doc) -> SpecialCharacters -> Doc
forall a b. (a -> b) -> a -> b
$ UnicodeOrAscii -> SpecialCharacters
specialCharactersForGlyphs UnicodeOrAscii
glyphMode
    replEquals :: [String] -> [String]
replEquals (String
"=" : [String]
ws) = String
arrow String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
ws
    replEquals (String
w   : [String]
ws) = String
w String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String] -> [String]
replEquals [String]
ws
    replEquals []         = []

-- | Solved goals already instantiated internally
-- The second argument potentially limits it to one specific goal.
solveInstantiatedGoals :: Rewrite -> Maybe InteractionId -> CommandM ()
solveInstantiatedGoals :: Rewrite -> Maybe InteractionId -> StateT CommandState TCM ()
solveInstantiatedGoals Rewrite
norm Maybe InteractionId
mii = do
  -- Andreas, 2016-10-23 issue #2280: throw away meta elims.
  [(InteractionId, Expr)]
out <- TCM [(InteractionId, Expr)]
-> StateT CommandState TCM [(InteractionId, Expr)]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM [(InteractionId, Expr)]
 -> StateT CommandState TCM [(InteractionId, Expr)])
-> TCM [(InteractionId, Expr)]
-> StateT CommandState TCM [(InteractionId, Expr)]
forall a b. (a -> b) -> a -> b
$ (TCEnv -> TCEnv)
-> TCM [(InteractionId, Expr)] -> TCM [(InteractionId, Expr)]
forall a. (TCEnv -> TCEnv) -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a.
MonadTCEnv m =>
(TCEnv -> TCEnv) -> m a -> m a
localTC (\ TCEnv
e -> TCEnv
e { envPrintMetasBare = True }) (TCM [(InteractionId, Expr)] -> TCM [(InteractionId, Expr)])
-> TCM [(InteractionId, Expr)] -> TCM [(InteractionId, Expr)]
forall a b. (a -> b) -> a -> b
$ do
    [(InteractionId, MetaId, Expr)]
sip <- Bool -> Rewrite -> TCM [(InteractionId, MetaId, Expr)]
B.getSolvedInteractionPoints Bool
False Rewrite
norm
           -- only solve metas which have a proper instantiation, i.e., not another meta
    let sip' :: [(InteractionId, MetaId, Expr)]
sip' = ([(InteractionId, MetaId, Expr)]
 -> [(InteractionId, MetaId, Expr)])
-> (InteractionId
    -> [(InteractionId, MetaId, Expr)]
    -> [(InteractionId, MetaId, Expr)])
-> Maybe InteractionId
-> [(InteractionId, MetaId, Expr)]
-> [(InteractionId, MetaId, Expr)]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [(InteractionId, MetaId, Expr)] -> [(InteractionId, MetaId, Expr)]
forall a. a -> a
id (\ InteractionId
ii -> ((InteractionId, MetaId, Expr) -> Bool)
-> [(InteractionId, MetaId, Expr)]
-> [(InteractionId, MetaId, Expr)]
forall a. (a -> Bool) -> [a] -> [a]
filter ((InteractionId
ii InteractionId -> InteractionId -> Bool
forall a. Eq a => a -> a -> Bool
==) (InteractionId -> Bool)
-> ((InteractionId, MetaId, Expr) -> InteractionId)
-> (InteractionId, MetaId, Expr)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (InteractionId, MetaId, Expr) -> InteractionId
forall a b c. (a, b, c) -> a
fst3)) Maybe InteractionId
mii [(InteractionId, MetaId, Expr)]
sip
    ((InteractionId, MetaId, Expr) -> TCMT IO (InteractionId, Expr))
-> [(InteractionId, MetaId, Expr)] -> TCM [(InteractionId, Expr)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (InteractionId, MetaId, Expr) -> TCMT IO (InteractionId, Expr)
(InteractionId, MetaId, Expr)
-> TCMT IO (InteractionId, ConOfAbs Expr)
forall {m :: * -> *} {a} {a}.
(MonadTrace m, ToConcrete a, MonadFresh NameId m,
 MonadInteractionPoints m, MonadStConcreteNames m, PureTCM m,
 IsString (m Doc), Null (m Doc), Semigroup (m Doc)) =>
(a, MetaId, a) -> m (a, ConOfAbs a)
prt [(InteractionId, MetaId, Expr)]
sip'
  Response -> StateT CommandState TCM ()
putResponse (Response -> StateT CommandState TCM ())
-> Response -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ [(InteractionId, Expr)] -> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
[(InteractionId, Expr)]
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_SolveAll [(InteractionId, Expr)]
out
  where
      prt :: (a, MetaId, a) -> m (a, ConOfAbs a)
prt (a
i, MetaId
m, a
e) = do
        Closure Range
mi <- MetaVariable -> Closure Range
getMetaInfo (MetaVariable -> Closure Range)
-> m MetaVariable -> m (Closure Range)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaId -> m MetaVariable
forall (m :: * -> *).
(HasCallStack, MonadDebug m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupLocalMeta MetaId
m
        ConOfAbs a
e' <- Closure Range -> m (ConOfAbs a) -> m (ConOfAbs a)
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadTrace m) =>
Closure Range -> m a -> m a
withMetaInfo Closure Range
mi (m (ConOfAbs a) -> m (ConOfAbs a))
-> m (ConOfAbs a) -> m (ConOfAbs a)
forall a b. (a -> b) -> a -> b
$ Precedence -> a -> m (ConOfAbs a)
forall a (m :: * -> *).
(ToConcrete a, MonadAbsToCon m) =>
Precedence -> a -> m (ConOfAbs a)
abstractToConcreteCtx Precedence
TopCtx a
e
        (a, ConOfAbs a) -> m (a, ConOfAbs a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
i, ConOfAbs a
e')

-- | @cmd_load' file argv unsolvedOk cmd@
--   loads the module in file @file@,
--   using @argv@ as the command-line options.
--
-- If type checking completes without any exceptions having been
-- encountered then the command @cmd r@ is executed, where @r@ is the
-- result of 'Imp.typeCheckMain'.

cmd_load'
  :: FilePath  -- ^ File to load into interaction.
  -> [String]  -- ^ Arguments to Agda for loading this file
  -> Bool      -- ^ Allow unsolved meta-variables?
  -> Mode      -- ^ Full type-checking, or only scope-checking?
  -> (CheckResult -> CommandM a)
               -- ^ Continuation after successful loading.
  -> CommandM a
cmd_load' :: forall a.
String
-> [String]
-> Bool
-> Mode
-> (CheckResult -> CommandM a)
-> CommandM a
cmd_load' String
file [String]
argv Bool
unsolvedOK Mode
mode CheckResult -> CommandM a
cmd = do
    AbsolutePath
fp <- IO AbsolutePath -> StateT CommandState TCM AbsolutePath
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO AbsolutePath -> StateT CommandState TCM AbsolutePath)
-> IO AbsolutePath -> StateT CommandState TCM AbsolutePath
forall a b. (a -> b) -> a -> b
$ String -> IO AbsolutePath
absolute String
file
    Bool
ex <- IO Bool -> StateT CommandState TCM Bool
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> StateT CommandState TCM Bool)
-> IO Bool -> StateT CommandState TCM Bool
forall a b. (a -> b) -> a -> b
$ String -> IO Bool
doesFileExist (String -> IO Bool) -> String -> IO Bool
forall a b. (a -> b) -> a -> b
$ AbsolutePath -> String
filePath AbsolutePath
fp
    Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
ex (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ TypeError -> StateT CommandState TCM ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> StateT CommandState TCM ())
-> TypeError -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String -> TypeError
GenericError (String -> TypeError) -> String -> TypeError
forall a b. (a -> b) -> a -> b
$
      String
"The file " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
file String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" was not found."

    -- Forget the previous "current file" and interaction points.
    (CommandState -> CommandState) -> StateT CommandState TCM ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((CommandState -> CommandState) -> StateT CommandState TCM ())
-> (CommandState -> CommandState) -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ \ CommandState
st -> CommandState
st { theInteractionPoints = []
                        , theCurrentFile       = Nothing
                        }

    ClockTime
t <- IO ClockTime -> StateT CommandState TCM ClockTime
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ClockTime -> StateT CommandState TCM ClockTime)
-> IO ClockTime -> StateT CommandState TCM ClockTime
forall a b. (a -> b) -> a -> b
$ String -> IO ClockTime
getModificationTime String
file

    -- Update the status. Because the "current file" is not set the
    -- status is not "Checked".
    StateT CommandState TCM ()
displayStatus

    -- Reset the state, preserving options and decoded modules. Note
    -- that if the include directories have changed, then the decoded
    -- modules are reset by TCM.setCommandLineOptions' below.
    TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCM ()
resetState

    -- Clear the info buffer to make room for information about which
    -- module is currently being type-checked.
    Response -> StateT CommandState TCM ()
putResponse Response
forall tcErr tcWarning warningsAndNonFatalErrors.
Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_ClearRunningInfo

    -- Remove any prior syntax highlighting.
    Response -> StateT CommandState TCM ()
putResponse (TokenBased -> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
TokenBased
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_ClearHighlighting TokenBased
NotOnlyTokenBased)

    -- Parse the file.
    --
    -- Note that options are set below.
    Source
src <- TCM Source -> StateT CommandState TCM Source
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM Source -> StateT CommandState TCM Source)
-> TCM Source -> StateT CommandState TCM Source
forall a b. (a -> b) -> a -> b
$ SourceFile -> TCM Source
Imp.parseSource (AbsolutePath -> SourceFile
SourceFile AbsolutePath
fp)

    -- Store the warnings.
    [TCWarning]
warnings <- Lens' TCState [TCWarning] -> StateT CommandState TCM [TCWarning]
forall (m :: * -> *) a. ReadTCState m => Lens' TCState a -> m a
useTC ([TCWarning] -> f [TCWarning]) -> TCState -> f TCState
Lens' TCState [TCWarning]
stTCWarnings

    -- All options are reset when a file is reloaded, including the
    -- choice of whether or not to display implicit arguments.
    CommandLineOptions
opts0 <- (CommandState -> CommandLineOptions)
-> StateT CommandState TCM CommandLineOptions
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets CommandState -> CommandLineOptions
optionsOnReload
    [Backend]
backends <- Lens' TCState [Backend] -> StateT CommandState TCM [Backend]
forall (m :: * -> *) a. ReadTCState m => Lens' TCState a -> m a
useTC ([Backend] -> f [Backend]) -> TCState -> f TCState
Lens' TCState [Backend]
stBackends
    let (Either String ([Backend], CommandLineOptions)
z, OptionWarnings
warns) = OptM ([Backend], CommandLineOptions)
-> (Either String ([Backend], CommandLineOptions), OptionWarnings)
forall opts. OptM opts -> (Either String opts, OptionWarnings)
runOptM (OptM ([Backend], CommandLineOptions)
 -> (Either String ([Backend], CommandLineOptions), OptionWarnings))
-> OptM ([Backend], CommandLineOptions)
-> (Either String ([Backend], CommandLineOptions), OptionWarnings)
forall a b. (a -> b) -> a -> b
$ [Backend]
-> [String]
-> CommandLineOptions
-> OptM ([Backend], CommandLineOptions)
parseBackendOptions [Backend]
backends [String]
argv CommandLineOptions
opts0
    (OptionWarning -> StateT CommandState TCM ())
-> OptionWarnings -> StateT CommandState TCM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> (OptionWarning -> TCM ())
-> OptionWarning
-> StateT CommandState TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Warning -> TCM ()
forall (m :: * -> *).
(HasCallStack, MonadWarning m) =>
Warning -> m ()
warning (Warning -> TCM ())
-> (OptionWarning -> Warning) -> OptionWarning -> TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OptionWarning -> Warning
OptionWarning) OptionWarnings
warns
    case Either String ([Backend], CommandLineOptions)
z of
      Left String
err -> TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ TypeError -> TCM ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ String -> TypeError
GenericError String
err
      Right ([Backend]
_, CommandLineOptions
opts) -> do
        CommandLineOptions
opts <- TCM CommandLineOptions
-> StateT CommandState TCM CommandLineOptions
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM CommandLineOptions
 -> StateT CommandState TCM CommandLineOptions)
-> TCM CommandLineOptions
-> StateT CommandState TCM CommandLineOptions
forall a b. (a -> b) -> a -> b
$ CommandLineOptions -> TCM CommandLineOptions
addTrustedExecutables CommandLineOptions
opts
        let update :: PragmaOptions -> PragmaOptions
update = Lens' PragmaOptions Bool -> LensMap PragmaOptions Bool
forall o i. Lens' o i -> LensMap o i
over ((WithDefault 'False -> f (WithDefault 'False))
-> PragmaOptions -> f PragmaOptions
forall (f :: * -> *).
Functor f =>
(WithDefault 'False -> f (WithDefault 'False))
-> PragmaOptions -> f PragmaOptions
lensOptAllowUnsolved ((WithDefault 'False -> f (WithDefault 'False))
 -> PragmaOptions -> f PragmaOptions)
-> ((Bool -> f Bool)
    -> WithDefault 'False -> f (WithDefault 'False))
-> (Bool -> f Bool)
-> PragmaOptions
-> f PragmaOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> f Bool) -> WithDefault 'False -> f (WithDefault 'False)
forall a (b :: Bool).
(Boolean a, Eq a, KnownBool b) =>
Lens' (WithDefault' a b) a
Lens' (WithDefault 'False) Bool
lensKeepDefault) (Bool
unsolvedOK Bool -> Bool -> Bool
&&)
            root :: AbsolutePath
root   = AbsolutePath -> TopLevelModuleName -> AbsolutePath
projectRoot AbsolutePath
fp (TopLevelModuleName -> AbsolutePath)
-> TopLevelModuleName -> AbsolutePath
forall a b. (a -> b) -> a -> b
$ Source -> TopLevelModuleName
Imp.srcModuleName Source
src
        TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ AbsolutePath -> CommandLineOptions -> TCM ()
TCM.setCommandLineOptions' AbsolutePath
root (CommandLineOptions -> TCM ()) -> CommandLineOptions -> TCM ()
forall a b. (a -> b) -> a -> b
$ (PragmaOptions -> PragmaOptions)
-> CommandLineOptions -> CommandLineOptions
forall a.
LensPragmaOptions a =>
(PragmaOptions -> PragmaOptions) -> a -> a
mapPragmaOptions PragmaOptions -> PragmaOptions
update CommandLineOptions
opts

    -- Restore the warnings that were saved above.
    Lens' TCState [TCWarning]
-> ([TCWarning] -> [TCWarning]) -> StateT CommandState TCM ()
forall (m :: * -> *) a.
MonadTCState m =>
Lens' TCState a -> (a -> a) -> m ()
modifyTCLens ([TCWarning] -> f [TCWarning]) -> TCState -> f TCState
Lens' TCState [TCWarning]
stTCWarnings ([TCWarning] -> [TCWarning] -> [TCWarning]
forall a. [a] -> [a] -> [a]
++ [TCWarning]
warnings)

    CheckResult
ok <- TCMT IO CheckResult -> StateT CommandState TCM CheckResult
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO CheckResult -> StateT CommandState TCM CheckResult)
-> TCMT IO CheckResult -> StateT CommandState TCM CheckResult
forall a b. (a -> b) -> a -> b
$ Mode -> Source -> TCMT IO CheckResult
Imp.typeCheckMain Mode
mode Source
src

    -- The module type checked. If the file was not changed while the
    -- type checker was running then the interaction points and the
    -- "current file" are stored.
    ClockTime
t' <- IO ClockTime -> StateT CommandState TCM ClockTime
forall a. IO a -> StateT CommandState TCM a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ClockTime -> StateT CommandState TCM ClockTime)
-> IO ClockTime -> StateT CommandState TCM ClockTime
forall a b. (a -> b) -> a -> b
$ String -> IO ClockTime
getModificationTime String
file
    Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (ClockTime
t ClockTime -> ClockTime -> Bool
forall a. Eq a => a -> a -> Bool
== ClockTime
t') (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
      [InteractionId]
is <- TCM [InteractionId] -> StateT CommandState TCM [InteractionId]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM [InteractionId] -> StateT CommandState TCM [InteractionId])
-> TCM [InteractionId] -> StateT CommandState TCM [InteractionId]
forall a b. (a -> b) -> a -> b
$ [InteractionId] -> TCM [InteractionId]
forall (m :: * -> *).
(MonadInteractionPoints m, MonadError TCErr m, MonadFail m) =>
[InteractionId] -> m [InteractionId]
sortInteractionPoints ([InteractionId] -> TCM [InteractionId])
-> TCM [InteractionId] -> TCM [InteractionId]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCM [InteractionId]
forall (m :: * -> *). ReadTCState m => m [InteractionId]
getInteractionPoints
      (CommandState -> CommandState) -> StateT CommandState TCM ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((CommandState -> CommandState) -> StateT CommandState TCM ())
-> (CommandState -> CommandState) -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ \CommandState
st -> CommandState
st { theInteractionPoints = is
                         , theCurrentFile       = Just $ CurrentFile
                             { currentFilePath   = fp
                             , currentFileModule = Imp.srcModuleName src
                             , currentFileArgs   = argv
                             , currentFileStamp  = t
                             }
                         }

    CheckResult -> CommandM a
cmd CheckResult
ok

-- | Set 'envCurrentPath' to 'theCurrentFile', if any.
withCurrentFile :: CommandM a -> CommandM a
withCurrentFile :: forall a. CommandM a -> CommandM a
withCurrentFile CommandM a
m = do
  Maybe AbsolutePath
mfile <- (CommandState -> Maybe AbsolutePath)
-> StateT CommandState TCM (Maybe AbsolutePath)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((CommandState -> Maybe AbsolutePath)
 -> StateT CommandState TCM (Maybe AbsolutePath))
-> (CommandState -> Maybe AbsolutePath)
-> StateT CommandState TCM (Maybe AbsolutePath)
forall a b. (a -> b) -> a -> b
$ (CurrentFile -> AbsolutePath)
-> Maybe CurrentFile -> Maybe AbsolutePath
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CurrentFile -> AbsolutePath
currentFilePath (Maybe CurrentFile -> Maybe AbsolutePath)
-> (CommandState -> Maybe CurrentFile)
-> CommandState
-> Maybe AbsolutePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CommandState -> Maybe CurrentFile
theCurrentFile
  (TCEnv -> TCEnv) -> CommandM a -> CommandM a
forall a.
(TCEnv -> TCEnv)
-> StateT CommandState TCM a -> StateT CommandState TCM a
forall (m :: * -> *) a.
MonadTCEnv m =>
(TCEnv -> TCEnv) -> m a -> m a
localTC (\ TCEnv
e -> TCEnv
e { envCurrentPath = mfile }) CommandM a
m

atTopLevel :: CommandM a -> CommandM a
atTopLevel :: forall a. CommandM a -> CommandM a
atTopLevel CommandM a
cmd = (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
forall a. (forall a. TCM a -> TCM a) -> CommandM a -> CommandM a
liftCommandMT TCM x -> TCM x
forall a. TCM a -> TCM a
B.atTopLevel CommandM a
cmd

---------------------------------------------------------------------------
-- Giving, refining.

data GiveRefine = Give | Refine | Intro | ElaborateGive Rewrite
  deriving (GiveRefine -> GiveRefine -> Bool
(GiveRefine -> GiveRefine -> Bool)
-> (GiveRefine -> GiveRefine -> Bool) -> Eq GiveRefine
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GiveRefine -> GiveRefine -> Bool
== :: GiveRefine -> GiveRefine -> Bool
$c/= :: GiveRefine -> GiveRefine -> Bool
/= :: GiveRefine -> GiveRefine -> Bool
Eq, Int -> GiveRefine -> String -> String
[GiveRefine] -> String -> String
GiveRefine -> String
(Int -> GiveRefine -> String -> String)
-> (GiveRefine -> String)
-> ([GiveRefine] -> String -> String)
-> Show GiveRefine
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> GiveRefine -> String -> String
showsPrec :: Int -> GiveRefine -> String -> String
$cshow :: GiveRefine -> String
show :: GiveRefine -> String
$cshowList :: [GiveRefine] -> String -> String
showList :: [GiveRefine] -> String -> String
Show)

-- | A "give"-like action (give, refine, etc).
--
--   @give_gen force ii rng s give_ref mk_newtxt@
--   acts on interaction point @ii@
--   occupying range @rng@,
--   placing the new content given by string @s@,
--   and replacing @ii@ by the newly created interaction points
--   in the state if safety checks pass (unless @force@ is applied).
give_gen
  :: UseForce       -- ^ Should safety checks be skipped?
  -> InteractionId
  -> Range
  -> String
  -> GiveRefine
  -> CommandM ()
give_gen :: UseForce
-> InteractionId
-> Range
-> String
-> GiveRefine
-> StateT CommandState TCM ()
give_gen UseForce
force InteractionId
ii Range
rng String
s0 GiveRefine
giveRefine = do
  let s :: String
s = String -> String
trim String
s0
  String -> Int -> String -> StateT CommandState TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> String -> m ()
reportSLn String
"interaction.give" Int
20 (String -> StateT CommandState TCM ())
-> String -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String
"give_gen  " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s
  -- Andreas, 2015-02-26 if string is empty do nothing rather
  -- than giving a parse error.
  Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (String -> Bool
forall a. Null a => a -> Bool
null String
s) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
    let give_ref :: UseForce -> InteractionId -> Maybe Range -> Expr -> TCM Expr
give_ref =
          case GiveRefine
giveRefine of
            GiveRefine
Give               -> UseForce -> InteractionId -> Maybe Range -> Expr -> TCM Expr
B.give
            GiveRefine
Refine             -> UseForce -> InteractionId -> Maybe Range -> Expr -> TCM Expr
B.refine
            GiveRefine
Intro              -> UseForce -> InteractionId -> Maybe Range -> Expr -> TCM Expr
B.refine
            ElaborateGive Rewrite
norm -> Rewrite
-> UseForce -> InteractionId -> Maybe Range -> Expr -> TCM Expr
B.elaborate_give Rewrite
norm
    -- save scope of the interaction point (for printing the given expr. later)
    ScopeInfo
scope     <- InteractionId -> CommandM ScopeInfo
forall (m :: * -> *).
(MonadDebug m, MonadFail m, ReadTCState m, MonadError TCErr m,
 MonadTCEnv m) =>
InteractionId -> m ScopeInfo
getInteractionScope InteractionId
ii
    -- parse string and "give", obtaining an abstract expression
    -- and newly created interaction points
    (Maybe CPUTime
time, (Expr
ae, Expr
ae0, [InteractionId]
iis)) <- CommandM (Expr, Expr, [InteractionId])
-> CommandM (Maybe CPUTime, (Expr, Expr, [InteractionId]))
forall a. CommandM a -> CommandM (Maybe CPUTime, a)
maybeTimed (CommandM (Expr, Expr, [InteractionId])
 -> CommandM (Maybe CPUTime, (Expr, Expr, [InteractionId])))
-> CommandM (Expr, Expr, [InteractionId])
-> CommandM (Maybe CPUTime, (Expr, Expr, [InteractionId]))
forall a b. (a -> b) -> a -> b
$ do
        -- Issue 3000: mark the current hole as solved before giving, to avoid confusing it with potential
        -- new interaction points introduced by the give.
        InteractionId -> StateT CommandState TCM ()
forall (m :: * -> *).
MonadInteractionPoints m =>
InteractionId -> m ()
removeInteractionPoint InteractionId
ii
        [InteractionId]
mis  <- StateT CommandState TCM [InteractionId]
forall (m :: * -> *). ReadTCState m => m [InteractionId]
getInteractionPoints
        String -> Int -> String -> StateT CommandState TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> String -> m ()
reportSLn String
"interaction.give" Int
30 (String -> StateT CommandState TCM ())
-> String -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String
"interaction points before = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [InteractionId] -> String
forall a. Show a => a -> String
show [InteractionId]
mis
        Expr
given <- TCM Expr -> CommandM Expr
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM Expr -> CommandM Expr) -> TCM Expr -> CommandM Expr
forall a b. (a -> b) -> a -> b
$ InteractionId -> Range -> String -> TCM Expr
B.parseExprIn InteractionId
ii Range
rng String
s
        Expr
ae    <- TCM Expr -> CommandM Expr
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM Expr -> CommandM Expr) -> TCM Expr -> CommandM Expr
forall a b. (a -> b) -> a -> b
$ UseForce -> InteractionId -> Maybe Range -> Expr -> TCM Expr
give_ref UseForce
force InteractionId
ii Maybe Range
forall a. Maybe a
Nothing Expr
given
        [InteractionId]
mis' <- StateT CommandState TCM [InteractionId]
forall (m :: * -> *). ReadTCState m => m [InteractionId]
getInteractionPoints
        String -> Int -> String -> StateT CommandState TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> String -> m ()
reportSLn String
"interaction.give" Int
30 (String -> StateT CommandState TCM ())
-> String -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String
"interaction points after = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [InteractionId] -> String
forall a. Show a => a -> String
show [InteractionId]
mis'
        (Expr, Expr, [InteractionId])
-> CommandM (Expr, Expr, [InteractionId])
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr
ae, Expr
given, [InteractionId]
mis' [InteractionId] -> [InteractionId] -> [InteractionId]
forall a. Eq a => [a] -> [a] -> [a]
List.\\ [InteractionId]
mis)
    -- favonia: backup the old scope for highlighting
    InteractionId -> ScopeInfo -> StateT CommandState TCM ()
insertOldInteractionScope InteractionId
ii ScopeInfo
scope
    -- sort the new interaction points and put them into the state
    -- in replacement of the old interaction point
    [InteractionId]
iis' <- [InteractionId] -> StateT CommandState TCM [InteractionId]
forall (m :: * -> *).
(MonadInteractionPoints m, MonadError TCErr m, MonadFail m) =>
[InteractionId] -> m [InteractionId]
sortInteractionPoints [InteractionId]
iis
    ([InteractionId] -> [InteractionId]) -> StateT CommandState TCM ()
modifyTheInteractionPoints (([InteractionId] -> [InteractionId])
 -> StateT CommandState TCM ())
-> ([InteractionId] -> [InteractionId])
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId
-> [InteractionId] -> [InteractionId] -> [InteractionId]
forall {t :: * -> *} {b}.
(Foldable t, Eq b) =>
b -> [b] -> t b -> [b]
replace InteractionId
ii [InteractionId]
iis'
    -- print abstract expr
    Expr
ce        <- ScopeInfo -> Expr -> StateT CommandState TCM (ConOfAbs Expr)
forall a (m :: * -> *).
(ToConcrete a, MonadAbsToCon m) =>
ScopeInfo -> a -> m (ConOfAbs a)
abstractToConcreteScope ScopeInfo
scope Expr
ae
    String -> Int -> [String] -> StateT CommandState TCM ()
forall a (m :: * -> *).
(ReportS a, MonadDebug m) =>
String -> Int -> a -> m ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> [String] -> m ()
reportS String
"interaction.give" Int
30
      [ String
"ce = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Expr -> String
forall a. Show a => a -> String
show Expr
ce
      , String
"scopePrecedence = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ PrecedenceStack -> String
forall a. Show a => a -> String
show (ScopeInfo
scope ScopeInfo -> Lens' ScopeInfo PrecedenceStack -> PrecedenceStack
forall o i. o -> Lens' o i -> i
^. (PrecedenceStack -> f PrecedenceStack) -> ScopeInfo -> f ScopeInfo
Lens' ScopeInfo PrecedenceStack
scopePrecedence)
      ]

    -- Issue 7218: if the give/refine command creates an extended
    -- lambda, it also needs to be added to the relevant unfolding sets.
    -- The easiest way to make sure this is consistent is to just re-run
    -- the saturation procedures.
    StateT CommandState TCM ()
forall (m :: * -> *).
(MonadTCState m, ReadTCState m, MonadFresh OpaqueId m,
 MonadDebug m, MonadTrace m, MonadWarning m, MonadIO m) =>
m ()
saturateOpaqueBlocks

    -- if the command was @Give@, use the literal user input;
    -- Andreas, 2014-01-15, see issue 1020:
    -- Refine could solve a goal by introducing the sole constructor
    -- without arguments.  Then there are no interaction metas, but
    -- we still cannot just `give' the user string (which may be empty).
    -- WRONG: also, if no interaction metas were created by @Refine@
    -- WRONG: let literally = (giveRefine == Give || null iis) && rng /= noRange
    -- Ulf, 2015-03-30, if we're doing intro we can't do literal give since
    -- there is nothing in the hole (issue 1892).
    let literally :: Bool
literally = (GiveRefine
giveRefine GiveRefine -> GiveRefine -> Bool
forall a. Eq a => a -> a -> Bool
== GiveRefine
Give Bool -> Bool -> Bool
|| GiveRefine
giveRefine GiveRefine -> GiveRefine -> Bool
forall a. Eq a => a -> a -> Bool
== GiveRefine
Refine) Bool -> Bool -> Bool
&& Expr
ae Expr -> Expr -> Bool
forall a. Eq a => a -> a -> Bool
== Expr
ae0 Bool -> Bool -> Bool
&& Range
rng Range -> Range -> Bool
forall a. Eq a => a -> a -> Bool
/= Range
forall a. Range' a
noRange
    -- Ulf, 2014-01-24: This works for give since we're highlighting the string
    -- that's already in the buffer. Doing it before the give action means that
    -- the highlighting is moved together with the text when the hole goes away.
    -- To make it work for refine we'd have to adjust the ranges.
    Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
literally (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
      HighlightingLevel
l <- (TCEnv -> HighlightingLevel)
-> StateT CommandState TCM HighlightingLevel
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> HighlightingLevel
envHighlightingLevel
      Bool -> StateT CommandState TCM () -> StateT CommandState TCM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (HighlightingLevel
l HighlightingLevel -> HighlightingLevel -> Bool
forall a. Eq a => a -> a -> Bool
/= HighlightingLevel
None) (StateT CommandState TCM () -> StateT CommandState TCM ())
-> StateT CommandState TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ do
        RemoveTokenBasedHighlighting -> HighlightingInfo -> TCM ()
forall (m :: * -> *).
MonadTrace m =>
RemoveTokenBasedHighlighting -> HighlightingInfo -> m ()
printHighlightingInfo RemoveTokenBasedHighlighting
KeepHighlighting (HighlightingInfo -> TCM ()) -> TCMT IO HighlightingInfo -> TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
          Range -> String -> TCMT IO HighlightingInfo
generateTokenInfoFromString Range
rng String
s
        Expr -> TCM ()
highlightExpr Expr
ae
    Response -> StateT CommandState TCM ()
putResponse (Response -> StateT CommandState TCM ())
-> Response -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId -> GiveResult -> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
InteractionId
-> GiveResult
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_GiveAction InteractionId
ii (GiveResult -> Response) -> GiveResult -> Response
forall a b. (a -> b) -> a -> b
$ Bool -> Expr -> GiveResult
mkNewTxt Bool
literally Expr
ce
    String -> Int -> String -> StateT CommandState TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> String -> m ()
reportSLn String
"interaction.give" Int
30 (String -> StateT CommandState TCM ())
-> String -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String
"putResponse GiveAction passed"
    -- display new goal set (if not measuring time)
    StateT CommandState TCM ()
-> (CPUTime -> StateT CommandState TCM ())
-> Maybe CPUTime
-> StateT CommandState TCM ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Interaction' Range -> StateT CommandState TCM ()
interpret (Interaction' Range -> StateT CommandState TCM ())
-> Interaction' Range -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ Rewrite -> Interaction' Range
forall range. Rewrite -> Interaction' range
Cmd_metas Rewrite
AsIs) (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> (CPUTime
    -> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors)
-> CPUTime
-> StateT CommandState TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CPUTime
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
CPUTime
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_Time) Maybe CPUTime
time
    String -> Int -> String -> StateT CommandState TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> String -> m ()
reportSLn String
"interaction.give" Int
30 (String -> StateT CommandState TCM ())
-> String -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ String
"interpret Cmd_metas passed"
  where
    -- Substitutes xs for x in ys.
    replace :: b -> [b] -> t b -> [b]
replace b
x [b]
xs t b
ys = (b -> [b]) -> t b -> [b]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\ b
y -> if b
y b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== b
x then [b]
xs else [b
y]) t b
ys
    -- For @Give@ we can replace the ii by the user given input.
    mkNewTxt :: Bool -> Expr -> GiveResult
mkNewTxt Bool
True  C.Paren{} = GiveResult
Give_Paren
    mkNewTxt Bool
True  Expr
_         = GiveResult
Give_NoParen
    -- Otherwise, we replace it by the reified value Agda computed.
    mkNewTxt Bool
False Expr
ce        = String -> GiveResult
Give_String (String -> GiveResult) -> String -> GiveResult
forall a b. (a -> b) -> a -> b
$ Expr -> String
forall a. Pretty a => a -> String
prettyShow Expr
ce

highlightExpr :: A.Expr -> TCM ()
highlightExpr :: Expr -> TCM ()
highlightExpr Expr
e =
  (TCEnv -> TCEnv) -> TCM () -> TCM ()
forall a. (TCEnv -> TCEnv) -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a.
MonadTCEnv m =>
(TCEnv -> TCEnv) -> m a -> m a
localTC (\TCEnv
st -> TCEnv
st { envImportPath         = []
                     , envHighlightingLevel  = NonInteractive
                     , envHighlightingMethod = Direct }) (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$
    Declaration -> Level -> Bool -> TCM ()
generateAndPrintSyntaxInfo Declaration
decl Level
Full Bool
True
  where
    dummy :: Name
dummy = NameId -> String -> Name
forall a. MkName a => NameId -> a -> Name
mkName_ (Hash -> ModuleNameHash -> NameId
NameId Hash
0 ModuleNameHash
noModuleNameHash) (String
"dummy" :: String)
    info :: DefInfo' Expr
info  = Name -> Fixity' -> Access -> IsAbstract -> Range -> DefInfo' Expr
forall t.
Name -> Fixity' -> Access -> IsAbstract -> Range -> DefInfo' t
mkDefInfo (Name -> Name
nameConcrete Name
dummy) Fixity'
noFixity' Access
PublicAccess IsAbstract
ConcreteDef (Expr -> Range
forall a. HasRange a => a -> Range
getRange Expr
e)
    decl :: Declaration
decl  = KindOfName
-> DefInfo' Expr
-> ArgInfo
-> Maybe [Occurrence]
-> QName
-> Expr
-> Declaration
A.Axiom KindOfName
OtherDefName DefInfo' Expr
info ArgInfo
defaultArgInfo Maybe [Occurrence]
forall a. Maybe a
Nothing (List1 Name -> QName
qnameFromList (List1 Name -> QName) -> List1 Name -> QName
forall a b. (a -> b) -> a -> b
$ Name -> List1 Name
forall el coll. Singleton el coll => el -> coll
singleton Name
dummy) Expr
e

-- | Sorts interaction points based on their ranges.

sortInteractionPoints
  :: (MonadInteractionPoints m, MonadError TCErr m, MonadFail m)
  => [InteractionId] -> m [InteractionId]
sortInteractionPoints :: forall (m :: * -> *).
(MonadInteractionPoints m, MonadError TCErr m, MonadFail m) =>
[InteractionId] -> m [InteractionId]
sortInteractionPoints [InteractionId]
is =
  ((InteractionId, Range) -> InteractionId)
-> [(InteractionId, Range)] -> [InteractionId]
forall a b. (a -> b) -> [a] -> [b]
map (InteractionId, Range) -> InteractionId
forall a b. (a, b) -> a
fst ([(InteractionId, Range)] -> [InteractionId])
-> ([(InteractionId, Range)] -> [(InteractionId, Range)])
-> [(InteractionId, Range)]
-> [InteractionId]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((InteractionId, Range) -> (InteractionId, Range) -> Ordering)
-> [(InteractionId, Range)] -> [(InteractionId, Range)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
List.sortBy (Range -> Range -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Range -> Range -> Ordering)
-> ((InteractionId, Range) -> Range)
-> (InteractionId, Range)
-> (InteractionId, Range)
-> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (InteractionId, Range) -> Range
forall a b. (a, b) -> b
snd) ([(InteractionId, Range)] -> [InteractionId])
-> m [(InteractionId, Range)] -> m [InteractionId]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
    [InteractionId]
-> (InteractionId -> m (InteractionId, Range))
-> m [(InteractionId, Range)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [InteractionId]
is ((InteractionId -> m (InteractionId, Range))
 -> m [(InteractionId, Range)])
-> (InteractionId -> m (InteractionId, Range))
-> m [(InteractionId, Range)]
forall a b. (a -> b) -> a -> b
$ \ InteractionId
i -> do
      (InteractionId
i,) (Range -> (InteractionId, Range))
-> m Range -> m (InteractionId, Range)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> InteractionId -> m Range
forall (m :: * -> *).
(MonadInteractionPoints m, MonadFail m, MonadError TCErr m) =>
InteractionId -> m Range
getInteractionRange InteractionId
i

-- | Displays the current goal, the given document, and the current
--   context.
--
--   Should not modify the state.

cmd_goal_type_context_and :: GoalTypeAux -> Rewrite -> InteractionId -> Range ->
                             String -> CommandM ()
cmd_goal_type_context_and :: GoalTypeAux
-> Rewrite
-> InteractionId
-> Range
-> String
-> StateT CommandState TCM ()
cmd_goal_type_context_and GoalTypeAux
aux Rewrite
norm InteractionId
ii Range
_ String
_ = do
  [ResponseContextEntry]
ctx <- TCM [ResponseContextEntry]
-> StateT CommandState TCM [ResponseContextEntry]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM [ResponseContextEntry]
 -> StateT CommandState TCM [ResponseContextEntry])
-> TCM [ResponseContextEntry]
-> StateT CommandState TCM [ResponseContextEntry]
forall a b. (a -> b) -> a -> b
$ Rewrite -> InteractionId -> TCM [ResponseContextEntry]
B.getResponseContext Rewrite
norm InteractionId
ii
  [OutputForm_boot TCErr Expr Expr]
constr <- TCM [OutputForm_boot TCErr Expr Expr]
-> StateT CommandState TCM [OutputForm_boot TCErr Expr Expr]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM [OutputForm_boot TCErr Expr Expr]
 -> StateT CommandState TCM [OutputForm_boot TCErr Expr Expr])
-> TCM [OutputForm_boot TCErr Expr Expr]
-> StateT CommandState TCM [OutputForm_boot TCErr Expr Expr]
forall a b. (a -> b) -> a -> b
$ InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii TCMT IO MetaId
-> (MetaId -> TCM [OutputForm_boot TCErr Expr Expr])
-> TCM [OutputForm_boot TCErr Expr Expr]
forall a b. TCMT IO a -> (a -> TCMT IO b) -> TCMT IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Rewrite -> MetaId -> TCM [OutputForm_boot TCErr Expr Expr]
B.getConstraintsMentioning Rewrite
norm
  [IPFace' Expr]
boundary <- TCMT IO [IPFace' Expr] -> StateT CommandState TCM [IPFace' Expr]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO [IPFace' Expr] -> StateT CommandState TCM [IPFace' Expr])
-> TCMT IO [IPFace' Expr] -> StateT CommandState TCM [IPFace' Expr]
forall a b. (a -> b) -> a -> b
$ Rewrite -> InteractionId -> TCMT IO [IPFace' Expr]
B.getIPBoundary Rewrite
norm InteractionId
ii
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ InteractionId
-> GoalDisplayInfo_boot TCErr
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
InteractionId
-> GoalDisplayInfo_boot tcErr
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_GoalSpecific InteractionId
ii (Rewrite
-> GoalTypeAux
-> [ResponseContextEntry]
-> [IPFace' Expr]
-> [OutputForm_boot TCErr Expr Expr]
-> GoalDisplayInfo_boot TCErr
forall tcErr.
Rewrite
-> GoalTypeAux
-> [ResponseContextEntry]
-> [IPFace' Expr]
-> [OutputForm_boot tcErr Expr Expr]
-> GoalDisplayInfo_boot tcErr
Goal_GoalType Rewrite
norm GoalTypeAux
aux [ResponseContextEntry]
ctx [IPFace' Expr]
boundary [OutputForm_boot TCErr Expr Expr]
constr)

-- | Shows all the top-level names in the given module, along with
-- their types.

showModuleContents :: Rewrite -> Range -> String -> CommandM ()
showModuleContents :: Rewrite -> Range -> String -> StateT CommandState TCM ()
showModuleContents Rewrite
norm Range
rng String
s = do
  ([Name]
modules, Telescope
tel, [(Name, Type)]
types) <- TCMT IO ([Name], Telescope, [(Name, Type)])
-> StateT CommandState TCM ([Name], Telescope, [(Name, Type)])
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO ([Name], Telescope, [(Name, Type)])
 -> StateT CommandState TCM ([Name], Telescope, [(Name, Type)]))
-> TCMT IO ([Name], Telescope, [(Name, Type)])
-> StateT CommandState TCM ([Name], Telescope, [(Name, Type)])
forall a b. (a -> b) -> a -> b
$ Rewrite
-> Range -> String -> TCMT IO ([Name], Telescope, [(Name, Type)])
B.moduleContents Rewrite
norm Range
rng String
s
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ [Name]
-> Telescope
-> [(Name, Type)]
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
[Name]
-> Telescope
-> [(Name, Type)]
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_ModuleContents [Name]
modules Telescope
tel [(Name, Type)]
types

-- | Shows all the top-level names in scope which mention all the given
-- identifiers in their type.

searchAbout :: Rewrite -> Range -> String -> CommandM ()
searchAbout :: Rewrite -> Range -> String -> StateT CommandState TCM ()
searchAbout Rewrite
norm Range
rg String
names = do
  String
-> (String -> StateT CommandState TCM ())
-> StateT CommandState TCM ()
forall (m :: * -> *) a.
(Monad m, Null a) =>
a -> (a -> m ()) -> m ()
unlessNull (String -> String
trim String
names) ((String -> StateT CommandState TCM ())
 -> StateT CommandState TCM ())
-> (String -> StateT CommandState TCM ())
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ \ String
trimmedNames -> do
    [(Name, Type)]
hits <- TCMT IO [(Name, Type)] -> StateT CommandState TCM [(Name, Type)]
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO [(Name, Type)] -> StateT CommandState TCM [(Name, Type)])
-> TCMT IO [(Name, Type)] -> StateT CommandState TCM [(Name, Type)]
forall a b. (a -> b) -> a -> b
$ Rewrite -> Range -> String -> TCMT IO [(Name, Type)]
findMentions Rewrite
norm Range
rg String
trimmedNames
    DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ [(Name, Type)]
-> String
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
[(Name, Type)]
-> String
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_SearchAbout [(Name, Type)]
hits String
trimmedNames

-- | Explain why something is in scope.

whyInScope :: String -> CommandM ()
whyInScope :: String -> StateT CommandState TCM ()
whyInScope String
s = do
  Just CurrentFile
file <- (CommandState -> Maybe CurrentFile)
-> StateT CommandState TCM (Maybe CurrentFile)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets CommandState -> Maybe CurrentFile
theCurrentFile
  let cwd :: String
cwd = String -> String
takeDirectory (AbsolutePath -> String
filePath (AbsolutePath -> String) -> AbsolutePath -> String
forall a b. (a -> b) -> a -> b
$ CurrentFile -> AbsolutePath
currentFilePath CurrentFile
file)
  WhyInScopeData
why <- TCM WhyInScopeData -> CommandM WhyInScopeData
forall a. TCM a -> CommandM a
liftLocalState (TCM WhyInScopeData -> CommandM WhyInScopeData)
-> TCM WhyInScopeData -> CommandM WhyInScopeData
forall a b. (a -> b) -> a -> b
$ String -> String -> TCM WhyInScopeData
B.whyInScope String
cwd String
s
  DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info (DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
 -> StateT CommandState TCM ())
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ WhyInScopeData
-> DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
forall tcErr tcWarning warningsAndNonFatalErrors.
WhyInScopeData
-> DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
Info_WhyInScope WhyInScopeData
why

-- | Sets the command line options and updates the status information.

setCommandLineOpts :: CommandLineOptions -> CommandM ()
setCommandLineOpts :: CommandLineOptions -> StateT CommandState TCM ()
setCommandLineOpts CommandLineOptions
opts = do
    TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ CommandLineOptions -> TCM ()
TCM.setCommandLineOptions CommandLineOptions
opts
    StateT CommandState TCM ()
displayStatus


-- | Computes some status information.
--
--   Does not change the state.

status :: CommandM Status
status :: CommandM Status
status = do
  Maybe CurrentFile
cf       <- (CommandState -> Maybe CurrentFile)
-> StateT CommandState TCM (Maybe CurrentFile)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets CommandState -> Maybe CurrentFile
theCurrentFile
  Bool
showImpl <- TCMT IO Bool -> StateT CommandState TCM Bool
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCMT IO Bool
forall (m :: * -> *). HasOptions m => m Bool
showImplicitArguments
  Bool
showIrr  <- TCMT IO Bool -> StateT CommandState TCM Bool
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift TCMT IO Bool
forall (m :: * -> *). HasOptions m => m Bool
showIrrelevantArguments

  -- Check if the file was successfully type checked, and has not
  -- changed since. Note: This code does not check if any dependencies
  -- have changed, and uses a time stamp to check for changes.
  Bool
checked  <- TCMT IO Bool -> StateT CommandState TCM Bool
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO Bool -> StateT CommandState TCM Bool)
-> TCMT IO Bool -> StateT CommandState TCM Bool
forall a b. (a -> b) -> a -> b
$ case Maybe CurrentFile
cf of
    Maybe CurrentFile
Nothing -> Bool -> TCMT IO Bool
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
    Just CurrentFile
f  -> do
      ClockTime
t <- IO ClockTime -> TCMT IO ClockTime
forall b. IO b -> TCM b
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ClockTime -> TCMT IO ClockTime)
-> IO ClockTime -> TCMT IO ClockTime
forall a b. (a -> b) -> a -> b
$ String -> IO ClockTime
getModificationTime (String -> IO ClockTime) -> String -> IO ClockTime
forall a b. (a -> b) -> a -> b
$ AbsolutePath -> String
filePath (CurrentFile -> AbsolutePath
currentFilePath CurrentFile
f)
      if CurrentFile -> ClockTime
currentFileStamp CurrentFile
f ClockTime -> ClockTime -> Bool
forall a. Eq a => a -> a -> Bool
== ClockTime
t
        then
          Bool -> (ModuleInfo -> Bool) -> Maybe ModuleInfo -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False ([TCWarning] -> Bool
forall a. Null a => a -> Bool
null ([TCWarning] -> Bool)
-> (ModuleInfo -> [TCWarning]) -> ModuleInfo -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModuleInfo -> [TCWarning]
miWarnings) (Maybe ModuleInfo -> Bool)
-> TCMT IO (Maybe ModuleInfo) -> TCMT IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          TopLevelModuleName -> TCMT IO (Maybe ModuleInfo)
forall (m :: * -> *).
ReadTCState m =>
TopLevelModuleName -> m (Maybe ModuleInfo)
getVisitedModule (CurrentFile -> TopLevelModuleName
currentFileModule CurrentFile
f)
        else
            Bool -> TCMT IO Bool
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False

  Status -> CommandM Status
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return (Status -> CommandM Status) -> Status -> CommandM Status
forall a b. (a -> b) -> a -> b
$ Status { sShowImplicitArguments :: Bool
sShowImplicitArguments   = Bool
showImpl,
                    sShowIrrelevantArguments :: Bool
sShowIrrelevantArguments = Bool
showIrr,
                    sChecked :: Bool
sChecked                 = Bool
checked }

-- | Displays or updates status information.
--
--   Does not change the state.

displayStatus :: CommandM ()
displayStatus :: StateT CommandState TCM ()
displayStatus =
  Response -> StateT CommandState TCM ()
putResponse (Response -> StateT CommandState TCM ())
-> (Status -> Response) -> Status -> StateT CommandState TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Status -> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
Status -> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_Status  (Status -> StateT CommandState TCM ())
-> CommandM Status -> StateT CommandState TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< CommandM Status
status

-- | @display_info@ does what @'display_info'' False@ does, but
--   additionally displays some status information (see 'status' and
--   'displayStatus').

display_info :: DisplayInfo -> CommandM ()
display_info :: DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> StateT CommandState TCM ()
display_info DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
info = do
  StateT CommandState TCM ()
displayStatus
  Response -> StateT CommandState TCM ()
putResponse (Response -> StateT CommandState TCM ())
-> Response -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
-> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
DisplayInfo_boot tcErr tcWarning warningsAndNonFatalErrors
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_DisplayInfo DisplayInfo_boot TCErr TCWarning WarningsAndNonFatalErrors
info

-- | Parses and scope checks an expression (using the \"inside scope\"
-- as the scope), performs the given command with the expression as
-- input, and returns the result and the time it takes.

parseAndDoAtToplevel
  :: (A.Expr -> TCM a)
     -- ^ The command to perform.
  -> String
     -- ^ The expression to parse.
  -> CommandM (Maybe CPUTime, a)
parseAndDoAtToplevel :: forall a. (Expr -> TCM a) -> String -> CommandM (Maybe CPUTime, a)
parseAndDoAtToplevel Expr -> TCM a
cmd String
s = do
  CommandM (Maybe CPUTime, a) -> CommandM (Maybe CPUTime, a)
forall a. CommandM a -> CommandM a
localStateCommandM (CommandM (Maybe CPUTime, a) -> CommandM (Maybe CPUTime, a))
-> CommandM (Maybe CPUTime, a) -> CommandM (Maybe CPUTime, a)
forall a b. (a -> b) -> a -> b
$ do
    (Expr
e, Attributes
attrs) <- TCM (Expr, Attributes)
-> StateT CommandState TCM (Expr, Attributes)
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (Expr, Attributes)
 -> StateT CommandState TCM (Expr, Attributes))
-> TCM (Expr, Attributes)
-> StateT CommandState TCM (Expr, Attributes)
forall a b. (a -> b) -> a -> b
$ PM (Expr, Attributes) -> TCM (Expr, Attributes)
forall a. PM a -> TCM a
runPM (PM (Expr, Attributes) -> TCM (Expr, Attributes))
-> PM (Expr, Attributes) -> TCM (Expr, Attributes)
forall a b. (a -> b) -> a -> b
$ Parser Expr -> String -> PM (Expr, Attributes)
forall a. Parser a -> String -> PM (a, Attributes)
parse Parser Expr
exprParser String
s
    TCM () -> StateT CommandState TCM ()
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM () -> StateT CommandState TCM ())
-> TCM () -> StateT CommandState TCM ()
forall a b. (a -> b) -> a -> b
$ Attributes -> TCM ()
checkAttributes Attributes
attrs
    CommandM a -> CommandM (Maybe CPUTime, a)
forall a. CommandM a -> CommandM (Maybe CPUTime, a)
maybeTimed (CommandM a -> CommandM (Maybe CPUTime, a))
-> CommandM a -> CommandM (Maybe CPUTime, a)
forall a b. (a -> b) -> a -> b
$ CommandM a -> CommandM a
forall a. CommandM a -> CommandM a
atTopLevel (CommandM a -> CommandM a) -> CommandM a -> CommandM a
forall a b. (a -> b) -> a -> b
$ TCM a -> CommandM a
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM a -> CommandM a) -> TCM a -> CommandM a
forall a b. (a -> b) -> a -> b
$
      Expr -> TCM a
cmd (Expr -> TCM a) -> TCM Expr -> TCM a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Expr -> ScopeM (AbsOfCon Expr)
forall c. ToAbstract c => c -> ScopeM (AbsOfCon c)
concreteToAbstract_ Expr
e

maybeTimed :: CommandM a -> CommandM (Maybe CPUTime, a)
maybeTimed :: forall a. CommandM a -> CommandM (Maybe CPUTime, a)
maybeTimed CommandM a
work = do
  Bool
doTime <- TCMT IO Bool -> StateT CommandState TCM Bool
forall (m :: * -> *) a. Monad m => m a -> StateT CommandState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO Bool -> StateT CommandState TCM Bool)
-> TCMT IO Bool -> StateT CommandState TCM Bool
forall a b. (a -> b) -> a -> b
$ ProfileOption -> TCMT IO Bool
forall (m :: * -> *). MonadDebug m => ProfileOption -> m Bool
hasProfileOption ProfileOption
Profile.Interactive
  if Bool -> Bool
not Bool
doTime
    then (Maybe CPUTime
forall a. Maybe a
Nothing,) (a -> (Maybe CPUTime, a))
-> CommandM a -> CommandM (Maybe CPUTime, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CommandM a
work
    else do
      (a
r, CPUTime
time) <- CommandM a -> StateT CommandState TCM (a, CPUTime)
forall (m :: * -> *) a. MonadIO m => m a -> m (a, CPUTime)
measureTime CommandM a
work
      (Maybe CPUTime, a) -> CommandM (Maybe CPUTime, a)
forall a. a -> StateT CommandState TCM a
forall (m :: * -> *) a. Monad m => a -> m a
return (CPUTime -> Maybe CPUTime
forall a. a -> Maybe a
Just CPUTime
time, a
r)

-- | Tell to highlight the code using the given highlighting
-- info (unless it is @Nothing@).

tellToUpdateHighlighting
  :: Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource) -> IO [Response]
tellToUpdateHighlighting :: Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
-> IO [Response]
tellToUpdateHighlighting Maybe (HighlightingInfo, HighlightingMethod, ModuleToSource)
Nothing                = [Response] -> IO [Response]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
tellToUpdateHighlighting (Just (HighlightingInfo
info, HighlightingMethod
method, ModuleToSource
modFile)) =
  [Response] -> IO [Response]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return [HighlightingInfo
-> RemoveTokenBasedHighlighting
-> HighlightingMethod
-> ModuleToSource
-> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
HighlightingInfo
-> RemoveTokenBasedHighlighting
-> HighlightingMethod
-> ModuleToSource
-> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_HighlightingInfo HighlightingInfo
info RemoveTokenBasedHighlighting
KeepHighlighting HighlightingMethod
method ModuleToSource
modFile]

-- | Tells the Emacs mode to go to the first error position (if any).

tellEmacsToJumpToError :: Range -> [Response]
tellEmacsToJumpToError :: Range -> [Response]
tellEmacsToJumpToError Range
r =
  case Range -> Maybe (Position' (Maybe RangeFile))
forall a. Range' a -> Maybe (Position' a)
rStart Range
r of
    Maybe (Position' (Maybe RangeFile))
Nothing                                           -> []
    Just (Pn { srcFile :: forall a. Position' a -> a
srcFile = Maybe RangeFile
Strict.Nothing })            -> []
    Just (Pn { srcFile :: forall a. Position' a -> a
srcFile = Strict.Just RangeFile
f, posPos :: forall a. Position' a -> Int32
posPos = Int32
p }) ->
       [ String -> Int32 -> Response
forall tcErr tcWarning warningsAndNonFatalErrors.
String
-> Int32 -> Response_boot tcErr tcWarning warningsAndNonFatalErrors
Resp_JumpToError (AbsolutePath -> String
filePath (RangeFile -> AbsolutePath
rangeFilePath RangeFile
f)) Int32
p ]