[Haskell-cafe] auto-completion for Vim 7
claus.reinke at talk21.com
Sun Mar 4 15:29:33 EST 2007
>> If someone knows of a simple way to generate a function/type list of
>> the standard modules, I'd love to hear about it. Generating such a
>> list on the fly each time is probably not an option, as it would be
>> too slow.
> Using a recent version of haddock, the --hoogle flag gives you exactly
> what you want.
Neil: is there any documentation on the output format? i couldn't find the
flag in the haddock manual, so i was surprised to see it in haddock --help;
it works, though, and does seem to generate modules with implementations
removed, and some declarations simplified?
one problem with this is that hoogle.txt is not included with releases, nor
are the library sources, so this route won't be available for most ghc users.
that is why my Doc.vim, announced earlier today, extracts information
somewhat tediously from the haddock html index files that are included
at least with windows releases.
Stephan: if your goal is intelligent, context-aware completion, that's quite
ambituous for Haskell!-) you might want to reuse the more simple-minded
completion and information extraction included in Doc.vim as a start, so that
you can focus on the more interesting context-sensitive bits. the current
version of Doc.vim allows to write out the docindex, once extracted from
the haddocks, and with simple reading it back in rather than re-generation,
completion seems reasonably quick.
Doc.vim supports CTRL-X CTRL-U insert-mode completion by looking
for matching prefixes in the docindex, including all unqualified names in the
libraries. one can also separately qualify names.
if you want (naive) completion based on text in imported files as well, you
can tell Vim's standard insert-mode completion (CTRL-N) to follow imports,
by using 'set include= ' and 'set includeexpr= '. there's an example in the
by now ancient hugs.vim at http://www.cs.kent.ac.uk/~cr3/toolbox/haskell/Vim/
to provide completion also for non-libraries identifiers, perhaps completion
based on tags-files (as generated by :ctags in ghci), via CTRL-X CTRL-] ,
might be a good approach. those tags-file don't include type info yet, but
then i'm not quite sure how you'd be able to use type info for completion
in Vim (which doesn't know anything about Haskell types).
ghc -e ":ctags" Main.hs
ought to give you a tags file, including exported identifiers in your project,
but not in the libraries.
with these three completion variants, one can get by, though putting everything
together and adding at least some context-sensitivity would be nice.
the haddock --hoogle route has the additional issue that it will miss identifiers
without type declarations. you could use ghc itself to provide identifier lists:
$ ghc -e ":b Data.Char"
digitToInt :: Char -> Int
type String = [Char]
chr :: Int -> Char
with the obvious disadvantage that you'd need to name every module. but
you could get those from 'ghc-pkg describe base'.
anyway, let us know about any progress with such Haskell/Vim utilities.
ps. i'm still rehacktoring Doc.vim, adding and removing bugs and features,
but don't want to bother the list with updated versions. a recent one,
including functions for writing/reading docindex, can be found here:
More information about the Haskell-Cafe