Carlo Hamalainen


ghc-imported-from => ghc-mod (March 2017)

2017-03-19

I have a pull request to merge ghc-imported-from into ghc-mod. The main benefit of being part of ghc-mod is that I don't have to duplicate ghc-mod's infrastructure for handling sandboxes, GHC options, interfaces to other build tools like Stack, and compatibility with more versions of GHC.

The pull request is still under review, so until then you can try it out by cloning the development branches:

git clone -b imported-from https://github.com/DanielG/ghc-mod.git ghc-mod-imported-from
cd ghc-mod-imported-from
cabal update && cabal sandbox init && cabal install
export PATH=`pwd`/.cabal-sandbox/bin:$PATH

Assuming that you use Plugged for managing Vim/Neovim plugins, use my branch of ghcmod-vim by adding this to your vimrc:

call plug#begin('~/.vim/plugged')

Plug 'carlohamalainen/ghcmod-vim', { 'branch': 'ghcmod-imported-from-cmd', 'for' : 'haskell' }

Install the plugin with :PlugInstall in vim.

Here are some handy key mappings:

au FileType  haskell nnoremap <buffer> <F1>          :GhcModType<CR>
au FileType  haskell nnoremap <buffer> <F2>          :GhcModInfo<CR>
au FileType  haskell nnoremap <buffer> <silent> <F3> :GhcModTypeClear<CR>

au FileType lhaskell nnoremap <buffer> <F1>          :GhcModType<CR>
au FileType lhaskell nnoremap <buffer> <F2>          :GhcModInfo<CR>
au FileType lhaskell nnoremap <buffer> <silent> <F3> :GhcModTypeClear<CR>

au FileType haskell  nnoremap <buffer> <F4> :GhcModOpenDoc<CR>
au FileType lhaskell nnoremap <buffer> <F4> :GhcModOpenDoc<CR>

au FileType haskell  nnoremap <buffer> <F5> :GhcModDocUrl<CR>
au FileType lhaskell nnoremap <buffer> <F5> :GhcModDocUrl<CR>

au FileType haskell  vnoremap <F6> :<C-u> GhcModOpenHaddockVismode<CR>
au FileType lhaskell vnoremap <F6> :<C-u> GhcModOpenHaddockVismode<CR>

au FileType haskell  vnoremap <F7> :<C-u> GhcModEchoUrlVismode<CR>
au FileType lhaskell vnoremap <F7> :<C-u> GhcModEchoUrlVismode<CR>

On the command line, use the imported-from command. It tells you the defining module, the exporting module, and the Haddock URL:

$ ghc-mod imported-from Foo.hs 9 34 show
base-4.8.2.0:GHC.Show.show Prelude https://hackage.haskell.org/package/base-4.8.2.0/docs/Prelude.html

From Vim/Neovim, navigate to a symbol and hit F4 which will open the Haddock URL in your browser, or F5 to echo the command-line output.