git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add a :s import and :s loaded subcommand to respectively see the loaded

modules (in current session) and the imported modules

commit2689ec4c203c95f4fcec0cb29f9f8235c7febf8a authorAntoine R. Dumont <antoine.romain.dumont@gmail.com> dateFri 31 Oct 2014, 13:26 (12 years ago) parent84cf4dc
3 files changed+25−8
psci/Commands.hs+3−2 psci/Main.hs+17−3 psci/Parser.hs+5−3
psci/Commands.hs+3−2
@@ -64,7 +64,7 @@ data Command
6464 -- |
6565 -- Show command
6666 --
67− | Show
67+ | Show String
6868
6969-- |
7070-- The help menu.
@@ -79,5 +79,6 @@ help =
7979 , [":r ", "Reset"]
8080 , [":t <expr> ", "Show the type of <expr>"]
8181 , [":k <type> ", "Show the kind of <type>"]
82− , [":s ", "Show loaded modules" ]
82+ , [":s loaded ", "Show loaded modules" ]
83+ , [":s import ", "Show imported modules" ]
8384 ]
psci/Main.hs+17−3
@@ -305,14 +305,27 @@ handleDeclaration value = do
305305 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
306306 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
307307
308−handleShowModules :: PSCI ()
309−handleShowModules = do
308+-- |
309+-- Show actual loaded modules in psci.
310+--
311+handleShowLoadedModules :: PSCI ()
312+handleShowLoadedModules = do
310313 PSCiState { psciLoadedModules = loadedModules } <- PSCI $ lift get
311314 psciIO $ readModules loadedModules >>= putStrLn
312315 return ()
313316 where readModules = return . unlines . nub . map toModuleName
314317 toModuleName = N.runModuleName . (\ (D.Module mdName _ _) -> mdName) . snd
315318
319+-- |
320+-- Show the imported modules in psci.
321+--
322+handleShowImportedModules :: PSCI ()
323+handleShowImportedModules = do
324+ PSCiState { psciImportedModuleNames = importedModuleNames } <- PSCI $ lift get
325+ psciIO $ readModules importedModuleNames >>= putStrLn
326+ return ()
327+ where readModules = return . unlines . map N.runModuleName
328+
316329-- |
317330-- Imports a module, preserving the initial state on failure.
318331--
@@ -455,7 +468,8 @@ handleCommand Reset = do
455468handleCommand (TypeOf val) = handleTypeOf val
456469handleCommand (KindOf typ) = handleKindOf typ
457470handleCommand (Browse moduleName) = handleBrowse moduleName
458−handleCommand Show = handleShowModules
471+handleCommand (Show "loaded") = handleShowLoadedModules
472+handleCommand (Show "import") = handleShowImportedModules
459473handleCommand _ = PSCI $ outputStrLn "Unknown command"
460474
461475singleLineFlag :: Cmd.Term Bool
psci/Parser.hs+5−3
@@ -70,8 +70,10 @@ psciImport = Import <$> (char 'i' *> P.whiteSpace *> P.moduleName)
7070--
7171psciLoadFile :: Parsec String P.ParseState Command
7272psciLoadFile = LoadFile . trimEnd <$> (char 'm' *> P.whiteSpace *> manyTill anyChar eof)
73− where
74− trimEnd = reverse . dropWhile isSpace . reverse
73+
74+-- | Trim end of input string
75+trimEnd :: String -> String
76+trimEnd = reverse . dropWhile isSpace . reverse
7577
7678-- |
7779-- Parses 'Commands.Quit' command.
@@ -107,4 +109,4 @@ psciBrowse = Browse <$> (char 'b' *> P.whiteSpace *> P.moduleName)
107109-- |
108110-- Show Command
109111psciShowModules :: Parsec String P.ParseState Command
110−psciShowModules = Show <$ char 's'
112+psciShowModules = Show . trimEnd <$> (char 's' *> P.whiteSpace *> manyTill anyChar eof)