Ejemplo n.º 1
0
      def consume_source( msg ):
        self._sources[ source_reference ] = source

        buf_name = os.path.join( '_vimspector_tmp', source[ 'name' ] )

        self._logger.debug( "Received source %s: %s", buf_name, msg )

        buf = utils.BufferForFile( buf_name )
        utils.SetUpScratchBuffer( buf, buf_name )
        source[ 'path' ] = buf_name
        with utils.ModifiableScratchBuffer( buf ):
          utils.SetBufferContents( buf, msg[ 'body' ][ 'content' ] )

        and_then( self._sources[ source_reference ] )
Ejemplo n.º 2
0
    def ShowMemory(self, memoryReference, length, offset, msg):
        if not self._window.valid:
            return False

        buf_name = os.path.join('_vimspector_mem', memoryReference)
        buf = utils.BufferForFile(buf_name)
        self._scratch_buffers.append(buf)
        utils.SetUpHiddenBuffer(buf, buf_name)
        with utils.ModifiableScratchBuffer(buf):
            # TODO: The data is encoded in base64, so we need to convert that to the
            # equivalent output of say xxd
            data = msg.get('body', {}).get('data', '')
            utils.SetBufferContents(buf, [
                f'Memory Dump for Reference {memoryReference} Length: {length} bytes'
                f' Offset: {offset}',
                '-' * 80,
                'Offset    Bytes                                             Text',
                '-' * 80,
            ])
            utils.AppendToBuffer(buf, utils.Base64ToHexDump(data))

        utils.SetSyntax('', 'vimspector-memory', buf)
        utils.JumpToWindow(self._window)
        utils.OpenFileInCurrentWindow(buf_name)
Ejemplo n.º 3
0
  def _UpdateView( self, breakpoint_list, show=True ):
    if show and not self._HasWindow():
      vim.command( f'botright { settings.Int( "bottombar_height" ) }new' )
      self._win = vim.current.window
      if self._HasBuffer():
        with utils.NoAutocommands():
          vim.current.buffer = self._buffer
      else:
        self._buffer = vim.current.buffer
        mappings = settings.Dict( 'mappings' )[ 'breakpoints' ]
        groups = {
          'toggle': 'ToggleBreakpointViewBreakpoint',
          'toggle_all': 'ToggleAllBreakpointsViewBreakpoint',
          'delete': 'DeleteBreakpointViewBreakpoint',
          'jump_to': 'JumpToBreakpointViewBreakpoint',
          'add_line': 'SetAdvancedLineBreakpoint',
          'add_func': 'AddAdvancedFunctionBreakpoint'
        }
        for key, func in groups.items():
          for mapping in utils.GetVimList( mappings, key ):
            vim.command( f'nnoremap <silent> <buffer> { mapping } '
                         ':<C-u>call '
                         f'vimspector#{ func }()<CR>' )
        utils.SetUpHiddenBuffer( self._buffer,
                                 "vimspector.Breakpoints" )

      utils.UpdateSessionWindows( {
        'breakpoints': utils.WindowID( self._win )
      } )

      # set highlighting
      vim.eval( "matchadd( 'WarningMsg', 'ENABLED', 100 )" )
      vim.eval( "matchadd( 'WarningMsg', 'VERIFIED', 100 )" )
      vim.eval( "matchadd( 'LineNr', 'DISABLED', 100 )" )
      vim.eval( "matchadd( 'LineNr', 'PENDING', 100 )" )
      vim.eval( "matchadd( 'Title', '\\v^\\S+:{0,}', 100 )" )

      if utils.UseWinBar():
        vim.command( 'nnoremenu <silent> 1.1 WinBar.Delete '
                     ':call vimspector#DeleteBreakpointViewBreakpoint()<CR>' )
        vim.command( 'nnoremenu <silent> 1.2 WinBar.Toggle '
                     ':call vimspector#ToggleBreakpointViewBreakpoint()<CR>' )
        vim.command( 'nnoremenu <silent> 1.2 WinBar.*Toggle '
                     ':call'
                       ' vimspector#ToggleAllBreakpointsViewBreakpoint()<CR>' )
        vim.command( 'nnoremenu <silent> 1.3 WinBar.Jump\\ To '
                     ':call vimspector#JumpToBreakpointViewBreakpoint()<CR>' )
        # TODO: Add tests for this function
        vim.command( 'nnoremenu <silent> 1.4 WinBar.+Line '
                     ':call vimspector#SetAdvancedLineBreakpoint()<CR>' )
        vim.command( 'nnoremenu <silent> 1.4 WinBar.+Function '
                     ':call vimspector#AddAdvancedFunctionBreakpoint()<CR>' )
        vim.command( 'nnoremenu <silent> 1.4 WinBar.Clear '
                     ':call vimspector#ClearBreakpoints()<CR>' )
        vim.command( 'nnoremenu <silent> 1.4 WinBar.Save '
                     ':call vimspector#WriteSessionFile()<CR>' )
        vim.command( 'nnoremenu <silent> 1.4 WinBar.Load '
                     ':call vimspector#ReadSessionFile()<CR>' )

      # we want to maintain the height of the window
      self._win.options[ "winfixheight" ] = True

    self._breakpoint_list = breakpoint_list

    def FormatEntry( el ):
      prefix = ''
      if el.get( 'type' ) == 'L':
        prefix = '{}:{} '.format( os.path.basename( el.get( 'filename' ) ),
                                  el.get( 'lnum' ) )

      return '{}{}'.format( prefix, el.get( 'text' ) )

    if self._HasBuffer():
      with utils.ModifiableScratchBuffer( self._buffer ):
        with utils.RestoreCursorPosition():
          utils.SetBufferContents( self._buffer,
                                   list( map( FormatEntry, breakpoint_list ) ) )