Use popup for confirmations (note these have to be async)
This commit is contained in:
parent
48076ba2ef
commit
68edda842a
5 changed files with 129 additions and 33 deletions
|
|
@ -80,6 +80,28 @@ function! vimspector#internal#neopopup#HideSplash( id ) abort
|
||||||
unlet s:db[ a:id ]
|
unlet s:db[ a:id ]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! vimspector#internal#neopopup#Confirm( confirm_id,
|
||||||
|
\ text,
|
||||||
|
\ default_value ) abort
|
||||||
|
let result = confirm( a:text, '&Yes &No &Default', 3 )
|
||||||
|
|
||||||
|
" Map the results to what popup_menu_filter would return (ok s:ConfirmCallback
|
||||||
|
" in popup.vim)
|
||||||
|
if result == 2
|
||||||
|
" No is represented as 0
|
||||||
|
let result = 0
|
||||||
|
elseif result == 0
|
||||||
|
" User pressed ESC/ctrl-c
|
||||||
|
let result = -1
|
||||||
|
elseif result == 3
|
||||||
|
" Default
|
||||||
|
let result = a:default_value
|
||||||
|
endif
|
||||||
|
|
||||||
|
py3 __import__( 'vimspector', fromlist = [ 'utils' ] ).utils.ConfirmCallback(
|
||||||
|
\ int( vim.eval( 'a:confirm_id' ) ),
|
||||||
|
\ int( vim.eval( 'result' ) ) )
|
||||||
|
endfunction
|
||||||
" Boilerplate {{{
|
" Boilerplate {{{
|
||||||
let &cpoptions=s:save_cpo
|
let &cpoptions=s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,37 @@ function! vimspector#internal#popup#HideSplash( id ) abort
|
||||||
call popup_hide( a:id )
|
call popup_hide( a:id )
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:YesNoDefaultFilter( default_value, id, key ) abort
|
||||||
|
if a:key ==# "\<CR>" || a:key ==# 'D' || a:key ==# 'd'
|
||||||
|
call popup_close( a:id, a:default_value )
|
||||||
|
endif
|
||||||
|
|
||||||
|
return popup_filter_yesno( a:id, a:key )
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:ConfirmCallback( confirm_id, id, result ) abort
|
||||||
|
py3 __import__( 'vimspector', fromlist = [ 'utils' ] ).utils.ConfirmCallback(
|
||||||
|
\ int( vim.eval( 'a:confirm_id' ) ),
|
||||||
|
\ int( vim.eval( 'a:result' ) ) )
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! vimspector#internal#popup#Confirm(
|
||||||
|
\ confirm_id,
|
||||||
|
\ text,
|
||||||
|
\ default_value ) abort
|
||||||
|
let text = a:text
|
||||||
|
if type( a:text ) != v:t_list
|
||||||
|
let text = [ a:text ]
|
||||||
|
endif
|
||||||
|
|
||||||
|
call extend( text, [ '', '(Y)es (N)o (D)efault' ] )
|
||||||
|
|
||||||
|
return popup_dialog( text, {
|
||||||
|
\ 'callback': function( 's:ConfirmCallback', [ a:confirm_id ] ),
|
||||||
|
\ 'filter': function( 's:YesNoDefaultFilter', [ a:default_value ] )
|
||||||
|
\ } )
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Boilerplate {{{
|
" Boilerplate {{{
|
||||||
let &cpoptions=s:save_cpo
|
let &cpoptions=s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,15 @@ class JavaDebugAdapter( object ):
|
||||||
return
|
return
|
||||||
|
|
||||||
if body.get( 'changeType' ) == 'BUILD_COMPLETE':
|
if body.get( 'changeType' ) == 'BUILD_COMPLETE':
|
||||||
if utils.AskForInput( 'Code has changed, hot reload? [Y/N] ',
|
def handler( result ):
|
||||||
'Y' ).upper()[ 0 ] == 'Y':
|
if result == 1:
|
||||||
self.debug_session._connection.DoRequest( None, {
|
self.debug_session._connection.DoRequest( None, {
|
||||||
'command': 'redefineClasses',
|
'command': 'redefineClasses',
|
||||||
'arguments': {},
|
'arguments': {},
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
utils.Confirm( self.debug_session._api_prefix,
|
||||||
|
'Code has changed, hot reload?',
|
||||||
|
handler )
|
||||||
elif body.get( 'message' ):
|
elif body.get( 'message' ):
|
||||||
utils.UserMessage( 'Hot code replace: ' + body[ 'message' ] )
|
utils.UserMessage( 'Hot code replace: ' + body[ 'message' ] )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -804,39 +804,52 @@ class DebugSession( object ):
|
||||||
self._logger.info( 'Debug Adapter Started' )
|
self._logger.info( 'Debug Adapter Started' )
|
||||||
|
|
||||||
def _StopDebugAdapter( self, interactive = False, callback = None ):
|
def _StopDebugAdapter( self, interactive = False, callback = None ):
|
||||||
self._splash_screen = utils.DisplaySplash(
|
def disconnect( arguments = {} ):
|
||||||
self._api_prefix,
|
self._splash_screen = utils.DisplaySplash(
|
||||||
self._splash_screen,
|
self._api_prefix,
|
||||||
"Shutting down debug adapter..." )
|
self._splash_screen,
|
||||||
|
"Shutting down debug adapter..." )
|
||||||
|
|
||||||
def handler( *args ):
|
def handler( *args ):
|
||||||
self._splash_screen = utils.HideSplash( self._api_prefix,
|
self._splash_screen = utils.HideSplash( self._api_prefix,
|
||||||
self._splash_screen )
|
self._splash_screen )
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
self._logger.debug( "Setting server exit handler before disconnect" )
|
self._logger.debug( "Setting server exit handler before disconnect" )
|
||||||
assert not self._run_on_server_exit
|
assert not self._run_on_server_exit
|
||||||
self._run_on_server_exit = callback
|
self._run_on_server_exit = callback
|
||||||
|
|
||||||
vim.eval( 'vimspector#internal#{}#StopDebugSession()'.format(
|
vim.eval( 'vimspector#internal#{}#StopDebugSession()'.format(
|
||||||
self._connection_type ) )
|
self._connection_type ) )
|
||||||
|
|
||||||
arguments = {}
|
self._connection.DoRequest( handler, {
|
||||||
if ( interactive and
|
'command': 'disconnect',
|
||||||
self._server_capabilities.get( 'supportTerminateDebuggee' ) ):
|
'arguments': {},
|
||||||
if self._stackTraceView.AnyThreadsRunning():
|
}, failure_handler = handler, timeout = 5000 )
|
||||||
choice = utils.AskForInput( "Terminate debuggee [Y/N/default]? ", "" )
|
|
||||||
if choice == "Y" or choice == "y":
|
if not interactive:
|
||||||
|
disconnect()
|
||||||
|
elif not self._server_capabilities.get( 'supportTerminateDebuggee' ):
|
||||||
|
disconnect()
|
||||||
|
elif not self._stackTraceView.AnyThreadsRunning():
|
||||||
|
disconnect()
|
||||||
|
else:
|
||||||
|
def handle_choice( choice ):
|
||||||
|
arguments = {}
|
||||||
|
if choice == 1:
|
||||||
arguments[ 'terminateDebuggee' ] = True
|
arguments[ 'terminateDebuggee' ] = True
|
||||||
elif choice == "N" or choice == 'n':
|
elif choice == 0:
|
||||||
arguments[ 'terminateDebuggee' ] = False
|
arguments[ 'terminateDebuggee' ] = False
|
||||||
|
elif choice == -1:
|
||||||
|
# Abort
|
||||||
|
return
|
||||||
|
|
||||||
self._connection.DoRequest( handler, {
|
disconnect( arguments )
|
||||||
'command': 'disconnect',
|
|
||||||
'arguments': arguments,
|
|
||||||
}, failure_handler = handler, timeout = 5000 )
|
|
||||||
|
|
||||||
# TODO: Use the 'tarminate' request if supportsTerminateRequest set
|
utils.Confirm( self._api_prefix,
|
||||||
|
"Terminate debuggee?",
|
||||||
|
handle_choice,
|
||||||
|
default_value = 3 )
|
||||||
|
|
||||||
|
|
||||||
def _PrepareAttach( self, adapter_config, launch_config ):
|
def _PrepareAttach( self, adapter_config, launch_config ):
|
||||||
|
|
|
||||||
|
|
@ -375,6 +375,31 @@ def AskForInput( prompt, default_value = None, completion = None ):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
CONFIRM = {}
|
||||||
|
CONFIRM_ID = 0
|
||||||
|
|
||||||
|
def ConfirmCallback( confirm_id, result ):
|
||||||
|
try:
|
||||||
|
handler = CONFIRM.pop( confirm_id )
|
||||||
|
except KeyError:
|
||||||
|
UserMessage( f"Internal error: unexpected callback id { confirm_id }",
|
||||||
|
persist = True,
|
||||||
|
error = True )
|
||||||
|
return
|
||||||
|
|
||||||
|
handler( result )
|
||||||
|
|
||||||
|
|
||||||
|
def Confirm( api_prefix, prompt, handler, default_value = 1 ):
|
||||||
|
global CONFIRM_ID
|
||||||
|
CONFIRM_ID += 1
|
||||||
|
CONFIRM[ CONFIRM_ID ] = handler
|
||||||
|
Call( f'vimspector#internal#{ api_prefix }popup#Confirm',
|
||||||
|
CONFIRM_ID,
|
||||||
|
prompt,
|
||||||
|
default_value )
|
||||||
|
|
||||||
|
|
||||||
def AppendToBuffer( buf, line_or_lines, modified=False ):
|
def AppendToBuffer( buf, line_or_lines, modified=False ):
|
||||||
line = 1
|
line = 1
|
||||||
try:
|
try:
|
||||||
|
|
@ -403,8 +428,10 @@ def AppendToBuffer( buf, line_or_lines, modified=False ):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ClearBuffer( buf ):
|
def ClearBuffer( buf, modified = False ):
|
||||||
buf[ : ] = None
|
buf[ : ] = None
|
||||||
|
if not modified:
|
||||||
|
buf.options[ 'modified' ] = False
|
||||||
|
|
||||||
|
|
||||||
def SetBufferContents( buf, lines, modified=False ):
|
def SetBufferContents( buf, lines, modified=False ):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue