Skip to content

Commit 55e3810

Browse files
authored
Fix documentation (or source) link when html file is less specific than 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
1 parent 26cb575 commit 55e3810

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Development/IDE/Spans/Documentation.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,20 @@ lookupSrcHtmlForModule =
170170

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

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

0 commit comments

Comments
 (0)