1
- " https://github.com/prabirshrestha/async.vim#236debf1a68d69a74f1f6647c273b0477e1ec1bf (dirty)
1
+ " https://github.com/prabirshrestha/async.vim#0fb846e1eb3c2bf04d52a57f41088afb3395212e (dirty)
2
2
" :AsyncEmbed path=./autoload/lsp/utils/job.vim namespace=lsp#utils#job
3
3
4
4
" Author: Prabir Shrestha <mail at prabir dot me>
@@ -36,6 +36,9 @@ let s:job_type_nvimjob = 'nvimjob'
36
36
let s: job_type_vimjob = ' vimjob'
37
37
let s: job_error_unsupported_job_type = -2 " unsupported job type
38
38
39
+ function ! s: noop (... ) abort
40
+ endfunction
41
+
39
42
function ! s: job_supported_types () abort
40
43
let l: supported_types = []
41
44
if has (' nvim' )
@@ -52,15 +55,11 @@ function! s:job_supports_type(type) abort
52
55
endfunction
53
56
54
57
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' )
58
59
endfunction
59
60
60
61
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' )
64
63
endfunction
65
64
66
65
function ! s: exit_cb (jobid, opts, job, status) abort
@@ -73,21 +72,13 @@ function! s:exit_cb(jobid, opts, job, status) abort
73
72
endfunction
74
73
75
74
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 )
82
77
endfunction
83
78
84
79
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 )
91
82
endfunction
92
83
93
84
function ! s: on_exit (jobid, status, event ) abort
@@ -138,8 +129,8 @@ function! s:job_start(cmd, opts) abort
138
129
139
130
if l: jobtype == s: job_type_nvimjob
140
131
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 ' ),
143
134
\ ' on_exit' : function (' s:on_exit' ),
144
135
\} )
145
136
let l: job = jobstart (a: cmd , l: jobopt )
@@ -156,8 +147,8 @@ function! s:job_start(cmd, opts) abort
156
147
let s: jobidseq = s: jobidseq + 1
157
148
let l: jobid = s: jobidseq
158
149
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 ' ),
161
152
\ ' exit_cb' : function (' s:exit_cb' , [l: jobid , a: opts ]),
162
153
\ ' mode' : ' raw' ,
163
154
\ })
0 commit comments