packages feed

hdocs 0.4.4.0 → 0.4.4.1

raw patch · 3 files changed

+9/−4 lines, 3 files

Files

hdocs.cabal view
@@ -1,5 +1,5 @@ name:                hdocs
-version:             0.4.4.0
+version:             0.4.4.1
 synopsis:            Haskell docs tool
 description:
   Tool and library to get docs for installed packages and source files.
src/HDocs/Haddock.hs view
@@ -2,7 +2,7 @@ 	-- * Documentation functions
 	readInstalledDocs,
 	readHaddock,
-	readSources, readSources_, readSource, readSourcesGhc,
+	readSources, readSources_, readSource, readSourcesGhc, readSourceGhc,
 
 	-- * Extract docs
 	installedInterfaceDocs, installedInterfacesDocs,
@@ -16,7 +16,8 @@ 	module HDocs.Base,
 
 	Ghc,
-	module Control.Monad.Except
+	module Control.Monad.Except,
+	withGhc
 	) where
 
 import Control.Applicative
@@ -69,6 +70,10 @@ readSourcesGhc opts fs = ExceptT $ liftM (left (show :: SomeException -> String)) $ gtry $ do
 	ifaces <- liftM fst $ processModules silent fs ([Flag_Verbosity "0", Flag_NoWarnings, Flag_UseUnicode] ++ map Flag_OptGhc opts) []
 	return $ map interfaceDocs ifaces
+
+-- | Read docs for haskell module
+readSourceGhc :: [String] -> FilePath -> ExceptT String Ghc (String, ModuleDocMap)
+readSourceGhc opts f = liftM listToMaybe (readSourcesGhc opts [f]) >>= maybe (throwError $ "Failed to load docs for " ++ f) return
 
 -- | Get docs for 'InstalledInterface'
 installedInterfaceDocs :: InstalledInterface -> (String, ModuleDocMap)
tools/hdocs.hs view
@@ -57,7 +57,7 @@ 
 		loadDocs :: String -> ExceptT String IO ModuleDocMap
 		loadDocs m
-			| takeExtension m == ".hs" = liftM snd $ readSource (optionGHC cfg) m
+			| takeExtension m == ".hs" = liftM snd $ ExceptT $ withGhc [] $ runExceptT $ readSourceGhc (optionGHC cfg) m
 			| otherwise = moduleDocs (optionGHC cfg) m
 
 	case cmds of