1) and 2) were answered by permeakra in comments. I'll try to cover 3) by describing setup similar to the one I'm using. First simple solution for base libraries, then more generic solution for whatever Haskell source package in general.
As a prerequisites we will need a tool which generates tags file for Haskell:
cabal install hothasktags
Instead of hothasktags
you might use your favourite one. See for example https://github.com/bitc/lushtags page which enumerates some of these.
Then we need to have sources for base libraries available. Here I'm using the ones from GitHub:
cd /space/haskell/sources/ # tweak to your personal taste
git clone https://github.com/ghc/packages-base.git
Optionally we might switch to particular branch. E.g.:
git checkout ghc-7.4
Run git branch -a
to see all possibilities.
Now let's generate tags for the base libraries (I do not have Mac available and thus have to assume the command works there or you are able to tweak it appropriately):
cd packages-base
export LC_ALL=C # needed for case-sensitive searching
find -type f | egrep \.hs$\|\.lhs$ | xargs -Ii hothasktags i | sort > tags
(Note about sort: My Vim complains when I do not use the sort. For LC_ALL
explanation see for example this blog post)
Now we need to let the Vim know about the tags we generated. The easiest way is probably to put the following line into your $HOME/.vimrc
:
autocmd FileType haskell setlocal tags+=/space/haskell/sources/packages-base/tags
This way the tags for base libraries will be set for each Haskell file we open. If this is not desirable we can put following Vim command into .vimrc
:
autocmd FileType haskell command! SetGHCTags
\ setlocal tags+=/space/haskell/sources/packages-base/tags
and call :SetGHCTags
on demand.
For more generic solution which works with all Haskell sources packages we can use the following function (put into .vimrc
or into Vim file dedicated to Haskell filetype):
" Add 'tags' of the given package to the current tag stack. The package sources
" must be available in "/space/haskell/sources/<package>" and the tags must be
" generated for it.
fun! s:SetHaskellTags(pathInHaskellSrcDir) "{{{
let tagFile = "/space/haskell/sources/" . a:pathInHaskellSrcDir . "/tags"
if filereadable(tagFile)
exe "setlocal tags+=" . tagFile
else
echoerr "File does not exist or is not readable: " . tagFile
endif
endfunction "}}}
command! -nargs=1 SetHaskellTags call <SID>SetHaskellTags(<args>)
Utilizing it for example for Shelly.hs
library:
cd /space/haskell/sources/
git clone https://github.com/yesodweb/Shelly.hs.git
cd Shelly.hs
regenerate-haskell-tags # [1]
In Vim just call:
:SetHaskellTags "Shelly.hs"
There is space for improvement - SetHaskellTags
could generate tags if not exist, or could even fetch the sources, configurable Haskell source code storage, directory completion, etc. But works good enough for me now. So at least sharing the solution I have. Will come back here if I get to some of these improvement done.
[1]: It's better to store regenerate-haskell-tags
in your $PAHT
.
.hs
file. – Thereafter