packages feed

haskell-docs 3.0.2 → 3.0.3

raw patch · 3 files changed

+127/−11 lines, 3 filesdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base

API changes (from Hackage documentation)

- Documentation.Haddock.Docs: descendSearch :: DynFlags -> String -> Name -> PackageConfig -> Ghc Bool
- Documentation.Haddock.Docs: doc :: Doc String -> String
- Documentation.Haddock.Docs: formatDoc :: Doc String -> String
- Documentation.Haddock.Docs: formatExample :: Example -> String
- Documentation.Haddock.Docs: getHaddockInterfacesByPackage :: PackageConfig -> IO [Either String InterfaceFile]
- Documentation.Haddock.Docs: getPackagesByModule :: DynFlags -> ModuleName -> IO (Either [Module] [PackageConfig])
- Documentation.Haddock.Docs: indentAfter :: Int -> String -> String
- Documentation.Haddock.Docs: interfaceArgMap :: InstalledInterface -> Map String (Map Int (Doc Name))
- Documentation.Haddock.Docs: interfaceNameMap :: InstalledInterface -> Map String (Doc String)
- Documentation.Haddock.Docs: normalize :: [Char] -> [Char]
- Documentation.Haddock.Docs: printArgs :: InstalledInterface -> String -> Ghc ()
- Documentation.Haddock.Docs: printDocumentationInitialized :: String -> ModuleName -> Maybe String -> [String] -> IO Bool
- Documentation.Haddock.Docs: printType :: GhcMonad m => DynFlags -> ModuleName -> t -> String -> m ()
- Documentation.Haddock.Docs: printWithInterface :: DynFlags -> Bool -> PackageConfig -> String -> ModuleName -> InstalledInterface -> Ghc Bool
- Documentation.Haddock.Docs: printWithPackage :: DynFlags -> Bool -> String -> ModuleName -> PackageConfig -> Ghc Bool
- Documentation.Haddock.Docs: run :: Ghc a -> IO a
- Documentation.Haddock.Docs: sdoc :: DynFlags -> SDoc -> String
- Documentation.Haddock.Docs: showPackageName :: PackageIdentifier -> String
- Documentation.Haddock.Docs: showSDocForUser :: DynFlags -> PrintUnqualified -> SDoc -> String
- Documentation.Haddock.Docs: showppr :: Outputable a => DynFlags -> a -> String
- Documentation.Haddock.Docs: trim :: [Char] -> [Char]
+ Documentation.Haddock.Docs: getType :: DynFlags -> ModuleName -> String -> Ghc String
+ Documentation.Haddock.Docs: instance Exception DocsException
+ Documentation.Haddock.Docs: instance Show DocsException
+ Documentation.Haddock.Docs: instance Typeable DocsException
+ Documentation.Haddock.Docs: mkModuleName :: String -> ModuleName

Files

haskell-docs.cabal view
@@ -1,5 +1,5 @@ name:                haskell-docs-version:             3.0.2+version:             3.0.3 synopsis:            A program to find and display the docs of a name from a                      given module. description:         Given a module name and a name, it will find and display@@ -8,6 +8,7 @@                      /EXAMPLE USAGE/                      .                      > $ haskell-docs Data.List.Split split+                     > split :: forall a. Splitter a -> [a] -> [[a]]                      > Split a list according to the given splitting strategy. This is                      >  how to "run" a Splitter that has been built using the other                      >  combinators.@@ -81,6 +82,13 @@                        ghc > 7.2 && < 7.9,                        haskell-docs,                        optparse-applicative++test-suite test+    type: exitcode-stdio-1.0+    main-is: Main.hs+    hs-source-dirs: src/test+    build-depends: base,+                   haskell-docs  source-repository head   type:        git
src/Documentation/Haddock/Docs.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE DeriveDataTypeable #-} {-# OPTIONS -Wall -fno-warn-missing-signatures #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE CPP #-}@@ -6,9 +7,15 @@ -- | Lookup the documentation of a name in a module (and in a specific -- package in the case of ambiguity). -module Documentation.Haddock.Docs where+module Documentation.Haddock.Docs+  (withInitializedPackages+  ,printDocumentation+  ,mkModuleName+  ,getType)+  where  import           Control.Arrow+import           Control.Exception import           Control.Monad import           Control.Monad.Loops import           Data.Char@@ -16,6 +23,7 @@ import           Data.List import           Data.Map (Map) import qualified Data.Map as M+import           Data.Typeable import           Documentation.Haddock import           GHC hiding (verbosity) import           GHC.Paths (libdir)@@ -33,6 +41,11 @@ import           DynFlags (defaultFlushOut, defaultFatalMessager) #endif +data DocsException+  = Couldn'tFindModule+  deriving (Typeable,Show)+instance Exception DocsException+ -- | Print documentation with an initialized package set. printDocumentationInitialized :: String -> ModuleName -> Maybe String -> [String] -> IO Bool printDocumentationInitialized x y z ghcopts =@@ -83,7 +96,7 @@ printWithInterface df printPackage package name mname interface = do   case find ((==name).getOccString) (instExports interface) of     Nothing -> bail-    Just qname ->+    Just{} ->       case M.lookup name docMap of         Nothing -> do           case lookup name (map (getOccString &&& id) (instExports interface)) of@@ -94,7 +107,7 @@         Just d ->           do liftIO (when printPackage $                        putStrLn $ "Package: " ++ showPackageName (sourcePackageId package))-             printType df mname qname name+             printType df mname name              liftIO (putStrLn (formatDoc d))              printArgs interface name              return True@@ -105,19 +118,39 @@                              moduleNameString (moduleName (instMod interface)))           return False -printType d mname _qname name =-  do _graph <- depanal [] False-     _loaded <- load LoadAllTargets-#if __GLASGOW_HASKELL__ == 702-#else-     setContext [IIDecl (simpleImportDecl mname)]-#endif+-- | Print the type of the given identifier from the given module.+printType :: DynFlags -> ModuleName -> String -> Ghc ()+printType d mname name =+  do _ <- depanal [] False+     _ <- load LoadAllTargets+     portableSetContext mname      names <- getNamesInScope      mty <- lookupName (head (filter ((==name).getOccString) names))      case mty of        Just (AnId i) -> liftIO (do putStr (showppr d i ++ " :: ")                                    putStrLn (showppr d (idType i)))        _ -> liftIO (putStrLn "Unable to find type for identifier.")+++-- | Get the type of the given identifier from the given module.+getType :: DynFlags -> ModuleName -> String -> Ghc String+getType d mname name =+  do _ <- depanal [] False+     _ <- load LoadAllTargets+     portableSetContext mname+     names <- getNamesInScope+     mty <- lookupName (head (filter ((==name).getOccString) names))+     case mty of+       Just (AnId i) -> return (showppr d (idType i))+       _ -> error "Unable to find type for identifier."++-- | Set the import context.+portableSetContext :: ModuleName -> Ghc ()+#if __GLASGOW_HASKELL__ == 702+portableSetContext mname = setContext [] [simpleImportDecl mname]+#else+portableSetContext mname = setContext [IIDecl (simpleImportDecl mname)]+#endif  -- | Print the documentation of the arguments. printArgs :: InstalledInterface -> String -> Ghc ()
+ src/test/Main.hs view
@@ -0,0 +1,75 @@+-- | Main test suite.++module Main where++import qualified Control.Exception as E+import           Control.Monad+import           Documentation.Haddock.Docs+import           System.Exit+import           System.IO++-- | Main entry point.+main :: IO ()+main =+  do hSetBuffering stdout NoBuffering+     spec++-- | Test suite.+spec :: IO ()+spec =+  do describe "initialization" initialization+     describe "docs" docs+     describe "types" types++-- | Test GHC initialization.+initialization :: IO ()+initialization =+  do it "withInitializedPackages"+        (withInitializedPackages [] (\dflags -> return ()))++-- | Test GHC docs.+docs :: IO ()+docs =+  do it "printDocumentation"+        (withInitializedPackages+           []+           (\d ->+              void (printDocumentation+                     d+                     "hSetBuffering"+                     (mkModuleName "System.IO")+                     Nothing+                     Nothing)))++-- | Test GHC types.+types :: IO ()+types =+  do it "getType"+        (withInitializedPackages+           []+           (\d ->+              do void (printDocumentation+                        d+                        "hSetBuffering"+                        (mkModuleName "System.IO")+                        Nothing+                        Nothing)+                 void (getType d+                               (mkModuleName "System.IO")+                               "hSetBuffering")))++-- | Describe a test spec.+describe :: String -> IO () -> IO ()+describe name m =+  do putStrLn ("Spec: " ++ name)+     m++-- | A test.+it :: String -> IO () -> IO ()+it name m =+  do putStr ("Testing: " ++ name)+     E.catch m+             (\E.SomeException{} ->+                do putStrLn ("\nFailed: " ++ name)+                   exitFailure)+     putStrLn "OK."