haskell-docs 4.1.0 → 4.1.1
raw patch · 4 files changed
+46/−22 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Haskell.Docs: searchAndPrintDoc :: Maybe PackageName -> Maybe ModuleName -> Identifier -> Ghc ()
+ Haskell.Docs: searchAndPrintDoc :: Bool -> Maybe PackageName -> Maybe ModuleName -> Identifier -> Ghc ()
- Haskell.Docs.Formatting: printIdentDoc :: Bool -> Bool -> IdentDoc -> Ghc ()
+ Haskell.Docs.Formatting: printIdentDoc :: Bool -> Bool -> Bool -> IdentDoc -> Ghc ()
Files
- haskell-docs.cabal +1/−1
- src/Haskell/Docs.hs +15/−12
- src/Haskell/Docs/Formatting.hs +8/−2
- src/main/Main.hs +22/−7
haskell-docs.cabal view
@@ -1,5 +1,5 @@ name: haskell-docs-version: 4.1.0+version: 4.1.1 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
src/Haskell/Docs.hs view
@@ -1,4 +1,6 @@+{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE TupleSections #-}+ -- | Lookup the documentation of a name in a module (and in a specific -- package in the case of ambiguity). @@ -8,35 +10,36 @@ ,PackageName(..)) where -import Control.Monad-import Data.List import Haskell.Docs.Formatting import Haskell.Docs.Haddock import Haskell.Docs.Types +import Control.Monad+import Data.List+import Data.Ord import GHC hiding (verbosity) import GhcMonad (liftIO)-import System.IO -- -- | Print the documentation of a name in the given module. searchAndPrintDoc- :: Maybe PackageName -- ^ Package.+ :: Bool -- ^ Print modules only.+ -> Maybe PackageName -- ^ Package. -> Maybe ModuleName -- ^ Module name. -> Identifier -- ^ Identifier. -> Ghc ()-searchAndPrintDoc pname mname ident =+searchAndPrintDoc ms pname mname ident = do (result,printPkg,printModule) <- search case result of Left err -> error (show err)- Right docs ->- mapM_ (\(i,doc) -> do when (i > 0)- (liftIO (putStrLn ""))- printIdentDoc printPkg printModule doc)- (zip [0..] (nub docs))+ Right (sortBy (comparing identDocPackageName) -> docs) ->+ mapM_ (\(i,doc') ->+ do when (not ms && i > 0)+ (liftIO (putStrLn ""))+ printIdentDoc ms printPkg printModule doc')+ (zip [0::Int ..] (nub docs)) where search = case (pname,mname) of (Just p,Just m) -> fmap (,False,False) (searchPackageModuleIdent Nothing p m ident) (Nothing,Just m) -> fmap (,True,False) (searchModuleIdent Nothing m ident)- (Nothing,Nothing) -> fmap (,True,True) (searchIdent Nothing ident)- _ -> error "arguments: <ident> | <module-name> <ident> [<package-name>]"+ _ -> fmap (,True,True) (searchIdent Nothing ident)
src/Haskell/Docs/Formatting.hs view
@@ -18,11 +18,17 @@ -- * Formatting -- | Print an identifier' documentation.-printIdentDoc :: Bool -- ^ Print package?+printIdentDoc :: Bool -- ^ Print modules only?+ -> Bool -- ^ Print package? -> Bool -- ^ Print module? -> IdentDoc -> Ghc ()-printIdentDoc printPkg printModule idoc =+printIdentDoc True _ _ idoc =+ do d <- getSessionDynFlags+ maybe (return ())+ (\i -> liftIO (putStrLn (showppr d (moduleName (nameModule (getName i))))))+ (identDocIdent idoc)+printIdentDoc _ printPkg printModule idoc = do d <- getSessionDynFlags when printPkg (liftIO (putStrLn ("Package: " ++ showPackageName (identDocPackageName idoc))))
src/main/Main.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE ViewPatterns #-} -- | Main command-line interface. module Main where@@ -19,29 +20,43 @@ -- | Do the printing. app :: [String] -> IO ()-app args =+app (extract -> (gs,ms,as)) = withInitializedPackages- []- (case args of+ gs+ (case as of [name] ->- searchAndPrintDoc Nothing Nothing (Identifier name)+ searchAndPrintDoc ms+ Nothing+ Nothing+ (Identifier name) [mname,name,pname] ->- searchAndPrintDoc (Just (PackageName pname))+ searchAndPrintDoc ms+ (Just (PackageName pname)) (Just (makeModuleName mname)) (Identifier name) [mname,name] ->- searchAndPrintDoc Nothing+ searchAndPrintDoc ms+ Nothing (Just (makeModuleName mname)) (Identifier name) _ -> error "<module-name> <ident> [<package-name>] | <ident>") +-- | Extract arguments.+extract :: [String] -> ([String],Bool,[String])+extract = go ([],False,[])+ where go (gs,ms,as) ("-g":arg:ys) = go (arg:gs,ms,as) ys+ go (gs,ms,as) ("--modules":ys) = go (gs,True,as) ys+ go (gs,ms,as) (y:ys) = go (gs,ms,y:as) ys+ go (gs,ms,as) [] = (gs,ms,as)+ -- | Print an exception for humans. printEx :: DocsException -> String printEx e = case e of NoFindModule -> "Couldn't find any packages with that module." NoModulePackageCombo -> "Couldn't match a module with that package."- NoInterfaceFiles -> "No interface files to search through! Maybe you need to generate documentation for the package?"+ NoInterfaceFiles -> "No interface files to search through! \+ \Maybe you need to generate documentation for the package?" NoParseInterfaceFiles reasons -> "Couldn't parse interface files: " ++ unlines (map printEx reasons) NoFindNameInExports -> "Couldn't find that name in an export list."