MyNixOS website logo
Description

Generate tags file for Haskell project and its nearest deps.

Haskdogs is a 300-lines tool which creates tag file for entire Haskell project directory. It takes into account first-level dependencies by recursively scanning imports and adding matching packages to the final tag list. As a result, programmer can use his/her text editor supporting tags (vim, for example) to jump directly to definition of any standard or foreign function he/she uses. Note, that haskdogs calls some Unix shell commands like grep so this tool will likely fail to work on pure Windows platforms. Starting from 0.3, cmdline args will be passed to hasktags followed by a filelist generated. Starting from 0.4, haskdogs will use stack toolchain.

HaskDogs

Haskdogs is a shellscript-like tool which creates tag file for entire haskell project directory. It takes into account first-level dependencies by recursively scanning imports and adding matching projects to the dependency list. Next, Haskdogs uses cabal or stack to unpack their sources into a temporary directory, which is ~/.haskdogs by default. Finally, hasktags is called to produce the tags file.

As a result, programmer can use his/her text editor supporting tags (e.g. vim) to jump directly to definition of any standard or foreign function he/she uses.

Note, that haskdogs relies on some GNU programs as well as on Unix shell commands such as 'cd', 'mkdir' and so on. Also it would run 'stack' and ghc-pkg' in order to obtain package information.

INSTALL

Check the dependencies. Currently they are: stack, hasktags, GNU find, which and shell.

Please follow stack's documentation(https://github.com/commercialhaskell/stack) to install stack.

$ stack install hasktags haskdogs

Make sure that PATH contains path to your stack binaries directory ($HOME/.local/bin by default).

RUNNING

  1. Make sure yoy have installed hasktags and put it in PATH.

  2. cd to your Haskell project dir

    $ cd $HOME/my-haskell-project
    
  3. Run haskdogs without arguments to generate tags file in Vim-compatible format

    $ haskdogs
    

Emacs users would probably want to add -e hasktags option to build Emacs-compatible TAGS.

$ haskdogs --help
haskdogs - Recursive hasktags-based TAGS generator for a Haskell project

Usage: haskdogs [--version] [-d|--dir-list FILE] [-f|--file-list FILE]
                [-i|--input FILE] [--hasktags-args OPTS] [--stack-args OPTS]
                [--ghc-pkg-args OPTS] [--use-stack ARG] [--deps-dir PATH]
                [--raw] [-q|--quiet] [OPTS]

Available options:
  -h,--help                Show this help text
  --version                Show version number
  -d,--dir-list FILE       File containing directory list to process (use '-' to
                           read from stdin)
  -f,--file-list FILE      File containing Haskell sources to process (use '-'
                           to read from stdin)
  -i,--input FILE          Single Haskell file to process (use '-' to read
                           Haskell source from stdin)
  --hasktags-args OPTS     Arguments to pass to hasktags. -c -x is the default.
                           Not for raw mode.
  --stack-args OPTS        Arguments to pass to stack
  --ghc-pkg-args OPTS      Arguments to pass to ghc-pkgs
  --use-stack ARG          Execute ghc-pkg via stack, arg is ON, OFF or AUTO
                           (the default)
  --deps-dir PATH          Specify the directory PATH to place the dependencies
                           of the project. Default is [$HOME/.haskdogs]
  --raw                    Don't execute hasktags, print list of files to tag on
                           the STDOUT. The output may be piped into hasktags
                           like this: `haskdogs --raw | hasktags -c -x STDIN'
  -q,--quiet               Don't print verbose messages
  OPTS                     More hasktags options, use `--' to pass flags
                           starting with `-'. Not for raw mode.

The following error could be caused by (over)strict Haskell policy regarding Unicode locale:

haskdogs: fd:5: hGetContents: invalid argument (invalid byte sequence)

It usually happens when the program tries to print Unicode character to non-unicode console. In order to overcome, try the following setting:

export LANG=en_US.UTF8

VIM HINT

Hasdogs (and underlying Hasktags) use simple scanning algorithm so it may become confused facing functions with identical names. In this case Hasktags includes all of them in the output file so user has to decide which tag to jump to. Vim offers :tag and :ts commands to deal with such situations but it is somewhat cumbersome to type them every time.

To speedup things a bit I use the following vim binding. It iterates over all same tags quickly with just one C-] command.

" Cyclic tag navigation {{{
let g:rt_cw = ''
function! RT()
	let cw = expand('<cword>')
	try
		if cw != g:rt_cw
			execute 'tag ' . cw
			call search(cw,'c',line('.'))
		else
			try
				execute 'tnext'
			catch /.*/
				execute 'trewind'
			endtry
			call search(cw,'c',line('.'))
		endif
		let g:rt_cw = cw
	catch /.*/
		echo "no tags on " . cw
	endtry
endfunction
map <C-]> :call RT()<CR>
" }}}

Just copy the code above to your ~/.vimrc and reload the vim.

NIX NOTE

The easiest way to generate Hakell tags on Nix-machine is to run Haskdogs from nix-shell as follows:

nix-shell -p haskellPackages.haskdogs haskellPackages.hasktags haskellPackages.cabal-install ghc
(nix-shell) $ haskdogs

TIPS

  • create tags for specific package

    echo 'import Control.Lens' | haskdogs -i -

  • incremental update

    haskdogs -i % --hasktags-args "-x -c -a" | sort -u -o tags tags.

Metadata

Version

0.6.0

Executables (1)

  • bin/haskdogs

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows