@@ -72,12 +72,16 @@ data PSCiOptions = PSCiOptions
7272--
7373data PSCiState = PSCiState
7474 { psciImportedFilenames :: [FilePath]
75− , psciImportedModuleNames :: [P.ModuleName]
75+ , psciImportedModules :: [C.ImportedModule]
7676 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
7777 , psciLetBindings :: [P.Declaration]
7878 , psciNodeFlags :: [String]
7979 }
8080
81+psciImportedModuleNames :: PSCiState -> [P.ModuleName]
82+psciImportedModuleNames (PSCiState{psciImportedModules = is}) =
83+ map (\(mn, _, _) -> mn) is
84+
8185-- State helpers
8286
8387-- |
@@ -89,8 +93,8 @@ updateImportedFiles filename st = st { psciImportedFilenames = filename : psciIm
8993-- |
9094-- Updates the state to have more imported modules.
9195--
92−updateImports :: P.ModuleName -> PSCiState -> PSCiState
93−updateImports name st = st { psciImportedModuleNames = name : psciImportedModuleNames st }
96+updateImportedModules :: C.ImportedModule -> PSCiState -> PSCiState
97+updateImportedModules im st = st { psciImportedModules = im : psciImportedModules st }
9498
9599-- |
96100-- Updates the state to have more loaded files.
@@ -108,8 +112,8 @@ updateLets ds st = st { psciLetBindings = psciLetBindings st ++ ds }
108112-- |
109113-- Load the necessary modules.
110114--
111−defaultImports :: [P.ModuleName]
112−defaultImports = [P.ModuleName [P.ProperName "Prelude"]]
115+defaultImports :: [C.ImportedModule]
116+defaultImports = [(P.ModuleName [P.ProperName "Prelude"], D.Unqualified, Nothing)]
113117
114118-- |
115119-- Locates the node executable.
@@ -181,7 +185,7 @@ helpMessage = "The following commands are available:\n\n " ++
181185 , replicate (11 - length arg) ' '
182186 , desc
183187 ]
184− where cmd = ":" ++ head (D.commands dir)
188+ where cmd = ":" ++ head (D.commands dir)
185189
186190-- |
187191-- The welcome prologue.
@@ -370,10 +374,9 @@ mkdirp = createDirectoryIfMissing True . takeDirectory
370374-- Makes a volatile module to execute the current expression.
371375--
372376createTemporaryModule :: Bool -> PSCiState -> P.Expr -> P.Module
373−createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetBindings = lets} val =
377+createTemporaryModule exec PSCiState{psciImportedModules = imports, psciLetBindings = lets} val =
374378 let
375379 moduleName = P.ModuleName [P.ProperName "$PSCI"]
376− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
377380 traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
378381 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
379382 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
@@ -388,10 +391,9 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
388391-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
389392--
390393createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
391−createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
394+createTemporaryModuleForKind PSCiState{psciImportedModules = imports} typ =
392395 let
393396 moduleName = P.ModuleName [P.ProperName "$PSCI"]
394− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
395397 itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
396398 in
397399 P.Module [] moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
@@ -400,13 +402,15 @@ createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
400402-- Makes a volatile module to execute the current imports.
401403--
402404createTemporaryModuleForImports :: PSCiState -> P.Module
403−createTemporaryModuleForImports PSCiState{psciImportedModuleNames = imports} =
405+createTemporaryModuleForImports PSCiState{psciImportedModules = imports} =
404406 let
405407 moduleName = P.ModuleName [P.ProperName "$PSCI"]
406− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
407408 in
408409 P.Module [] moduleName (importDecl `map` imports) Nothing
409410
411+importDecl :: C.ImportedModule -> P.Declaration
412+importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ
413+
410414modulesDir :: FilePath
411415modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
412416
@@ -463,17 +467,36 @@ handleShowLoadedModules = do
463467--
464468handleShowImportedModules :: PSCI ()
465469handleShowImportedModules = do
466− PSCiState { psciImportedModuleNames = importedModuleNames } <- PSCI $ lift get
467− psciIO $ readModules importedModuleNames >>= putStrLn
470+ PSCiState { psciImportedModules = importedModules } <- PSCI $ lift get
471+ psciIO $ showModules importedModules >>= putStrLn
468472 return ()
469− where readModules = return . unlines . sort . map N.runModuleName
473+ where
474+ showModules = return . unlines . sort . map showModule
475+ showModule (mn, declType, asQ) =
476+ case asQ of
477+ Just mn' -> "qualified " ++ N.runModuleName mn ++ " as " ++ N.runModuleName mn'
478+ Nothing -> N.runModuleName mn ++ " " ++ showDeclType declType
479+ showDeclType D.Unqualified = ""
480+ showDeclType (D.Qualifying refs) = refsList refs
481+ showDeclType (D.Hiding refs) = "hiding " ++ refsList refs
482+ refsList refs = "(" ++ commaList (map showRef refs) ++ ")"
483+
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
490+
491+ commaList :: [String] -> String
492+ commaList = intercalate ", "
470493
471494-- |
472495-- Imports a module, preserving the initial state on failure.
473496--
474−handleImport :: P.ModuleName -> PSCI ()
475−handleImport moduleName = do
476− st <- updateImports moduleName <$> PSCI (lift get)
497+handleImport :: C.ImportedModule -> PSCI ()
498+handleImport im = do
499+ st <- updateImportedModules im <$> PSCI (lift get)
477500 let m = createTemporaryModuleForImports st
478501 e <- psciIO . runMake $ P.make modulesDir (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
479502 case e of
@@ -575,7 +598,7 @@ getCommand singleLineMode = do
575598handleCommand :: C.Command -> PSCI ()
576599handleCommand (C.Expression val) = handleDeclaration val
577600handleCommand C.Help = PSCI $ outputStrLn helpMessage
578−handleCommand (C.Import moduleName) = handleImport moduleName
601+handleCommand (C.Import im) = handleImport im
579602handleCommand (C.Let l) = handleLet l
580603handleCommand (C.LoadFile filePath) = do
581604 absPath <- psciIO $ expandTilde filePath
@@ -592,7 +615,7 @@ handleCommand C.Reset = do
592615 files <- psciImportedFilenames <$> PSCI (lift get)
593616 PSCI . lift . modify $ \st -> st
594617 { psciImportedFilenames = files
595− , psciImportedModuleNames = defaultImports
618+ , psciImportedModules = defaultImports
596619 , psciLetBindings = []
597620 }
598621 loadAllImportedModules