mirror of
https://github.com/IHaskell/IHaskell.git
synced 2025-04-16 11:26:08 +00:00
Adding :m + and :m -. Closes #298.
This commit is contained in:
parent
7bff2be3f4
commit
20aa688a9a
@ -452,6 +452,22 @@ evalCommand output (Directive SetExtension opts) state = do
|
||||
let set = concatMap (" -X" ++) $ words opts
|
||||
evalCommand output (Directive SetDynFlag set) state
|
||||
|
||||
evalCommand output (Directive LoadModule mods) state = wrapExecution state $ do
|
||||
write $ "Load Module: " ++ mods
|
||||
let stripped@(firstChar:remainder) = mods
|
||||
(modules, removeModule) =
|
||||
case firstChar of
|
||||
'+' -> (words remainder, False)
|
||||
'-' -> (words remainder, True)
|
||||
_ -> (words stripped, False)
|
||||
|
||||
forM_ modules $ \modl ->
|
||||
if removeModule
|
||||
then removeImport modl
|
||||
else evalImport $ "import " ++ modl
|
||||
|
||||
return mempty
|
||||
|
||||
evalCommand a (Directive SetOption opts) state = do
|
||||
write $ "Option: " ++ opts
|
||||
let (existing, nonExisting) = partition optionExists $ words opts
|
||||
|
@ -67,6 +67,7 @@ data DirectiveType
|
||||
| SearchHoogle -- ^ Search for something via Hoogle.
|
||||
| GetDoc -- ^ Get documentation for an identifier via Hoogle.
|
||||
| GetKind -- ^ Get the kind of a type via ':kind'.
|
||||
| LoadModule -- ^ Load and unload modules via ':module'.
|
||||
deriving (Show, Eq)
|
||||
|
||||
-- | Pragma types. Only LANGUAGE pragmas are currently supported.
|
||||
@ -268,7 +269,8 @@ parseDirective (':':directive) line = case find rightDirective directives of
|
||||
[] -> False
|
||||
dir:_ -> dir `elem` tail (inits dirname)
|
||||
directives =
|
||||
[ (GetType, "type")
|
||||
[ (LoadModule, "module")
|
||||
, (GetType, "type")
|
||||
, (GetKind, "kind")
|
||||
, (GetInfo, "info")
|
||||
, (SearchHoogle, "hoogle")
|
||||
|
@ -11,6 +11,7 @@ module IHaskell.Eval.Util (
|
||||
|
||||
-- * Code Evaluation
|
||||
evalImport,
|
||||
removeImport,
|
||||
evalDeclarations,
|
||||
getType,
|
||||
getDescription,
|
||||
@ -196,6 +197,18 @@ evalImport imports = do
|
||||
Just (True, _) -> True
|
||||
_ -> False
|
||||
|
||||
removeImport :: GhcMonad m => String -> m ()
|
||||
removeImport moduleName = do
|
||||
flags <- getSessionDynFlags
|
||||
ctx <- getContext
|
||||
let ctx' = filter (not . (isImportOf $ mkModuleName moduleName)) ctx
|
||||
setContext ctx'
|
||||
|
||||
where
|
||||
isImportOf :: ModuleName -> InteractiveImport -> Bool
|
||||
isImportOf name (IIModule modName) = name == modName
|
||||
isImportOf name (IIDecl impDecl) = name == unLoc (ideclName impDecl)
|
||||
|
||||
-- | Evaluate a series of declarations.
|
||||
-- Return all names which were bound by these declarations.
|
||||
evalDeclarations :: GhcMonad m => String -> m [String]
|
||||
|
Loading…
x
Reference in New Issue
Block a user