fix(termdebug): handle exiting during startup properly (#16790)

s:EndTermDebug should only be called when exiting if the debugger started
without error, otherwise the plugin breaks.

Vim handles this by using job_setoptions to set the on_exit callback to
s:EndTermDebug after startup succeeds. However, Nvim does not have such
functionality; instead; use s:starting to mimic this behaviour.

Also, introduce s:running to fix s:CheckGdbRunning; it did not work correctly
due to the "[Process exited X]" message keeping the job's channel alive (though
the stream is closed). This means nvim_get_chan_info cannot be used to check if
the debugger has exited, as it may still return a non-empty dict.
This commit is contained in:
Sean Dewar 2022-03-20 10:10:01 +00:00 committed by GitHub
parent 75157d2572
commit 315858bf67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -197,7 +197,7 @@ func s:CloseBuffers()
endfunc
func s:CheckGdbRunning()
if nvim_get_chan_info(s:gdb_job_id) == {}
if !s:running
echoerr string(s:GetCommand()[0]) . ' exited unexpectedly'
call s:CloseBuffers()
return ''
@ -280,6 +280,8 @@ func s:StartDebug_term(dict)
call s:CloseBuffers()
return
endif
let s:running = v:true
let s:starting = v:true
let gdb_job_info = nvim_get_chan_info(s:gdb_job_id)
let s:gdbbuf = gdb_job_info['buffer']
let s:gdbwin = win_getid(winnr())
@ -355,6 +357,8 @@ func s:StartDebug_term(dict)
sleep 10m
endwhile
let s:starting = v:false
" Set the filetype, this can be used to add mappings.
set filetype=termdebug
@ -663,6 +667,11 @@ func s:GetAsmAddr(msg)
endfunc
function s:EndTermDebug(job_id, exit_code, event)
let s:running = v:false
if s:starting
return
endif
if exists('#User#TermdebugStopPre')
doauto <nomodeline> User TermdebugStopPre
endif