Skip to content

Commit 699761b

Browse files
committed
Stack support
If a `stack.yaml` file is found in the pwd, then hdevtools commands will be invoked by `stack exec --package hdevtools hdevtools` instead of `hdevtools`. `hdevtools` must be built with the same version of GHC as the project being inspected. With Stack support for vim-hdevtools, `hdevtools` will be built with the same version of GHC referred to by the `stack.yaml` resolver for the project, and `hdevtools` will be automatically installed locally the first time a vim-hdevtools command is run. Stack support must be enabled by `g:hdevtools_stack = 1`, otherwise vim-hdevtools will revert to the usual behavior of always looking for `hdevtools` in the `$PATH`. This will provide continuity for users who would be surprised by the new behavior if they weren't expecting it. In the future, perhaps Stack support could be enabled by default.
1 parent 85462d9 commit 699761b

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,55 @@ 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/hdevtools/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
2742

28-
$ cabal install hdevtools
43+
Note that `hdevtools` must be built with the same version of GHC as the
44+
project which you will be editing.
45+
46+
### Local `hdevtools` with `stack`
47+
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+
------------
2963

30-
2. Install this plugin. [pathogen.vim](<https://github.com/tpope/vim-pathogen/>)
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>

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)