From d94912fb43b7cba55172b9d4f62deba6d3dd0f6a Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Thu, 28 Jan 2021 14:58:41 +0100 Subject: [PATCH] Adapt AsyncLint to work with Neovim --- vim/ftplugin/ruby.vim | 15 ++++++++------- vim/plugin/async_lint.vim | 16 +++++++--------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/vim/ftplugin/ruby.vim b/vim/ftplugin/ruby.vim index d83936f..4d150a0 100644 --- a/vim/ftplugin/ruby.vim +++ b/vim/ftplugin/ruby.vim @@ -1,21 +1,22 @@ augroup RUBY if b:undo_ftplugin - let b:undo_ftplugin .= " | " + let b:undo_ftplugin .= " | " else - let b:undo_ftplugin = "" + let b:undo_ftplugin = "" 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 - aut BufWritePost Defer timeout 5 ripper-tags -R + set complete=t,.,kspell,i + aut BufWritePost Defer timeout 5 ripper-tags -R " au InsertLeave AsyncLint " au BufWritePre Lint diff --git a/vim/plugin/async_lint.vim b/vim/plugin/async_lint.vim index b16d9eb..bc05584 100644 --- a/vim/plugin/async_lint.vim +++ b/vim/plugin/async_lint.vim @@ -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 -