问题描述:

I have installed a bunch of packages to the snapshot database. I would now like a local copy of their documentation (even better if it's with hyperlinked source). Is there a way I can tell stack to run haddock on all of them?

EDIT (copied from my answer):

It seems that the obvious stack haddock package will install haddock for the package, so

$ cd ~/.stack/snapshots/x86_64-linux/lts-3.0/7.10.2/doc

$ stack haddock *

seems to do what I want, with two downsides:

  1. I'll still need to remember to pass the --haddock flag to every build (there isn't a ~/.stack/config file, is there?)
  2. It seems to rebuild them; is there a way to avoid that?

网友答案:

It seems that the obvious stack haddock package will install haddock for the package, so

$ cd ~/.stack/snapshots/x86_64-linux/lts-3.0/7.10.2/doc
$ stack haddock *

seems to do what I want, with two downsides:

  1. I'll still need to remember to pass the --haddock flag to every build (there isn't a ~/.stack/config file, is there?)
  2. It seems to rebuild them; is there a way to avoid that?
网友答案:

Step 1. Download and build the newest haddock. The build instructions are in README.md.

git clone https://github.com/haskell/haddock.git
cd haddock

cabal sandbox init
cabal sandbox add-source haddock-library
cabal sandbox add-source haddock-api
cabal install --dependencies-only
cabal build

Then install the new haddock as haddock.real

cp dist/build/haddock/haddock /some/bin/dir/haddock.real

Step 2. Create a wrapper script named haddock:

#!/bin/sh

/some/bin/dir/haddock.real --hyperlinked-source "[email protected]"

Don't forget to make it executable and put it in your path.

Step 3. Download and build standalone-haddock:

mkdir build-standalone-haddock
git clone https://github.com/feuerbach/standalone-haddock.git
cd standalone-haddock
cabal build
cp dist/build/standalone-haddock/standalone-haddock /some/bin/dir/

An example of how to use standalone-haddock:

mkdir temp
cd temp
cabal get heredoc-0.2.0.0
standalone-haddock -o doc heredoc-0.2.0.0

Then open doc/heredoc/index.html in your browser.

When you navigate to a type definition you should see a Source link on the right and that will bring you to the new hyperlinked source.

相关阅读:
Top