comparison autoload/gutentags.vim @ 267:6030953258fe

On Windows, kill ongoing jobs before leaving so we can clean-up temp files
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 12 May 2022 09:20:21 -0700
parents cbe7ffc327a4
children f75a8cddf174
comparison
equal deleted inserted replaced
266:1b74fb3819e1 267:6030953258fe
352 " Set a variable on exit so that we don't complain when a job gets killed. 352 " Set a variable on exit so that we don't complain when a job gets killed.
353 function! gutentags#on_vim_leave_pre() abort 353 function! gutentags#on_vim_leave_pre() abort
354 let g:__gutentags_vim_is_leaving = 1 354 let g:__gutentags_vim_is_leaving = 1
355 endfunction 355 endfunction
356 356
357 function! gutentags#on_vim_leave() abort
358 if has('win32') && !has('nvim')
359 " Vim8 doesn't seem to be killing child processes soon enough for
360 " us to clean things up inside this plugin, so do it ourselves.
361 " TODO: test other platforms and other vims
362 for module in g:gutentags_modules
363 for upd_info in s:update_in_progress[module]
364 let l:job = upd_info[1]
365 call job_stop(l:job, "term")
366 let l:status = job_status(l:job)
367 if l:status == "run"
368 call job_stop(l:job, "kill")
369 endif
370 endfor
371 endfor
372 endif
373 endfunction
374
357 " }}} 375 " }}}
358 376
359 " Job Management {{{ 377 " Job Management {{{
360 378
361 " List of queued-up jobs, and in-progress jobs, per module. 379 " List of queued-up jobs, and in-progress jobs, per module.
364 for module in g:gutentags_modules 382 for module in g:gutentags_modules
365 let s:update_queue[module] = [] 383 let s:update_queue[module] = []
366 let s:update_in_progress[module] = [] 384 let s:update_in_progress[module] = []
367 endfor 385 endfor
368 386
387 " Adds a started job to the list of ongoing updates.
388 " Must pass the tags file being created/updated, and the job data as
389 " returned by the gutentags#start_job function
369 function! gutentags#add_job(module, tags_file, data) abort 390 function! gutentags#add_job(module, tags_file, data) abort
370 call add(s:update_in_progress[a:module], [a:tags_file, a:data]) 391 call add(s:update_in_progress[a:module], [a:tags_file, a:data])
371 endfunction 392 endfunction
372 393
394 " Finds an ongoing job by tags file
373 function! gutentags#find_job_index_by_tags_file(module, tags_file) abort 395 function! gutentags#find_job_index_by_tags_file(module, tags_file) abort
374 let l:idx = -1 396 let l:idx = -1
375 for upd_info in s:update_in_progress[a:module] 397 for upd_info in s:update_in_progress[a:module]
376 let l:idx += 1 398 let l:idx += 1
377 if upd_info[0] == a:tags_file 399 if upd_info[0] == a:tags_file
379 endif 401 endif
380 endfor 402 endfor
381 return -1 403 return -1
382 endfunction 404 endfunction
383 405
406 " Finds an ongoing job by job data
384 function! gutentags#find_job_index_by_data(module, data) abort 407 function! gutentags#find_job_index_by_data(module, data) abort
385 let l:idx = -1 408 let l:idx = -1
386 for upd_info in s:update_in_progress[a:module] 409 for upd_info in s:update_in_progress[a:module]
387 let l:idx += 1 410 let l:idx += 1
388 if upd_info[1] == a:data 411 if upd_info[1] == a:data
390 endif 413 endif
391 endfor 414 endfor
392 return -1 415 return -1
393 endfunction 416 endfunction
394 417
418 " Gets the tags file of a given job
395 function! gutentags#get_job_tags_file(module, job_idx) abort 419 function! gutentags#get_job_tags_file(module, job_idx) abort
396 return s:update_in_progress[a:module][a:job_idx][0] 420 return s:update_in_progress[a:module][a:job_idx][0]
397 endfunction 421 endfunction
398 422
423 " Gets the job data of the i-th job
399 function! gutentags#get_job_data(module, job_idx) abort 424 function! gutentags#get_job_data(module, job_idx) abort
400 return s:update_in_progress[a:module][a:job_idx][1] 425 return s:update_in_progress[a:module][a:job_idx][1]
401 endfunction 426 endfunction
402 427
428 " Removes the i-th job from the ongoing jobs
403 function! gutentags#remove_job(module, job_idx) abort 429 function! gutentags#remove_job(module, job_idx) abort
404 let l:tags_file = s:update_in_progress[a:module][a:job_idx][0] 430 let [l:tags_file, l:job_data] = s:update_in_progress[a:module][a:job_idx]
405 call remove(s:update_in_progress[a:module], a:job_idx) 431 call remove(s:update_in_progress[a:module], a:job_idx)
406 432
407 " Run the user callback for finished jobs. 433 " Run the user callback for finished jobs.
408 silent doautocmd User GutentagsUpdated 434 silent doautocmd User GutentagsUpdated
409 435
429 \"because originating buffer doesn't exist anymore.") 455 \"because originating buffer doesn't exist anymore.")
430 endif 456 endif
431 else 457 else
432 call gutentags#trace("Finished ".a:module." job.") 458 call gutentags#trace("Finished ".a:module." job.")
433 endif 459 endif
434 endfunction 460
435 461 return [l:tags_file, l:job_data]
462 endfunction
463
464 " Removes the job from the ongoing jobs given its job data
436 function! gutentags#remove_job_by_data(module, data) abort 465 function! gutentags#remove_job_by_data(module, data) abort
437 let l:idx = gutentags#find_job_index_by_data(a:module, a:data) 466 let l:idx = gutentags#find_job_index_by_data(a:module, a:data)
438 call gutentags#remove_job(a:module, l:idx) 467 return gutentags#remove_job(a:module, l:idx)
439 endfunction 468 endfunction
440 469
441 " }}} 470 " }}}
442 471
443 " Tags File Management {{{ 472 " Tags File Management {{{