@@ -340,48 +340,6 @@ handleImport moduleName = do
340 PSCI $ lift $ put s
340 PSCI $ lift $ put s
341 return ()
341 return ()
344−-- Browse and display the module's function signatures
346−handleBrowse :: P.ModuleName -> PSCI ()
347−handleBrowse moduleName = do
348− PSCiState { psciLoadedModules = loadedModules
349− , psciImportedFilenames = loadedPaths} <- PSCI $ lift get
350− psciIO $ (readModuleTypes loadedModules . findKeyModulePath loadedPaths . N.runModuleName) moduleName >>= putStrLn
353− moduleToPath :: String -> FilePath
354− moduleToPath = (pathSeparator:) . (++ ".purs") . map (\x -> if x == '.' then pathSeparator else x) . N.runModuleName . N.moduleNameFromString
356− -- HACK - permit to `:b` prelude modules - I do not know better
357− preludeModules = ["Prelude", "Data.Function", "Data.Eq", "Prelude.Unsafe",
358− "Control.Monad.Eff", "Control.Monad.Eff.Unsafe",
359− "Debug.Trace", "Control.Monad.ST"]
361− -- find the fully qualified module path (key to full module)
362− findKeyModulePath :: [FilePath] -> String -> Either String FilePath
363− findKeyModulePath _ [] = Left "Module must be specified."
364− findKeyModulePath filePaths modName =
365− let partialModulePath = if modName `elem` preludeModules then "/prelude/prelude.purs" else moduleToPath modName in
366− case filter (isInfixOf partialModulePath) filePaths of
367− [] -> Left $ "Module ('" ++ modName ++ "','" ++ partialModulePath ++ "') was not found."
370− getSignature (P.PositionedDeclaration _ d) = getSignature d
371− getSignature (P.TypeDeclaration ident mtype) = Just $ show ident ++ " :: " ++ prettyPrintType mtype
372− getSignature _ = Nothing
374− signatures :: P.Module -> [String]
375− signatures (P.Module _ ds _) = mapMaybe getSignature ds
377− readModuleTypes :: [(FilePath, D.Module)] -> Either String FilePath -> IO String
378− readModuleTypes [] _ = return "No module(s) loaded."
379− readModuleTypes _ (Left err) = return err
380− readModuleTypes loadedModules (Right modName) =
381− return $ case lookup modName loadedModules of
382− Just mName -> (unlines . sort . signatures) mName
383− _ -> "Module '" ++ modName ++ "' not found!"
386-- Takes a value and prints its type
344-- Takes a value and prints its type
@@ -397,6 +355,25 @@ handleTypeOf value = do
397 Just (ty, _, _) -> PSCI . outputStrLn . P.prettyPrintType $ ty
355 Just (ty, _, _) -> PSCI . outputStrLn . P.prettyPrintType $ ty
398 Nothing -> PSCI $ outputStrLn "Could not find type"
356 Nothing -> PSCI $ outputStrLn "Could not find type"
358+handleBrowse :: P.ModuleName -> PSCI ()
359+handleBrowse moduleName = do
360+ st <- PSCI $ lift get
361+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st) []
363+ Left err -> PSCI $ outputStrLn err
365+ let namesEnv = P.names env'
366+ moduleNamesIdent = (filter ((== moduleName) . fst) . M.keys) namesEnv
371+ . map (showType . findType namesEnv)) moduleNamesIdent
372+ where findType :: M.Map (P.ModuleName, P.Ident) (P.Type, P.NameKind, P.NameVisibility) -> (P.ModuleName, P.Ident) -> (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility))
373+ findType envNames m@(_, mIdent) = (mIdent, M.lookup m envNames)
374+ showType :: (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility)) -> String
375+ showType (mIdent, Just (mType, _, _)) = show mIdent ++ " :: " ++ P.prettyPrintType mType
401-- Takes a value and prints its kind
378-- Takes a value and prints its kind