Skip to content

Commit

Permalink
Use dict for custom backend, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
owickstrom committed Dec 13, 2017
1 parent 724e96b commit 81b4adf
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 10 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ Some key features:
The installation is local (not global!). This means that Intero is always
current for each of your projects. The goal of Intero is to Just Work™.

- **Bring Your Own GHCi**

You can configure the plugin to use a custom *backend*, e.g. `cabal repl` or
plain `ghci`, instead of the default Intero backend. Newer features are
enabled based on the GHCi version.

- **On-the-fly Typechecking**

Intero reports errors and warnings as you work on your file using the Neomake
Expand Down Expand Up @@ -149,6 +155,27 @@ augroup END
let g:intero_start_immediately = 0
```

## Using a Custom Backend

The default Intero backend can be overriden, so that you can use this plugin
without Stack and Intero. The following configuration uses `cabal new-repl`,
and specifies a `cwd` for a sub-directory project:

``` vim
let g:intero_backend = {
\ 'command': 'cabal new-repl',
\ 'options': '-Wall',
\ 'cwd': expand('%:p:h')
| }
```

Such configuration can be set per-project using a [local .nvimrc
file](https://andrew.stwrt.ca/posts/project-specific-vimrc/), or in your init
file for a system-wide effect.

**NOTE:** If `g:intero_backend` is set, `g:intero_ghci_options` and
`g:intero_load_targets` have no effect.

## Caveats

- Running `:Neomake!` directly will not work. You need to run `:InteroReload`
Expand Down
26 changes: 17 additions & 9 deletions autoload/intero/process.vim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function! intero#process#initialize() abort
echom 'Neomake not detected. Flychecking will be disabled.'
endif

if(!s:uses_custom_ghci())
if(!s:uses_custom_backend())
call s:ensure_intero_is_installed()
endif

Expand All @@ -56,7 +56,7 @@ function! intero#process#start() abort

call intero#process#initialize()

if !s:uses_custom_ghci() && (!exists('g:intero_built') || g:intero_built == 0)
if !s:uses_custom_backend() && (!exists('g:intero_built') || g:intero_built == 0)
echom 'Intero is still compiling'
return -1
endif
Expand Down Expand Up @@ -134,8 +134,8 @@ function! intero#process#restart() abort
endfunction

function! intero#process#restart_with_targets(...) abort
if s:uses_custom_ghci()
throw 'Targets is not supported when using a custom GHCi command.'
if s:uses_custom_backend()
throw 'Selecting targets is not supported when using a custom GHCi backend.'
end

if a:0 == 0
Expand All @@ -151,8 +151,8 @@ endfunction
" Private:
""""""""""

function! s:uses_custom_ghci() abort
return exists('g:intero_ghci_command')
function! s:uses_custom_backend() abort
return exists('g:intero_backend')
endfunction

function! s:start_compile(height, opts) abort
Expand Down Expand Up @@ -373,9 +373,17 @@ function! s:build_terminal_invocation() abort
\ 'on_stdout': function('s:on_stdout'),
\ }

if s:uses_custom_ghci()
" Override to use a custom GHCi command.
let l:terminal_command = g:intero_ghci_command
if s:uses_custom_backend()
" Override to use a custom GHCi backend.
let l:terminal_command = g:intero_backend.command
" Add options if set.
if has_key(g:intero_backend, 'options')
let l:terminal_command .= ' ' . g:intero_backend.options
endif
" Use user-specified cwd if set.
if has_key(g:intero_backend, 'cwd')
let l:terminal_options.cwd = g:intero_backend.cwd
endif
else
" Use the default Intero invocation.
let l:terminal_ghci_options = []
Expand Down
23 changes: 22 additions & 1 deletion doc/intero.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ different stack project than you were in initially, you may want to call
list.

*:InteroUseAllTargets*
:InteroUseAllTargets
:InteroUseAllTargets
This loads all targets specified by `stack ide targets`.

*:InteroClearTargetCache*
Expand Down Expand Up @@ -323,6 +323,27 @@ g:intero_ghci_options

Options that configure the behaviour of GHCi. For example, -fobject-code.

*g:intero_backend*

Overrides the default `intero` backend with a custom one. Specified as a
dict: >
let g:intero_backend = {
\ 'command': 'ghci',
\ 'options': '-Wall',
\ 'cwd': expand('%:p:h')
| }
<
The following keys are supported:

* `'command'`: the command to start a GHCi REPL, e.g. `cabal repl` or
`ghci`.
* `'options'`: a string of command-line arguments to the command (optional)
* `'cwd'`: specifies the current working directory of the GHCi
process (optional)

If `g:intero_backend` is set, `g:intero_ghci_options` and
`g:intero_load_targets` have no effect.

=============================================================================
CAVEATS *intero-caveats*

Expand Down

0 comments on commit 81b4adf

Please sign in to comment.