Skip to content

Commit ab33578

Browse files
authored
Merge pull request #33 from jamesdbrock/stack-aware
Haskell Tool Stack awareness
2 parents 2224117 + 699761b commit ab33578

File tree

3 files changed

+65
-15
lines changed

3 files changed

+65
-15
lines changed

README.md

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ hdevtools Vim Plugin
22
====================
33

44
Vim plugin for Haskell development powered by the lightning fast
5-
[hdevtools](<https://github.com/bitc/hdevtools/>) background server.
5+
[hdevtools](<https://github.com/hdevtools/hdevtools/>) background server.
66

77

88
About
99
-----
1010

11-
[hdevtools](<https://github.com/bitc/hdevtools/>) is a command line program
11+
[hdevtools](<https://github.com/hdevtools/hdevtools/>) is a command line program
1212
powered by the GHC API, that provides services for Haskell development.
1313
hdevtools works by running a persistent process in the background, so that your
1414
Haskell modules remain in memory, instead of having to reload everything each
@@ -19,25 +19,60 @@ editor.
1919
This is the Vim plugin that integrates Vim with hdevtools.
2020

2121

22-
Installation
22+
Requirements
2323
------------
2424

25-
1. You must install the `hdevtools` command line program, It can be found
26-
here: <https://github.com/bitc/hdevtools/>, or from Hackage:
25+
The *vim-hdevtools* plugin requires a way to run `hdevtools`. Here are the
26+
ways to make `hdevtools` available to the plugin.
27+
28+
### Global `hdevtools`
29+
30+
Install the `hdevtools` command line program so that it is on your
31+
executable `$PATH`.
32+
33+
Get it from Github: <https://github.com/hdevtools/hdevtools/>
34+
35+
Or from Hackage:
36+
37+
$ cabal install hdevtools
38+
39+
Or from Stackage:
40+
41+
$ stack install hdevtools
42+
43+
Note that `hdevtools` must be built with the same version of GHC as the
44+
project which you will be editing.
2745

28-
$ cabal install hdevtools
46+
### Local `hdevtools` with `stack`
2947

30-
2. Install this plugin. [pathogen.vim](<https://github.com/tpope/vim-pathogen/>)
48+
If your project is built with [stack](<https://www.haskellstack.org>) and
49+
if you run Vim from the directory that contains `stack.yaml`, then
50+
the *vim-hdevtools* plugin can employ `stack` to automatically install
51+
`hdevtools` built with the same version of GHC indicated by the resolver
52+
in your `stack.yaml`. This will not conflict with any other installations
53+
of `hdevtools` on your system.
54+
55+
If you want the *vim-hdevtools* plugin to use `stack`,
56+
you have to enable this feature in your `.vimrc` like so:
57+
58+
let g:hdevtools_stack = 1
59+
60+
61+
Installation
62+
------------
63+
64+
1. Install this plugin. [pathogen.vim](<https://github.com/tpope/vim-pathogen/>)
3165
is the recommended way:
3266

3367
cd ~/.vim/bundle
3468
git clone https://github.com/bitc/vim-hdevtools.git
3569

36-
3. Configure your keybindings in your `.vimrc` file. I recommend something
70+
2. Configure your keybindings in your `.vimrc` file. I recommend something
3771
like:
3872

3973
au FileType haskell nnoremap <buffer> <F1> :HdevtoolsType<CR>
40-
au FileType haskell nnoremap <buffer> <silent> <F2> :HdevtoolsClear<CR>
74+
au FileType haskell nnoremap <buffer> <silent> <F2> :HdevtoolsInfo<CR>
75+
au FileType haskell nnoremap <buffer> <silent> <F3> :HdevtoolsClear<CR>
4176

4277

4378
Features
@@ -61,6 +96,9 @@ The type for the expression under the cursor will be printed, and the
6196
expression will be highlighted. Repeated presses will expand the expression
6297
that is examined.
6398

99+
To get information from GHC about the identifier under cursor,
100+
execute `HdevtoolsInfo` (or press the `<F2>` key as configured above).
101+
64102
You can execute `HdevtoolsClear` to get rid of the highlighting.
65103

66104
Customization
@@ -79,6 +117,12 @@ appropriate (such as your project's `Session.vim`):
79117
Make sure that each GHC option has its own `-g` prefix (don't group multiple
80118
options like this: `"-g-isrc\ -Wall"`)
81119

120+
I recommend setting the flag to
121+
[defer GHC type errors to runtime](<https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#deferring-type-errors-to-runtime>),
122+
so that Haskell expressions can be typechecked even if type errors
123+
elsewhere in the project would otherwise prevent GHC from compiling.
124+
125+
let g:hdevtools_options = '-g-fdefer-type-errors'
82126

83127
Credits
84128
-------

autoload/hdevtools.vim

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,18 +477,15 @@ function! s:on_leave()
477477
endfunction
478478

479479
function! hdevtools#build_command(command, args)
480-
let l:cmd = 'hdevtools'
481-
let l:cmd = l:cmd . ' ' . a:command . ' '
482-
480+
let l:cmd = g:hdevtools_exe . ' ' . a:command . ' '
483481
let l:cmd = l:cmd . get(g:, 'hdevtools_options', '') . ' '
484482
let l:cmd = l:cmd . a:args
485483
return l:cmd
486484
endfunction
487485

488486
" Does not include g:hdevtools_options
489487
function! hdevtools#build_command_bare(command, args)
490-
let l:cmd = 'hdevtools'
491-
let l:cmd = l:cmd . ' ' . a:command . ' '
488+
let l:cmd = g:hdevtools_exe . ' ' . a:command . ' '
492489
let l:cmd = l:cmd . a:args
493490
return l:cmd
494491
endfunction

ftplugin/haskell/hdevtools.vim

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ let b:did_ftplugin_hdevtools = 1
66
if !exists('s:has_hdevtools')
77
let s:has_hdevtools = 0
88

9-
if !executable('hdevtools')
9+
" For stack support, vim must be started in the directory containing stack.yaml
10+
if exists('g:hdevtools_stack') && g:hdevtools_stack && filereadable("stack.yaml")
11+
if !executable('stack')
12+
call hdevtools#print_error('hdevtools: stack.yaml found, but stack is not executable!')
13+
finish
14+
endif
15+
let g:hdevtools_exe = 'stack exec --silent --no-ghc-package-path --package hdevtools hdevtools --'
16+
elseif executable('hdevtools')
17+
let g:hdevtools_exe = 'hdevtools'
18+
else
1019
call hdevtools#print_error('hdevtools: hdevtools is not executable!')
1120
finish
1221
endif

0 commit comments

Comments
 (0)