Adapt AsyncLint to work with Neovim
This commit is contained in:
parent
6dda62b19e
commit
d94912fb43
2 changed files with 15 additions and 16 deletions
|
@ -6,12 +6,13 @@ augroup RUBY
|
|||
end
|
||||
let b:undo_ftplugin .= "augroup RUBY | au! | augroup END"
|
||||
|
||||
comm! -buffer AsyncLint call AsyncLint(bufnr("%"), b:linter->substitute("%", expand("%"), "g"))
|
||||
" comm! -buffer AsyncLint call AsyncLint(bufnr("%"), substitute(b:linter, "%", expand("%"), "g"))
|
||||
comm! -buffer AsyncLint call AsyncLint(bufnr("%"), substitute(substitute(b:linter, "$0", "\\\\$0", "g"), "%", expand("%"), "g"))
|
||||
let b:undo_ftplugin .= " | delcommand AsyncLint"
|
||||
comm! -buffer Lint silent exec "%!".b:linter->substitute("$0", "\\\\$0", "g")->substitute("%", expand("%"), "g")
|
||||
comm! -buffer Lint silent exec "%!".substitute(substitute(b:linter, "$0", "\\\\$0", "g"), "%", expand("%"), "g")
|
||||
let b:undo_ftplugin .= " | delcommand Lint"
|
||||
|
||||
let b:linter = "sh -c \"rubocop --auto-correct -o /dev/null --stdin % 2>/dev/null | awk 'BEGIN { header=0 } // && header==1 { print $0 } /^====================$/ { header=1 }'\""
|
||||
let b:linter = "sh -c \"standardrb --auto-correct -o /dev/null --stdin % 2>/dev/null | awk 'BEGIN { header=0 } // && header==1 { print $0 } /^====================$/ { header=1 }'\""
|
||||
let b:undo_ftplugin .= " | unlet b:linter"
|
||||
|
||||
set complete=t,.,kspell,i
|
||||
|
|
|
@ -3,7 +3,7 @@ function s:async_lint_done(bufnr, buffer)
|
|||
call getbufvar(a:bufnr, "")
|
||||
let l:pos = getcurpos()
|
||||
call deletebufline(bufname(a:bufnr), 1, "$")
|
||||
for line in a:buffer
|
||||
for line in a:buffer[0:-2]
|
||||
call appendbufline(bufname(a:bufnr), "$", line)
|
||||
endfor
|
||||
call deletebufline(bufname(a:bufnr), 1)
|
||||
|
@ -22,13 +22,12 @@ endfun
|
|||
|
||||
function AsyncLint(bufnr, command)
|
||||
if getbufvar(a:bufnr, "lint_job")==""
|
||||
let l:buffer = []
|
||||
let l:job = job_start(a:command, {
|
||||
\ "in_io": "buffer", "in_name": bufname(a:bufnr),
|
||||
\ "out_io": "pipe",
|
||||
\ "out_cb": { pipe, text -> add(l:buffer, text) },
|
||||
\ "close_cb": { pipe -> s:async_lint_done(a:bufnr, l:buffer) }
|
||||
\ })
|
||||
let l:job = jobstart(a:command, {
|
||||
\ "on_stdout": { id, text -> s:async_lint_done(a:bufnr, text) },
|
||||
\ "stdout_buffered": 1,
|
||||
\})
|
||||
call chansend(l:job, getline(1, line("$")))
|
||||
call chanclose(l:job, "stdin")
|
||||
call setbufvar(a:bufnr, "lint_job", l:job)
|
||||
end
|
||||
endfun
|
||||
|
@ -38,4 +37,3 @@ augroup ASYNC_LINT
|
|||
au TextChangedI * call s:async_lint_abort(bufnr("%"))
|
||||
au TextChangedP * call s:async_lint_abort(bufnr("%"))
|
||||
augroup END
|
||||
|
||||
|
|
Loading…
Reference in a new issue