Adapt AsyncLint to work with Neovim

This commit is contained in:
Talia 2021-01-28 14:58:41 +01:00
parent 6dda62b19e
commit d94912fb43
2 changed files with 15 additions and 16 deletions

View File

@ -1,21 +1,22 @@
augroup RUBY augroup RUBY
if b:undo_ftplugin if b:undo_ftplugin
let b:undo_ftplugin .= " | " let b:undo_ftplugin .= " | "
else else
let b:undo_ftplugin = "" let b:undo_ftplugin = ""
end end
let b:undo_ftplugin .= "augroup RUBY | au! | augroup 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" 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: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" let b:undo_ftplugin .= " | unlet b:linter"
set complete=t,.,kspell,i set complete=t,.,kspell,i
aut BufWritePost <buffer> Defer timeout 5 ripper-tags -R aut BufWritePost <buffer> Defer timeout 5 ripper-tags -R
" au InsertLeave <buffer> AsyncLint " au InsertLeave <buffer> AsyncLint
" au BufWritePre <buffer> Lint " au BufWritePre <buffer> Lint

View File

@ -3,7 +3,7 @@ function s:async_lint_done(bufnr, buffer)
call getbufvar(a:bufnr, "") call getbufvar(a:bufnr, "")
let l:pos = getcurpos() let l:pos = getcurpos()
call deletebufline(bufname(a:bufnr), 1, "$") call deletebufline(bufname(a:bufnr), 1, "$")
for line in a:buffer for line in a:buffer[0:-2]
call appendbufline(bufname(a:bufnr), "$", line) call appendbufline(bufname(a:bufnr), "$", line)
endfor endfor
call deletebufline(bufname(a:bufnr), 1) call deletebufline(bufname(a:bufnr), 1)
@ -22,13 +22,12 @@ endfun
function AsyncLint(bufnr, command) function AsyncLint(bufnr, command)
if getbufvar(a:bufnr, "lint_job")=="" if getbufvar(a:bufnr, "lint_job")==""
let l:buffer = [] let l:job = jobstart(a:command, {
let l:job = job_start(a:command, { \ "on_stdout": { id, text -> s:async_lint_done(a:bufnr, text) },
\ "in_io": "buffer", "in_name": bufname(a:bufnr), \ "stdout_buffered": 1,
\ "out_io": "pipe", \})
\ "out_cb": { pipe, text -> add(l:buffer, text) }, call chansend(l:job, getline(1, line("$")))
\ "close_cb": { pipe -> s:async_lint_done(a:bufnr, l:buffer) } call chanclose(l:job, "stdin")
\ })
call setbufvar(a:bufnr, "lint_job", l:job) call setbufvar(a:bufnr, "lint_job", l:job)
end end
endfun endfun
@ -38,4 +37,3 @@ augroup ASYNC_LINT
au TextChangedI * call s:async_lint_abort(bufnr("%")) au TextChangedI * call s:async_lint_abort(bufnr("%"))
au TextChangedP * call s:async_lint_abort(bufnr("%")) au TextChangedP * call s:async_lint_abort(bufnr("%"))
augroup END augroup END