Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Aug 19, 2016
0 parents commit d5ecc16
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) Alexis Sellier 2016.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Neil Mitchell nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 changes: 27 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@



neovim-ghcid


Provides instant haskell error feedback inside of neovim, via ghcid[1].

In principle, this should work a lot better than the alternatives.

[1]: https://github.com/ndmitchell/ghcid

0. Dependencies

* neovim (https://github.com/neovim/neovim)
* ghcid (https://github.com/ndmitchell/ghcid)

1. Usage

`:Ghcid` runs ghcid inside a neovim terminal buffer and populates
the quickfix list with any errors or warnings.

After every file save, the quickfix list is updated with the output
of ghcid.

`:GhcidKill` kills the ghcid job.

101 changes: 101 additions & 0 deletions ftplugin/haskell.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"
" neovim-ghcid
"
" Author: Alexis Sellier <http://cloudhead.io>
" Version: 0.1

if exists("g:ghcid_loaded") || &cp || !has('nvim')
finish
endif
let g:ghcid_loaded = 1

let g:ghcid_lines = 10
let s:ghcid_base_sign_id = 100
let s:ghcid_sign_id = s:ghcid_base_sign_id
let s:ghcid_dummy_sign_id = 99
let s:ghcid_job_id = 0

command! Ghcid call s:ghcid()
command! GhcidKill call s:ghcid_kill()

sign define ghcid-error text=·· texthl=ErrorMsg
sign define ghcid-dummy

function! s:ghcid_init()
exe 'sign' 'place' s:ghcid_dummy_sign_id 'line=9999' 'name=ghcid-dummy' 'buffer=' . bufnr('%')
endfunction

autocmd BufWritePost,FileChangedShellPost *.hs call s:ghcid_clear_signs()
autocmd TextChanged *.hs call s:ghcid_clear_signs()
autocmd BufEnter *.hs call s:ghcid_init()

function! s:ghcid_update(ghcid, data) abort
caddexpr join(a:data, "\n")
let list = getqflist()
let filename = expand('%:p')
let errors = 0

for entry in list
if entry.valid
let errors += 1
let s:ghcid_sign_id += 1
silent exe "sign"
\ "place"
\ s:ghcid_sign_id
\ "line=" . string(entry.lnum)
\ "name=ghcid-error"
\ "file=" . expand(bufname(entry.bufnr))
endif
endfor

if !empty(matchstr(a:data, "All good"))
if !a:ghcid.closed
let a:ghcid.closed = 1
drop ghcid
quit
endif
echo "Ghcid: OK"
elseif errors != 0 && a:ghcid.closed
let a:ghcid.closed = 0
bot split ghcid
execute 'resize' g:ghcid_lines
normal! G
wincmd p
endif
endfunction

function! s:ghcid_clear_signs() abort
for i in range(s:ghcid_base_sign_id, s:ghcid_sign_id)
silent exe 'sign' 'unplace' i
endfor
cexpr ""
let s:ghcid_sign_id = s:ghcid_base_sign_id
endfunction

function! s:ghcid() abort
let command = "ghcid"
let opts = { 'closed': 0 }

function! opts.on_exit(id, code)
endfunction

function! opts.on_stdout(id, data, event) abort
call s:ghcid_update(self, a:data)
endfunction

below new
execute 'resize' g:ghcid_lines
call termopen(command, opts)
let s:ghcid_job_id = b:terminal_job_id
file ghcid
wincmd p
endfunction

function! s:ghcid_kill() abort
if !empty(bufname('ghcid'))
silent bwipeout! ghcid
echo "Ghcid: Killed"
else
echo "Ghcid: Not running"
endif
endfunction

0 comments on commit d5ecc16

Please sign in to comment.