Feature: Silent Errors if not connected
This commit is contained in:
parent
1277ec6347
commit
9be0f43a5f
2 changed files with 31 additions and 8 deletions
|
|
@ -20,6 +20,7 @@ import os
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import traceback
|
import traceback
|
||||||
|
import functools
|
||||||
import vim
|
import vim
|
||||||
|
|
||||||
from vimspector import ( breakpoints,
|
from vimspector import ( breakpoints,
|
||||||
|
|
@ -252,9 +253,21 @@ class DebugSession( object ):
|
||||||
|
|
||||||
self._StartWithConfiguration( self._configuration, self._adapter )
|
self._StartWithConfiguration( self._configuration, self._adapter )
|
||||||
|
|
||||||
|
def IfConnected( fct ):
|
||||||
|
"""Decorator, call fct if self._connected else echo warning"""
|
||||||
|
@functools.wraps( fct )
|
||||||
|
def wrapper(self, *args, **kwargs):
|
||||||
|
if not self._connection:
|
||||||
|
utils.UserMessage(
|
||||||
|
'Vimspector not connected, start a debug session first',
|
||||||
|
persist=True, error=True )
|
||||||
|
return
|
||||||
|
return fct(self, *args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
@IfConnected
|
||||||
def OnChannelData( self, data ):
|
def OnChannelData( self, data ):
|
||||||
if self._connection:
|
self._connection.OnData( data )
|
||||||
self._connection.OnData( data )
|
|
||||||
|
|
||||||
|
|
||||||
def OnServerStderr( self, data ):
|
def OnServerStderr( self, data ):
|
||||||
|
|
@ -263,14 +276,15 @@ class DebugSession( object ):
|
||||||
self._outputView.Print( 'server', data )
|
self._outputView.Print( 'server', data )
|
||||||
|
|
||||||
|
|
||||||
|
@IfConnected
|
||||||
def OnRequestTimeout( self, timer_id ):
|
def OnRequestTimeout( self, timer_id ):
|
||||||
if self._connection:
|
self._connection.OnRequestTimeout( timer_id )
|
||||||
self._connection.OnRequestTimeout( timer_id )
|
|
||||||
|
|
||||||
def OnChannelClosed( self ):
|
def OnChannelClosed( self ):
|
||||||
# TODO: Not calld
|
# TODO: Not calld
|
||||||
self._connection = None
|
self._connection = None
|
||||||
|
|
||||||
|
@IfConnected
|
||||||
def Stop( self ):
|
def Stop( self ):
|
||||||
self._logger.debug( "Stop debug adapter with no callback" )
|
self._logger.debug( "Stop debug adapter with no callback" )
|
||||||
self._StopDebugAdapter()
|
self._StopDebugAdapter()
|
||||||
|
|
@ -302,6 +316,7 @@ class DebugSession( object ):
|
||||||
# make sure that we're displaying signs in any still-open buffers
|
# make sure that we're displaying signs in any still-open buffers
|
||||||
self._breakpoints.UpdateUI()
|
self._breakpoints.UpdateUI()
|
||||||
|
|
||||||
|
@IfConnected
|
||||||
def StepOver( self ):
|
def StepOver( self ):
|
||||||
if self._stackTraceView.GetCurrentThreadId() is None:
|
if self._stackTraceView.GetCurrentThreadId() is None:
|
||||||
return
|
return
|
||||||
|
|
@ -313,6 +328,7 @@ class DebugSession( object ):
|
||||||
},
|
},
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
@IfConnected
|
||||||
def StepInto( self ):
|
def StepInto( self ):
|
||||||
if self._stackTraceView.GetCurrentThreadId() is None:
|
if self._stackTraceView.GetCurrentThreadId() is None:
|
||||||
return
|
return
|
||||||
|
|
@ -324,6 +340,7 @@ class DebugSession( object ):
|
||||||
},
|
},
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
@IfConnected
|
||||||
def StepOut( self ):
|
def StepOut( self ):
|
||||||
if self._stackTraceView.GetCurrentThreadId() is None:
|
if self._stackTraceView.GetCurrentThreadId() is None:
|
||||||
return
|
return
|
||||||
|
|
@ -341,6 +358,7 @@ class DebugSession( object ):
|
||||||
else:
|
else:
|
||||||
self.Start()
|
self.Start()
|
||||||
|
|
||||||
|
@IfConnected
|
||||||
def Pause( self ):
|
def Pause( self ):
|
||||||
self._stackTraceView.Pause()
|
self._stackTraceView.Pause()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -228,16 +228,21 @@ def Escape( msg ):
|
||||||
return msg.replace( "'", "''" )
|
return msg.replace( "'", "''" )
|
||||||
|
|
||||||
|
|
||||||
def UserMessage( msg, persist=False ):
|
def UserMessage( msg, persist=False, error=False):
|
||||||
if persist:
|
if persist:
|
||||||
_logger.warning( 'User Msg: ' + msg )
|
_logger.warning( 'User Msg: ' + msg )
|
||||||
else:
|
else:
|
||||||
_logger.info( 'User Msg: ' + msg )
|
_logger.info( 'User Msg: ' + msg )
|
||||||
|
|
||||||
vim.command( 'redraw' )
|
|
||||||
cmd = 'echom' if persist else 'echo'
|
cmd = 'echom' if persist else 'echo'
|
||||||
for line in msg.split( '\n' ):
|
vim.command( 'redraw' )
|
||||||
vim.command( "{0} '{1}'".format( cmd, Escape( line ) ) )
|
try:
|
||||||
|
if error:
|
||||||
|
vim.command("echohl WarningMsg")
|
||||||
|
for line in msg.split( '\n' ):
|
||||||
|
vim.command( "{0} '{1}'".format( cmd, Escape( line ) ) )
|
||||||
|
finally:
|
||||||
|
vim.command('echohl None') if error else None
|
||||||
vim.command( 'redraw' )
|
vim.command( 'redraw' )
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue