Commit 2ec32a8e authored by Iavor S. Diatchki's avatar Iavor S. Diatchki
Browse files

Add ":info!" to GHCi. This shows all instances without filtering first.

The default behavior of :info is to show only those instances of
for a type, where all relevant type constructor names are in scope.
This keeps down the number of instances shown to the user.

In some cases, it is nice to be able to see all instances for a type.
This patch implements this with the :info! command.
parent 77ef6ca0
......@@ -890,8 +890,8 @@ moduleIsInterpreted modl = withSession $ \h ->
-- are in scope (qualified or otherwise). Otherwise we list a whole lot too many!
-- The exact choice of which ones to show, and which to hide, is a judgement call.
-- (see Trac #1581)
getInfo :: GhcMonad m => Name -> m (Maybe (TyThing,Fixity,[ClsInst]))
getInfo name
getInfo :: GhcMonad m => Bool -> Name -> m (Maybe (TyThing,Fixity,[ClsInst]))
getInfo allInfo name
= withSession $ \hsc_env ->
do mb_stuff <- liftIO $ hscTcRnGetInfo hsc_env name
case mb_stuff of
......@@ -900,8 +900,10 @@ getInfo name
let rdr_env = ic_rn_gbl_env (hsc_IC hsc_env)
return (Just (thing, fixity, filter (plausible rdr_env) ispecs))
where
plausible rdr_env ispec -- Dfun involving only names that are in ic_rn_glb_env
= all ok $ nameSetToList $ orphNamesOfType $ idType $ instanceDFunId ispec
plausible rdr_env ispec
-- Dfun involving only names that are in ic_rn_glb_env
= allInfo
|| all ok (nameSetToList $ orphNamesOfType $ idType $ instanceDFunId ispec)
where -- A name is ok if it's in the rdr_env,
-- whether qualified or not
ok n | n == name = True -- The one we looked for in the first place!
......
......@@ -155,7 +155,8 @@ ghciCommands = [
("forward", keepGoing forwardCmd, noCompletion),
("help", keepGoing help, noCompletion),
("history", keepGoing historyCmd, noCompletion),
("info", keepGoing' info, completeIdentifier),
("info", keepGoing' (info False), completeIdentifier),
("info!", keepGoing' (info True), completeIdentifier),
("issafe", keepGoing' isSafeCmd, completeModule),
("kind", keepGoing' (kindOfType False), completeIdentifier),
("kind!", keepGoing' (kindOfType True), completeIdentifier),
......@@ -237,7 +238,8 @@ defFullHelpText =
" :edit edit last module\n" ++
" :etags [<file>] create tags file for Emacs (default: \"TAGS\")\n" ++
" :help, :? display this list of commands\n" ++
" :info [<name> ...] display information about the given names\n" ++
" :info[!] [<name> ...] display information about the given names\n" ++
" (!: do not filter instances)\n" ++
" :issafe [<mod>] display safe haskell information of module <mod>\n" ++
" :kind <type> show the kind of <type>\n" ++
" :load [*]<module> ... load module(s) and their dependents\n" ++
......@@ -1006,20 +1008,20 @@ help _ = do
-----------------------------------------------------------------------------
-- :info
info :: String -> InputT GHCi ()
info "" = throwGhcException (CmdLineError "syntax: ':i <thing-you-want-info-about>'")
info s = handleSourceError GHC.printException $ do
info :: Bool -> String -> InputT GHCi ()
info _ "" = throwGhcException (CmdLineError "syntax: ':i <thing-you-want-info-about>'")
info allInfo s = handleSourceError GHC.printException $ do
unqual <- GHC.getPrintUnqual
dflags <- getDynFlags
sdocs <- mapM infoThing (words s)
sdocs <- mapM (infoThing allInfo) (words s)
mapM_ (liftIO . putStrLn . showSDocForUser dflags unqual) sdocs
infoThing :: GHC.GhcMonad m => String -> m SDoc
infoThing str = do
infoThing :: GHC.GhcMonad m => Bool -> String -> m SDoc
infoThing allInfo str = do
dflags <- getDynFlags
let pefas = gopt Opt_PrintExplicitForalls dflags
names <- GHC.parseName str
mb_stuffs <- mapM GHC.getInfo names
mb_stuffs <- mapM (GHC.getInfo allInfo) names
let filtered = filterOutChildren (\(t,_f,_i) -> t) (catMaybes mb_stuffs)
return $ vcat (intersperse (text "") $ map (pprInfo pefas) filtered)
......@@ -2185,7 +2187,7 @@ showBindings = do
makeDoc tt = do
dflags <- getDynFlags
let pefas = gopt Opt_PrintExplicitForalls dflags
mb_stuff <- GHC.getInfo (getName tt)
mb_stuff <- GHC.getInfo False (getName tt)
return $ maybe (text "") (pprTT pefas) mb_stuff
pprTT :: PrintExplicitForalls -> (TyThing, Fixity, [GHC.ClsInst]) -> SDoc
pprTT pefas (thing, fixity, _insts) =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment