-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d5ecc16
Showing
3 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |