Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.stack-work/
*.docset/
.DS_Store
stack.yaml.lock
51 changes: 50 additions & 1 deletion Documentation/Haddocset.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import System.Process

import Network.HTTP.Types.URI (urlEncode)

import qualified Data.ByteString as BS
import Data.Char
import Data.List
import Data.Maybe
Expand All @@ -48,10 +49,18 @@ import qualified Data.Text.Encoding as T
import Text.HTML.TagSoup as Ts
import Text.HTML.TagSoup.Match as Ts

#if __GLASGOW_HASKELL__ <= 800
import Distribution.Compat.ReadP
#endif
import Distribution.InstalledPackageInfo
import Distribution.Package hiding (Module)
import Distribution.Pretty (prettyShow)

#if __GLASGOW_HASKELL__ <= 800
import Distribution.Text (display, parse)
#elif __GLASGOW_HASKELL__ >= 800
import Distribution.Text (display, simpleParse)
#endif
import Documentation.Haddock
import qualified Module as Ghc
import qualified Name as Ghc
Expand Down Expand Up @@ -116,24 +125,52 @@ readDocInfoFile pifile = doesDirectoryExist pifile >>= \isDir ->
if isDir
then filter ((== ".haddock") . takeExtension) <$> listDirectory pifile >>= \hdc -> case hdc of
[] -> return Nothing
#if __GLASGOW_HASKELL__ >= 810
hs@(h:_) -> readInterfaceFile freshNameCache h False >>= \ei -> case ei of
#else
hs@(h:_) -> readInterfaceFile freshNameCache h >>= \ei -> case ei of
#endif
Left _ -> return Nothing
Right (InterfaceFile _ (intf:_)) -> do
#if __GLASGOW_HASKELL__ >= 800
#if __GLASGOW_HASKELL__ >= 810
let rPkg = simpleParse . Ghc.unitIdString . Ghc.moduleUnitId $ instMod intf :: Maybe PackageId
#elif __GLASGOW_HASKELL__ >= 800
let rPkg = readP_to_S parse . Ghc.unitIdString . Ghc.moduleUnitId $ instMod intf :: [(PackageId, String)]
#elif __GLASGOW_HASKELL__ >= 710
let rPkg = readP_to_S parse . Ghc.packageKeyString . Ghc.modulePackageKey $ instMod intf :: [(PackageId, String)]
#else
let rPkg = readP_to_S parse . Ghc.packageIdString . Ghc.modulePackageId $ instMod intf :: [(PackageId, String)]
#endif
case rPkg of
#if __GLASGOW_HASKELL__ >= 810
Nothing -> return Nothing
Just pkg ->
return . Just $ DocInfo pkg hs [collapse pifile] True
#else
[] -> return Nothing
pkg -> do
return . Just $ DocInfo (fst $ last pkg) hs [collapse pifile] True
Right _ -> return Nothing
#endif
else do
#if __GLASGOW_HASKELL__ >= 810
result <- parseInstalledPackageInfo <$> BS.readFile pifile
#elif __GLASGOW_HASKELL__ <= 800
result <- parseInstalledPackageInfo <$> readFile pifile
#endif
return $ case result of
#if __GLASGOW_HASKELL__ >= 810
Left _ -> Nothing
Right (_, a)
| null (haddockHTMLs a) -> Nothing
| null (haddockInterfaces a) -> Nothing
| otherwise -> Just $
DocInfo
(sourcePackageId a)
(map expandPkgRoot (haddockInterfaces a))
(map expandPkgRoot (haddockHTMLs a))
(exposed a)
#elif __GLASGOW_HASKELL__ <= 800
ParseFailed _ -> Nothing
ParseOk [] a
| null (haddockHTMLs a) -> Nothing
Expand All @@ -146,6 +183,8 @@ readDocInfoFile pifile = doesDirectoryExist pifile >>= \isDir ->
(exposed a)

ParseOk _ _ -> Nothing

#endif
where
-- drop the package.conf directory: pkgroot/package.conf.d/foo.conf -> pkgroot
pkgroot = takeDirectory . takeDirectory $ pifile
Expand Down Expand Up @@ -185,8 +224,14 @@ copyHtml doc dst = do
]) (anchorName =<< lookup "name" as) $
[tag]
| otherwise = [tag]
addAnchor tag@(Ts.TagOpen "html" _) =
[tag, Ts.TagComment (" Online page at " <> (packageIdToUrl . docPackage $ doc) <> " ")]
addAnchor tag = [tag]

packageIdToUrl :: PackageId -> T.Text
packageIdToUrl (PackageIdentifier n v) = T.pack $
"https://hackage.haskell.org/package/" ++ unPackageName n ++ "-" ++ prettyShow v ++ "/docs/"

unescape [] = Just []
unescape ('-':n) = case reads n of
[(c, '-':o)] -> (toEnum c :) <$> unescape o
Expand Down Expand Up @@ -267,7 +312,11 @@ moduleProvider iFile =
mapM_ sub $ diInterfaces iFile
where
sub file = do
#if __GLASGOW_HASKELL__ >= 810
rd <- liftIO $ readInterfaceFile freshNameCache file False
#else
rd <- liftIO $ readInterfaceFile freshNameCache file
#endif
case rd of
Left _ -> return ()
Right (ifInstalledIfaces -> iIntrf) -> do
Expand Down
4 changes: 3 additions & 1 deletion Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ main = do
createOpts = Create
<$> ( Plist <$> (textOption (long "CFBundleIdentifier") <|> pure "haskell")
<*> (textOption (long "CFBundleName") <|> pure "Haskell")
<*> (textOption (long "DocSetPlatformFamily") <|> pure "haskell"))
-- Important not to chose haskell for the family for "open online documentation" to work properly
-- Otherwise, Dash tries to own the redirect and it fails
<*> (textOption (long "DocSetPlatformFamily") <|> pure "hackage"))
<*> many (argument str (metavar "CONFS" <> help "path to installed package configuration."))

addOpts = Add
Expand Down
9 changes: 5 additions & 4 deletions haddocset.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ executable haddocset
Documentation.Haddocset.Index
Documentation.Haddocset.Plist
ghc-options: -Wall -O2
build-depends: base >=4.6 && <4.12
, ghc >=7.8 && <8.5
, optparse-applicative >=0.11 && <0.15
build-depends: base >=4.14.0 && <4.15
, bytestring
, ghc >=7.8 && <8.11
, optparse-applicative >=0.11 && <0.16.2
, conduit >=1.0 && <1.4
, conduit-extra >=1.1 && <1.4
, tagsoup >=0.13 && <1.4
, Cabal >=1.16 && <2.3
, Cabal >=1.16 && <3.3
, text >=1.0 && <1.3
, sqlite-simple >=0.4.5 && <0.5
, process >=1.1 && <1.7
Expand Down
5 changes: 2 additions & 3 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
resolver: lts-12.0
resolver: lts-18.28
packages:
- '.'


extra-deps:
- haddock-api-2.20.0
- haddock-library-1.6.0
- haddock-api-2.24.2



Expand Down