@@ -72,12 +72,16 @@ data PSCiOptions = PSCiOptions
73data PSCiState = PSCiState
73data PSCiState = PSCiState
74 { psciImportedFilenames :: [FilePath]
74 { psciImportedFilenames :: [FilePath]
75− , psciImportedModuleNames :: [P.ModuleName]
75+ , psciImportedModules :: [C.ImportedModule]
76 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
76 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
77 , psciLetBindings :: [P.Declaration]
77 , psciLetBindings :: [P.Declaration]
78 , psciNodeFlags :: [String]
78 , psciNodeFlags :: [String]
81+psciImportedModuleNames :: PSCiState -> [P.ModuleName]
82+psciImportedModuleNames (PSCiState{psciImportedModules = is}) =
83+ map (\(mn, _, _) -> mn) is
81-- State helpers
85-- State helpers
@@ -89,8 +93,8 @@ updateImportedFiles filename st = st { psciImportedFilenames = filename : psciIm
90-- Updates the state to have more imported modules.
94-- Updates the state to have more imported modules.
92−updateImports :: P.ModuleName -> PSCiState -> PSCiState
96+updateImportedModules :: C.ImportedModule -> PSCiState -> PSCiState
93−updateImports name st = st { psciImportedModuleNames = name : psciImportedModuleNames st }
97+updateImportedModules im st = st { psciImportedModules = im : psciImportedModules st }
96-- Updates the state to have more loaded files.
100-- Updates the state to have more loaded files.
@@ -108,8 +112,8 @@ updateLets ds st = st { psciLetBindings = psciLetBindings st ++ ds }
109-- Load the necessary modules.
113-- Load the necessary modules.
111−defaultImports :: [P.ModuleName]
115+defaultImports :: [C.ImportedModule]
112−defaultImports = [P.ModuleName [P.ProperName "Prelude"]]
116+defaultImports = [(P.ModuleName [P.ProperName "Prelude"], D.Implicit, Nothing)]
115-- Locates the node executable.
119-- Locates the node executable.
@@ -181,7 +185,7 @@ helpMessage = "The following commands are available:\n\n " ++
181 , replicate (11 - length arg) ' '
185 , replicate (11 - length arg) ' '
184− where cmd = ":" ++ head (D.commands dir)
188+ where cmd = ":" ++ head (D.commands dir)
187-- The welcome prologue.
191-- The welcome prologue.
@@ -223,7 +227,6 @@ completionContext (':' : cmd) word =
223 dstr = takeWhile (not . isSpace) cmd
227 dstr = takeWhile (not . isSpace) cmd
225 context :: D.Directive -> Maybe CompletionContext
229 context :: D.Directive -> Maybe CompletionContext
226− context D.Import = Just Module
227 context D.Browse = Just Module
230 context D.Browse = Just Module
228 context D.Load = Just $ FilePath word
231 context D.Load = Just $ FilePath word
229 context D.Quit = Nothing
232 context D.Quit = Nothing
@@ -370,10 +373,9 @@ mkdirp = createDirectoryIfMissing True . takeDirectory
370-- Makes a volatile module to execute the current expression.
373-- Makes a volatile module to execute the current expression.
372createTemporaryModule :: Bool -> PSCiState -> P.Expr -> P.Module
375createTemporaryModule :: Bool -> PSCiState -> P.Expr -> P.Module
373−createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetBindings = lets} val =
376+createTemporaryModule exec PSCiState{psciImportedModules = imports, psciLetBindings = lets} val =
375 moduleName = P.ModuleName [P.ProperName "$PSCI"]
378 moduleName = P.ModuleName [P.ProperName "$PSCI"]
376− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
377 traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
379 traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
378 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
380 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
379 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
381 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
@@ -388,10 +390,9 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
388-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
390-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
390createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
392createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
391−createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
393+createTemporaryModuleForKind PSCiState{psciImportedModules = imports} typ =
393 moduleName = P.ModuleName [P.ProperName "$PSCI"]
395 moduleName = P.ModuleName [P.ProperName "$PSCI"]
394− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
395 itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
396 itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
397 P.Module [] moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
398 P.Module [] moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
@@ -400,13 +401,15 @@ createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
400-- Makes a volatile module to execute the current imports.
401-- Makes a volatile module to execute the current imports.
402createTemporaryModuleForImports :: PSCiState -> P.Module
403createTemporaryModuleForImports :: PSCiState -> P.Module
403−createTemporaryModuleForImports PSCiState{psciImportedModuleNames = imports} =
404+createTemporaryModuleForImports PSCiState{psciImportedModules = imports} =
405 moduleName = P.ModuleName [P.ProperName "$PSCI"]
406 moduleName = P.ModuleName [P.ProperName "$PSCI"]
406− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
408 P.Module [] moduleName (importDecl `map` imports) Nothing
408 P.Module [] moduleName (importDecl `map` imports) Nothing
410+importDecl :: C.ImportedModule -> P.Declaration
411+importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ
410modulesDir :: FilePath
413modulesDir :: FilePath
411modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
414modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
@@ -434,11 +437,11 @@ handleDeclaration val = do
434 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
437 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
437−-- Takes a let declaration and updates the environment, then run a make. If the declaration fails,
440+-- Takes a list of declarations and updates the environment, then run a make. If the declaration fails,
438−-- restore the pre-let environment.
441+-- restore the original environment.
440−handleLet :: [P.Declaration] -> PSCI ()
443+handleDecls :: [P.Declaration] -> PSCI ()
441−handleLet ds = do
444+handleDecls ds = do
442 st <- PSCI $ lift get
445 st <- PSCI $ lift get
443 let st' = updateLets ds st
446 let st' = updateLets ds st
444 let m = createTemporaryModule False st' (P.ObjectLiteral [])
447 let m = createTemporaryModule False st' (P.ObjectLiteral [])
@@ -463,17 +466,37 @@ handleShowLoadedModules = do
464handleShowImportedModules :: PSCI ()
467handleShowImportedModules :: PSCI ()
465handleShowImportedModules = do
468handleShowImportedModules = do
466− PSCiState { psciImportedModuleNames = importedModuleNames } <- PSCI $ lift get
469+ PSCiState { psciImportedModules = importedModules } <- PSCI $ lift get
467− psciIO $ readModules importedModuleNames >>= putStrLn
470+ psciIO $ showModules importedModules >>= putStrLn
468 return ()
471 return ()
469− where readModules = return . unlines . sort . map N.runModuleName
473+ showModules = return . unlines . sort . map showModule
474+ showModule (mn, declType, asQ) =
475+ "import " ++ case asQ of
476+ Just mn' -> "qualified " ++ N.runModuleName mn ++ " as " ++ N.runModuleName mn'
477+ Nothing -> N.runModuleName mn ++ " " ++ showDeclType declType
479+ showDeclType D.Implicit = ""
480+ showDeclType (D.Explicit refs) = refsList refs
481+ showDeclType (D.Hiding refs) = "hiding " ++ refsList refs
482+ refsList refs = "(" ++ commaList (map showRef refs) ++ ")"
484+ showRef :: P.DeclarationRef -> String
485+ showRef (D.TypeRef pn dctors) = show pn ++ "(" ++ maybe ".." (commaList . map N.runProperName) dctors ++ ")"
486+ showRef (D.ValueRef ident) = show ident
487+ showRef (D.TypeClassRef pn) = show pn
488+ showRef (D.TypeInstanceRef ident) = show ident
489+ showRef (D.PositionedDeclarationRef _ _ ref) = showRef ref
491+ commaList :: [String] -> String
492+ commaList = intercalate ", "
472-- Imports a module, preserving the initial state on failure.
495-- Imports a module, preserving the initial state on failure.
474−handleImport :: P.ModuleName -> PSCI ()
497+handleImport :: C.ImportedModule -> PSCI ()
475−handleImport moduleName = do
498+handleImport im = do
476− st <- updateImports moduleName <$> PSCI (lift get)
499+ st <- updateImportedModules im <$> PSCI (lift get)
477 let m = createTemporaryModuleForImports st
500 let m = createTemporaryModuleForImports st
478 e <- psciIO . runMake $ P.make modulesDir (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
501 e <- psciIO . runMake $ P.make modulesDir (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
479 case e of
502 case e of
@@ -575,8 +598,8 @@ getCommand singleLineMode = do
575handleCommand :: C.Command -> PSCI ()
598handleCommand :: C.Command -> PSCI ()
576handleCommand (C.Expression val) = handleDeclaration val
599handleCommand (C.Expression val) = handleDeclaration val
577handleCommand C.Help = PSCI $ outputStrLn helpMessage
600handleCommand C.Help = PSCI $ outputStrLn helpMessage
578−handleCommand (C.Import moduleName) = handleImport moduleName
601+handleCommand (C.Import im) = handleImport im
579−handleCommand (C.Let l) = handleLet l
602+handleCommand (C.Decls l) = handleDecls l
580handleCommand (C.LoadFile filePath) = do
603handleCommand (C.LoadFile filePath) = do
581 absPath <- psciIO $ expandTilde filePath
604 absPath <- psciIO $ expandTilde filePath
582 exists <- psciIO $ doesFileExist absPath
605 exists <- psciIO $ doesFileExist absPath
@@ -592,7 +615,7 @@ handleCommand C.Reset = do
592 files <- psciImportedFilenames <$> PSCI (lift get)
615 files <- psciImportedFilenames <$> PSCI (lift get)
593 PSCI . lift . modify $ \st -> st
616 PSCI . lift . modify $ \st -> st
594 { psciImportedFilenames = files
617 { psciImportedFilenames = files
595− , psciImportedModuleNames = defaultImports
618+ , psciImportedModules = defaultImports
596 , psciLetBindings = []
619 , psciLetBindings = []
598 loadAllImportedModules
621 loadAllImportedModules