Skip to content

Add option to use location list #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ function! GhcModQuickFix()
endfunction
```

If you want to use the location list instead of the quickfix list, set `g:ghcmod_use_loclist`.

```vim
let g:ghcmod_use_loclist = 1
```

### :GhcModCheckAsync, :GhcModLintAsync, :GhcModCheckAndLintAsync
You can run check and/or lint asynchronously.

Expand Down
48 changes: 36 additions & 12 deletions autoload/ghcmod/command.vim
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ function! ghcmod#command#make(type, force) "{{{
return
endif

let l:qflist = ghcmod#make(a:type, l:path)
call setqflist(l:qflist)
let l:list = ghcmod#make(a:type, l:path)
call s:set_list(l:list)
call s:open_quickfix()
if empty(l:qflist)
if empty(l:list)
echo printf('ghc-mod %s: No errors found', a:type)
endif
endfunction "}}}
Expand All @@ -202,14 +202,14 @@ function! ghcmod#command#async_make(type, force) "{{{
endif

let l:callback = { 'type': a:type }
function! l:callback.on_finish(qflist)
call setqflist(a:qflist)
function! l:callback.on_finish(list)
call s:set_list(a:list)
call s:open_quickfix()
if &l:buftype ==# 'quickfix'
" go back to original window
wincmd p
endif
if empty(a:qflist)
if empty(a:list)
echomsg printf('ghc-mod %s(async): No errors found', self.type)
endif
endfunction
Expand All @@ -224,18 +224,18 @@ function! ghcmod#command#check_and_lint_async(force) "{{{
endif

let l:callback = { 'first': 1 }
function! l:callback.on_finish(qflist)
function! l:callback.on_finish(list)
if self.first
call setqflist(a:qflist)
call s:set_list(a:list)
let self.first = 0
else
call setqflist(a:qflist, 'a')
call s:set_list(a:list, 'a')
call s:open_quickfix()
if &l:buftype ==# 'quickfix'
" go back to original window
wincmd p
endif
if empty(getqflist())
if empty(s:get_list())
echomsg 'ghc-mod check and lint(async): No errors found'
endif
endif
Expand All @@ -253,14 +253,38 @@ function! ghcmod#command#expand(force) "{{{
return
endif

call setqflist(ghcmod#expand(l:path))
call s:set_list(ghcmod#expand(l:path))
call s:open_quickfix()
endfunction "}}}

function! s:get_list() "{{{
let l:use_loclist = get(g:, 'ghcmod_use_loclist', 0)
if l:use_loclist
return getloclist(0)
else
return getqflist()
endif
endfunction "}}}

function! s:set_list(...) "{{{
let l:use_loclist = get(g:, 'ghcmod_use_loclist', 0)
if l:use_loclist
let l:args = [0] + a:000
call call('setloclist', l:args)
else
call call('setqflist', a:000)
endif
endfunction "}}}

function! s:open_quickfix() "{{{
let l:func = get(g:, 'ghcmod_open_quickfix_function', '')
if empty(l:func)
cwindow
let l:use_loclist = get(g:, 'ghcmod_use_loclist', 0)
if l:use_loclist
lwindow
else
cwindow
endif
else
try
call call(l:func, [])
Expand Down