git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add a :s command to list the modules loaded in current session.
84cf4dcAntoine R. Dumont
psci/Commands.hs+5
@@ -61,6 +61,10 @@ data Command
61 -- Find the kind of an expression
61 -- Find the kind of an expression
62 --
62 --
63 | KindOf Type
63 | KindOf Type
64+ -- |
65+ -- Show command
66+ --
67+ | Show
64
68
65-- |
69-- |
66-- The help menu.
70-- The help menu.
@@ -75,4 +79,5 @@ help =
75 , [":r ", "Reset"]
79 , [":r ", "Reset"]
76 , [":t <expr> ", "Show the type of <expr>"]
80 , [":t <expr> ", "Show the type of <expr>"]
77 , [":k <type> ", "Show the kind of <type>"]
81 , [":k <type> ", "Show the kind of <type>"]
82+ , [":s ", "Show loaded modules" ]
78 ]
83 ]
psci/Main.hs+9
@@ -305,6 +305,14 @@ handleDeclaration value = do
305 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
305 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
306 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
306 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
307
307
308+handleShowModules :: PSCI ()
309+handleShowModules = do
310+ PSCiState { psciLoadedModules = loadedModules } <- PSCI $ lift get
311+ psciIO $ readModules loadedModules >>= putStrLn
312+ return ()
313+ where readModules = return . unlines . nub . map toModuleName
314+ toModuleName = N.runModuleName . (\ (D.Module mdName _ _) -> mdName) . snd
315+
308-- |
316-- |
309-- Imports a module, preserving the initial state on failure.
317-- Imports a module, preserving the initial state on failure.
310--
318--
@@ -447,6 +455,7 @@ handleCommand Reset = do
447handleCommand (TypeOf val) = handleTypeOf val
455handleCommand (TypeOf val) = handleTypeOf val
448handleCommand (KindOf typ) = handleKindOf typ
456handleCommand (KindOf typ) = handleKindOf typ
449handleCommand (Browse moduleName) = handleBrowse moduleName
457handleCommand (Browse moduleName) = handleBrowse moduleName
458+handleCommand Show = handleShowModules
450handleCommand _ = PSCI $ outputStrLn "Unknown command"
459handleCommand _ = PSCI $ outputStrLn "Unknown command"
451
460
452singleLineFlag :: Cmd.Term Bool
461singleLineFlag :: Cmd.Term Bool
psci/Parser.hs+6−1
@@ -42,7 +42,7 @@ psciLet = Let <$> (P.Let <$> (P.reserved "let" *> P.indented *> C.mark (many1 (C
42--
42--
43parseCommand :: String -> Either ParseError Command
43parseCommand :: String -> Either ParseError Command
44parseCommand = P.runIndentParser "" $ choice
44parseCommand = P.runIndentParser "" $ choice
45− [ P.whiteSpace *> char ':' *> (psciHelp <|> psciImport <|> psciLoadFile <|> psciQuit <|> psciReload <|> psciTypeOf <|> psciKindOf <|> psciBrowse)
45+ [ P.whiteSpace *> char ':' *> (psciHelp <|> psciImport <|> psciLoadFile <|> psciQuit <|> psciReload <|> psciTypeOf <|> psciKindOf <|> psciBrowse <|> psciShowModules)
46 , try psciLet
46 , try psciLet
47 , psciExpression
47 , psciExpression
48 ] <* eof
48 ] <* eof
@@ -103,3 +103,8 @@ psciKindOf = KindOf <$> (char 'k' *> P.whiteSpace *> P.parseType)
103--
103--
104psciBrowse :: Parsec String P.ParseState Command
104psciBrowse :: Parsec String P.ParseState Command
105psciBrowse = Browse <$> (char 'b' *> P.whiteSpace *> P.moduleName)
105psciBrowse = Browse <$> (char 'b' *> P.whiteSpace *> P.moduleName)
106+
107+-- |
108+-- Show Command
109+psciShowModules :: Parsec String P.ParseState Command
110+psciShowModules = Show <$ char 's'