@@ -172,17 +172,42 @@ function! dispatch#vim_executable() abort
172172 return s: vim
173173endfunction
174174
175- function ! dispatch#has_callback () abort
176- return has (' clientserver' ) && ! empty (v: servername )
175+ function dispatch#has_callback () abort
176+ if has (' clientserver' ) && ! empty (v: servername )
177+ return 1
178+ elseif ! exists (' *job_start' ) && ! exists (' *jobstart' )
179+ return 0
180+ endif
181+ if ! exists (' s:has_temp_fifo' )
182+ let fifo = tempname ()
183+ call system (' mkfifo ' . dispatch#shellescape (fifo))
184+ let s: has_temp_fifo = (getftype (fifo) == # ' fifo' )
185+ call delete (fifo)
186+ endif
187+ return s: has_temp_fifo
177188endfunction
178189
179190function ! dispatch#callback (request) abort
180- if has (' clientserver' ) && ! empty (v: servername ) && has_key (s: request (a: request ), ' id' )
191+ let request = s: request (a: request )
192+ if ! has_key (request, ' id' ) || ! dispatch#has_callback ()
193+ return ' '
194+ endif
195+ if has (' clientserver' ) && ! empty (v: servername )
181196 return dispatch#shellescape (dispatch#vim_executable ()) .
182197 \ ' --servername ' . dispatch#shellescape (v: servername ) .
183- \ ' --remote-expr "' . ' DispatchComplete(' . s: request( a: request ) .id . ' )' . ' "'
198+ \ ' --remote-expr "' . ' DispatchComplete(' . request.id . ' )' . ' "'
184199 endif
185- return ' '
200+ call system (' mkfifo ' . dispatch#shellescape (request.file . ' .callback' ))
201+ let cmd = [' head' , ' -1' , request.file . ' .callback' ]
202+ let Cb = { ... - > dispatch#complete (request.id) }
203+ if exists (' *job_start' )
204+ call job_start (cmd, {' exit_cb' : Cb})
205+ elseif exists (' *jobstart' )
206+ call jobstart (cmd, {' on_exit' : Cb})
207+ else
208+ return ' '
209+ endif
210+ return ' echo > ' . request.file . ' .callback'
186211endfunction
187212
188213function ! dispatch#autowrite () abort
0 commit comments