haddock icon indicating copy to clipboard operation
haddock copied to clipboard

Cross-package hyperlinked sources links are broken

Open bgamari opened this issue 1 year ago • 2 comments

Consider case like the following:

-- in package `foo`
module Lib (hello) where

-- | Hello world
hello = print "hello"


-- in package `bar`
module Wombat (hello) where
import Lib (hello)

Running cabal haddock bar against a project containing both packages foo and bar will produce faulty documentation.

Specifically, the "Source" link in the generated HTML documentation for Wombat.hello points to something like dist-newstyle/build/x86_64-linux/ghc-9.9.20240122/foo-0.1.0.0/doc/html/foo/src.

The reason for this appears to be that Cabal passes the following to haddock:

--read-interface=file:///.../dist-newstyle/build/x86_64-linux/ghc-9.9.20240122/foo-0.1.0.0/doc/html/foo,file:///.../dist-newstyle/build/x86_64-linux/ghc-9.9.20240122/foo-0.1.0.0/doc/html/foo/src,visible,/.../dist-newstyle/build/x86_64-linux/ghc-9.9.20240122/foo-0.1.0.0/doc/html/foo/foo.haddock

The path used to locate the hyperlinked sources for foo is derived from the second component of this 4-tuple using Haddock.Backends.Xhtml.Utils.spliceURL. However, this function expects this string to be a pattern (e.g. containing the %{MODULE} token), not a path. It is unclear how this could have ever worked.

bgamari avatar Feb 04 '24 00:02 bgamari