Ticket #2986: ghci-info-no-instances.patch

File ghci-info-no-instances.patch, 2.5 KB (added by Remi, 6 years ago)

patch to optionally not print instances with :info

  • compiler/ghci/InteractiveUI.hs

    old new  
    211211 "   :edit                       edit last module\n" ++ 
    212212 "   :etags [<file>]             create tags file for Emacs (default: \"TAGS\")\n" ++ 
    213213 "   :help, :?                   display this list of commands\n" ++ 
    214  "   :info [<name> ...]          display information about the given names\n" ++ 
     214 "   :info [-][<name> ...]       display information about the given names\n" ++ 
    215215 "   :kind <type>                show the kind of <type>\n" ++ 
    216216 "   :load [*]<module> ...       load module(s) and their dependents\n" ++ 
    217217 "   :main [<arguments> ...]     run the main function with the given arguments\n" ++ 
     
    876876help _ = io (putStr helpText) 
    877877 
    878878info :: String -> GHCi () 
    879 info "" = ghcError (CmdLineError "syntax: ':i <thing-you-want-info-about>'") 
     879info "" = ghcError (CmdLineError "syntax: ':i [-]<thing-you-want-info-about>'") 
     880info "-"= ghcError (CmdLineError "syntax: ':i [-]<thing-you-want-info-about>'") 
    880881info s  = handleSourceError GHC.printExceptionAndWarnings $ do 
    881              { let names = words s 
    882              ; dflags <- getDynFlags 
     882             { dflags <- getDynFlags 
    883883             ; let pefas = dopt Opt_PrintExplicitForalls dflags 
    884884             ; mapM_ (infoThing pefas) names } 
    885885  where 
     886    (wantInstances, names) = case s of 
     887                                '-' : s'-> (False, words s') 
     888                                _       -> (True, words s) 
    886889    infoThing pefas str = do 
    887890        names     <- GHC.parseName str 
    888891        mb_stuffs <- mapM GHC.getInfo names 
     
    891894        liftIO $ 
    892895          putStrLn (showSDocForUser unqual $ 
    893896                     vcat (intersperse (text "") $ 
    894                            map (pprInfo pefas) filtered)) 
     897                           map (pprInfo pefas wantInstances) filtered)) 
    895898 
    896899  -- Filter out names whose parent is also there Good 
    897900  -- example is '[]', which is both a type and data 
     
    902905  where 
    903906    implicits = mkNameSet [getName t | x <- xs, t <- implicitTyThings (get_thing x)] 
    904907 
    905 pprInfo :: PrintExplicitForalls -> (TyThing, Fixity, [GHC.Instance]) -> SDoc 
    906 pprInfo pefas (thing, fixity, insts) 
     908pprInfo :: PrintExplicitForalls -> Bool -> (TyThing, Fixity, [GHC.Instance]) -> SDoc 
     909pprInfo pefas wantInstances (thing, fixity, insts) 
    907910  =  pprTyThingInContextLoc pefas thing 
    908911  $$ show_fixity fixity 
    909   $$ vcat (map GHC.pprInstance insts) 
     912  $$ if wantInstances then vcat (map GHC.pprInstance insts) else empty 
    910913  where 
    911914    show_fixity fix  
    912915        | fix == GHC.defaultFixity = empty