Skip to content

Commit 2ba31c2

Browse files
update async.vim to 0fb846e1eb3c2bf04d52a57f41088afb3395212e (#1117)
avoid has_key check for on_stdout and on_stderr
1 parent a3b58eb commit 2ba31c2

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

autoload/lsp/utils/job.vim

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
" https://github.com/prabirshrestha/async.vim#236debf1a68d69a74f1f6647c273b0477e1ec1bf (dirty)
1+
" https://github.com/prabirshrestha/async.vim#0fb846e1eb3c2bf04d52a57f41088afb3395212e (dirty)
22
" :AsyncEmbed path=./autoload/lsp/utils/job.vim namespace=lsp#utils#job
33

44
" Author: Prabir Shrestha <mail at prabir dot me>
@@ -36,6 +36,9 @@ let s:job_type_nvimjob = 'nvimjob'
3636
let s:job_type_vimjob = 'vimjob'
3737
let s:job_error_unsupported_job_type = -2 " unsupported job type
3838

39+
function! s:noop(...) abort
40+
endfunction
41+
3942
function! s:job_supported_types() abort
4043
let l:supported_types = []
4144
if has('nvim')
@@ -52,15 +55,11 @@ function! s:job_supports_type(type) abort
5255
endfunction
5356

5457
function! s:out_cb(jobid, opts, job, data) abort
55-
if has_key(a:opts, 'on_stdout')
56-
call a:opts.on_stdout(a:jobid, split(a:data, "\n", 1), 'stdout')
57-
endif
58+
call a:opts.on_stdout(a:jobid, split(a:data, "\n", 1), 'stdout')
5859
endfunction
5960

6061
function! s:err_cb(jobid, opts, job, data) abort
61-
if has_key(a:opts, 'on_stderr')
62-
call a:opts.on_stderr(a:jobid, split(a:data, "\n", 1), 'stderr')
63-
endif
62+
call a:opts.on_stderr(a:jobid, split(a:data, "\n", 1), 'stderr')
6463
endfunction
6564

6665
function! s:exit_cb(jobid, opts, job, status) abort
@@ -73,21 +72,13 @@ function! s:exit_cb(jobid, opts, job, status) abort
7372
endfunction
7473

7574
function! s:on_stdout(jobid, data, event) abort
76-
if has_key(s:jobs, a:jobid)
77-
let l:jobinfo = s:jobs[a:jobid]
78-
if has_key(l:jobinfo.opts, 'on_stdout')
79-
call l:jobinfo.opts.on_stdout(a:jobid, a:data, a:event)
80-
endif
81-
endif
75+
let l:jobinfo = s:jobs[a:jobid]
76+
call l:jobinfo.opts.on_stdout(a:jobid, a:data, a:event)
8277
endfunction
8378

8479
function! s:on_stderr(jobid, data, event) abort
85-
if has_key(s:jobs, a:jobid)
86-
let l:jobinfo = s:jobs[a:jobid]
87-
if has_key(l:jobinfo.opts, 'on_stderr')
88-
call l:jobinfo.opts.on_stderr(a:jobid, a:data, a:event)
89-
endif
90-
endif
80+
let l:jobinfo = s:jobs[a:jobid]
81+
call l:jobinfo.opts.on_stderr(a:jobid, a:data, a:event)
9182
endfunction
9283

9384
function! s:on_exit(jobid, status, event) abort
@@ -138,8 +129,8 @@ function! s:job_start(cmd, opts) abort
138129

139130
if l:jobtype == s:job_type_nvimjob
140131
call extend(l:jobopt, {
141-
\ 'on_stdout': function('s:on_stdout'),
142-
\ 'on_stderr': function('s:on_stderr'),
132+
\ 'on_stdout': has_key(a:opts, 'on_stdout') ? function('s:on_stdout') : function('s:noop'),
133+
\ 'on_stderr': has_key(a:opts, 'on_stderr') ? function('s:on_stderr') : function('s:noop'),
143134
\ 'on_exit': function('s:on_exit'),
144135
\})
145136
let l:job = jobstart(a:cmd, l:jobopt)
@@ -156,8 +147,8 @@ function! s:job_start(cmd, opts) abort
156147
let s:jobidseq = s:jobidseq + 1
157148
let l:jobid = s:jobidseq
158149
call extend(l:jobopt, {
159-
\ 'out_cb': function('s:out_cb', [l:jobid, a:opts]),
160-
\ 'err_cb': function('s:err_cb', [l:jobid, a:opts]),
150+
\ 'out_cb': has_key(a:opts, 'on_stdout') ? function('s:out_cb', [l:jobid, a:opts]) : function('s:noop'),
151+
\ 'err_cb': has_key(a:opts, 'on_stderr') ? function('s:err_cb', [l:jobid, a:opts]) : function('s:noop'),
161152
\ 'exit_cb': function('s:exit_cb', [l:jobid, a:opts]),
162153
\ 'mode': 'raw',
163154
\ })

0 commit comments

Comments
 (0)