Skip to content

Commit

Permalink
Merge pull request puremourning#85 from tinmarino/merge_check_connection
Browse files Browse the repository at this point in the history
Check connection before some operation (`next`) to avoid Python errors in vim messages
  • Loading branch information
mergify[bot] authored Jan 15, 2020
2 parents 1277ec6 + 9be0f43 commit cb2e08b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
26 changes: 22 additions & 4 deletions python3/vimspector/debug_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import shlex
import subprocess
import traceback
import functools
import vim

from vimspector import ( breakpoints,
Expand Down Expand Up @@ -252,9 +253,21 @@ def Restart( self ):

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 ):
if self._connection:
self._connection.OnData( data )
self._connection.OnData( data )


def OnServerStderr( self, data ):
Expand All @@ -263,14 +276,15 @@ def OnServerStderr( self, data ):
self._outputView.Print( 'server', data )


@IfConnected
def OnRequestTimeout( self, timer_id ):
if self._connection:
self._connection.OnRequestTimeout( timer_id )
self._connection.OnRequestTimeout( timer_id )

def OnChannelClosed( self ):
# TODO: Not calld
self._connection = None

@IfConnected
def Stop( self ):
self._logger.debug( "Stop debug adapter with no callback" )
self._StopDebugAdapter()
Expand Down Expand Up @@ -302,6 +316,7 @@ def _Reset( self ):
# make sure that we're displaying signs in any still-open buffers
self._breakpoints.UpdateUI()

@IfConnected
def StepOver( self ):
if self._stackTraceView.GetCurrentThreadId() is None:
return
Expand All @@ -313,6 +328,7 @@ def StepOver( self ):
},
} )

@IfConnected
def StepInto( self ):
if self._stackTraceView.GetCurrentThreadId() is None:
return
Expand All @@ -324,6 +340,7 @@ def StepInto( self ):
},
} )

@IfConnected
def StepOut( self ):
if self._stackTraceView.GetCurrentThreadId() is None:
return
Expand All @@ -341,6 +358,7 @@ def Continue( self ):
else:
self.Start()

@IfConnected
def Pause( self ):
self._stackTraceView.Pause()

Expand Down
13 changes: 9 additions & 4 deletions python3/vimspector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,21 @@ def Escape( msg ):
return msg.replace( "'", "''" )


def UserMessage( msg, persist=False ):
def UserMessage( msg, persist=False, error=False):
if persist:
_logger.warning( 'User Msg: ' + msg )
else:
_logger.info( 'User Msg: ' + msg )

vim.command( 'redraw' )
cmd = 'echom' if persist else 'echo'
for line in msg.split( '\n' ):
vim.command( "{0} '{1}'".format( cmd, Escape( line ) ) )
vim.command( 'redraw' )
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' )


Expand Down

0 comments on commit cb2e08b

Please sign in to comment.