Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Fix documentation (or source) link when html file is less specific th…
Browse files Browse the repository at this point in the history
…an module (#766)

* show doc/source link when html file name is less specific than module name

* try most qualified file names first, both dash and dot delimited

* small cleanup

* make hlint happy

* hlint again
  • Loading branch information
DunetsNM authored Sep 20, 2020
1 parent 26cb575 commit 55e3810
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Development/IDE/Spans/Documentation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,20 @@ lookupSrcHtmlForModule =

lookupHtmlForModule :: (FilePath -> FilePath -> FilePath) -> DynFlags -> Module -> IO (Maybe FilePath)
lookupHtmlForModule mkDocPath df m = do
let mfs = go <$> (listToMaybe =<< lookupHtmls df ui)
-- try all directories
let mfs = fmap (concatMap go) (lookupHtmls df ui)
htmls <- filterM doesFileExist (concat . maybeToList $ mfs)
return $ listToMaybe htmls
where
-- The file might use "." or "-" as separator
go pkgDocDir = [mkDocPath pkgDocDir mn | mn <- [mndot,mndash]]
go pkgDocDir = map (mkDocPath pkgDocDir) mns
ui = moduleUnitId m
mndash = map (\x -> if x == '.' then '-' else x) mndot
mndot = moduleNameString $ moduleName m
-- try to locate html file from most to least specific name e.g.
-- first Language.Haskell.LSP.Types.Uri.html and Language-Haskell-LSP-Types-Uri.html
-- then Language.Haskell.LSP.Types.html and Language-Haskell-LSP-Types.html etc.
mns = do
chunks <- (reverse . drop1 . inits . splitOn ".") $ (moduleNameString . moduleName) m
-- The file might use "." or "-" as separator
map (`intercalate` chunks) [".", "-"]

lookupHtmls :: DynFlags -> UnitId -> Maybe [FilePath]
lookupHtmls df ui = haddockHTMLs <$> lookupPackage df ui

0 comments on commit 55e3810

Please sign in to comment.