Ejemplo n.º 1
0
 def Clear(self):
     with utils.ModifiableScratchBuffer(self._vars.buf):
         utils.ClearBuffer(self._vars.buf)
     with utils.ModifiableScratchBuffer(self._watch.buf):
         utils.ClearBuffer(self._watch.buf)
     self.ClearTooltip()
     self._current_syntax = ''
Ejemplo n.º 2
0
  def Evaluate( self, frame, expression ):
    console = self._buffers[ 'Console' ].buf
    with utils.ModifiableScratchBuffer( console ):
      utils.AppendToBuffer( console, 'Evaluating: ' + expression )

    def print_result( message ):
      with utils.ModifiableScratchBuffer( console ):
        utils.AppendToBuffer( console,
                              'Evaluated: ' + expression )

        result = message[ 'body' ][ 'result' ]
        if result is None:
          result = 'null'

        utils.AppendToBuffer( console, '  Result: ' + result )

    request = {
      'command': 'evaluate',
      'arguments': {
        'expression': expression,
        'context': 'repl',
      }
    }

    if frame:
      request[ 'arguments' ][ 'frameId' ] = frame[ 'id' ]

    self._connection.DoRequest( print_result, request )
Ejemplo n.º 3
0
  def _DrawThreads( self ):
    self._line_to_frame.clear()
    self._line_to_thread.clear()

    if self._current_thread_sign_id:
      signs.UnplaceSign( self._current_thread_sign_id, 'VimspectorStackTrace' )
    else:
      self._current_thread_sign_id = 1

    with utils.ModifiableScratchBuffer( self._buf ):
      with utils.RestoreCursorPosition():
        utils.ClearBuffer( self._buf )

        for thread in self._threads:
          icon = '+' if not thread.IsExpanded() else '-'
          line = utils.AppendToBuffer(
            self._buf,
            f'{icon} Thread {thread.id}: {thread.thread["name"]} '
            f'({thread.State()})' )

          if self._current_thread == thread.id:
            # TODO - Scroll the window such that this line is visible (e.g. at
            # the top)
            signs.PlaceSign( self._current_thread_sign_id,
                             'VimspectorStackTrace',
                             'vimspectorCurrentThread',
                             self._buf.name,
                             line )

          self._line_to_thread[ line ] = thread
          self._DrawStackTrace( thread )
Ejemplo n.º 4
0
 def Clear( self ):
   self._currentFrame = None
   self._currentThread = None
   self._threads = []
   self._sources = {}
   with utils.ModifiableScratchBuffer( self._buf ):
     utils.ClearBuffer( self._buf )
Ejemplo n.º 5
0
        def print_result(message):
            with utils.ModifiableScratchBuffer(console):
                utils.AppendToBuffer(console, 'Evaluated: ' + expression)

                result = message['body']['result']
                if result is None:
                    result = 'null'

                utils.AppendToBuffer(console, '  Result: ' + result)
Ejemplo n.º 6
0
 def _DrawScopes(self):
     # FIXME: The drawing is dumb and draws from scratch every time. This is
     # simple and works and makes sure the line-map is always correct.
     # However it is pretty inefficient.
     self._vars.lines.clear()
     with utils.RestoreCursorPosition():
         with utils.ModifiableScratchBuffer(self._vars.buf):
             utils.ClearBuffer(self._vars.buf)
             for scope in self._scopes:
                 self._DrawScope(0, scope)
Ejemplo n.º 7
0
 def _DrawScopes(self):
     # FIXME: The drawing is dumb and draws from scratch every time. This is
     # simple and works and makes sure the line-map is always correct.
     # However it is really inefficient, and makes it so that expanded results
     # are collapsed on every step.
     self._vars.lines.clear()
     with utils.RestoreCursorPosition():
         with utils.ModifiableScratchBuffer(self._vars.win.buffer):
             utils.ClearBuffer(self._vars.win.buffer)
             for scope in self._scopes:
                 self._DrawScope(0, scope)
Ejemplo n.º 8
0
    def _DrawBalloonEval(self):
        watch = self._variable_eval
        view = self._variable_eval_view

        with utils.RestoreCursorPosition():
            with utils.ModifiableScratchBuffer(view.buf):
                utils.ClearBuffer(view.buf)
                view.syntax = utils.SetSyntax(view.syntax,
                                              self._current_syntax, view.buf)

                self._DrawWatchResult(view, 0, watch, is_short=True)

                vim.eval("vimspector#internal#balloon#ResizeTooltip()")
Ejemplo n.º 9
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.º 10
0
    def OnOutput(self, event):
        category = CategoryToBuffer(event.get('category') or 'output')
        if category not in self._buffers:
            self._CreateBuffer(category)

        buf = self._buffers[category]
        with utils.ModifiableScratchBuffer(buf):
            utils.AppendToBuffer(buf, event['output'].splitlines())

        # Scroll the buffer
        with utils.RestoreCurrentWindow():
            with utils.RestoreCurrentBuffer(self._window):
                self.ShowOutput(category)
                vim.command('normal G')
Ejemplo n.º 11
0
  def Clear( self ):
    self._current_frame = None
    self._current_thread = None
    self._current_syntax = ""
    self._threads.clear()
    self._sources = {}
    self._requesting_threads = StackTraceView.ThreadRequestState.NO
    self._pending_thread_request = None
    if self._next_sign_id:
      signs.UnplaceSign( self._next_sign_id, 'VimspectorStackTrace' )
    self._next_sign_id = 0

    with utils.ModifiableScratchBuffer( self._buf ):
      utils.ClearBuffer( self._buf )
Ejemplo n.º 12
0
 def _DrawWatches(self):
     # FIXME: The drawing is dumb and draws from scratch every time. This is
     # simple and works and makes sure the line-map is always correct.
     # However it is pretty inefficient.
     self._watch.lines.clear()
     with utils.RestoreCursorPosition():
         with utils.ModifiableScratchBuffer(self._watch.buf):
             utils.ClearBuffer(self._watch.buf)
             utils.AppendToBuffer(self._watch.buf, 'Watches: ----')
             for watch in self._watches:
                 line = utils.AppendToBuffer(
                     self._watch.buf,
                     'Expression: ' + watch.expression['expression'])
                 watch.line = line
                 self._DrawWatchResult(2, watch)
Ejemplo n.º 13
0
    def _Print(self, category, text_lines):
        if category not in self._buffers:
            self._CreateBuffer(category)

        buf = self._buffers[category].buf

        with utils.ModifiableScratchBuffer(buf):
            utils.AppendToBuffer(buf, text_lines)

        self._ToggleFlag(category, True)

        # Scroll the buffer
        with utils.RestoreCurrentWindow():
            with utils.RestoreCurrentBuffer(self._window):
                self._ShowOutput(category)
Ejemplo n.º 14
0
 def _DrawWatches( self ):
   # FIXME: The drawing is dumb and draws from scratch every time. This is
   # simple and works and makes sure the line-map is always correct.
   # However it is really inefficient, and makes it so that expanded results
   # are collapsed on every step.
   self._watch.lines.clear()
   with utils.RestoreCursorPosition():
     with utils.ModifiableScratchBuffer( self._watch.win.buffer ):
       utils.ClearBuffer( self._watch.win.buffer )
       utils.AppendToBuffer( self._watch.win.buffer, 'Watches: ----' )
       for watch in self._watches:
         line = utils.AppendToBuffer( self._watch.win.buffer,
                                      'Expression: ' + watch[ 'expression' ] )
         watch[ '_line' ] = line
         self._DrawWatchResult( 2, watch )
Ejemplo n.º 15
0
    def _DrawThreads(self):
        self._line_to_frame.clear()
        self._line_to_thread.clear()

        with utils.ModifiableScratchBuffer(self._buf):
            utils.ClearBuffer(self._buf)

            for thread in self._threads:
                icon = '+' if '_frames' not in thread else '-'

                line = utils.AppendToBuffer(
                    self._buf, '{0} Thread: {1}'.format(icon, thread['name']))

                self._line_to_thread[line] = thread

                self._DrawStackTrace(thread)
Ejemplo n.º 16
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.º 17
0
    def Evaluate(self, frame, expression, return_to_insert=False):
        console = self._buffers['Console'].buf
        with utils.ModifiableScratchBuffer(console):
            utils.AppendToBuffer(console, 'Evaluating: ' + expression)

        def tidy_up(reason, msg):
            if return_to_insert:
                # A and I for some reason disable left and right arrows.
                vim.command('call feedkeys("G$a", "n")')
            else:
                vim.command('call feedkeys("G", "n")')

        def print_result(message):
            with utils.ModifiableScratchBuffer(console):
                utils.AppendToBuffer(console, 'Evaluated: ' + expression)

                result = message['body']['result']
                if result is None:
                    result = 'null'

                utils.AppendToBuffer(console, '  Result: ' + result)

                tidy_up(None, message)

        request = {
            'command': 'evaluate',
            'arguments': {
                'expression': expression,
                'context': 'repl',
            }
        }

        if frame:
            request['arguments']['frameId'] = frame['id']

        self._connection.DoRequest(print_result, request, tidy_up)
Ejemplo n.º 18
0
 def Clear(self):
     with utils.ModifiableScratchBuffer(self._vars.win.buffer):
         utils.ClearBuffer(self._vars.win.buffer)
     with utils.ModifiableScratchBuffer(self._watch.win.buffer):
         utils.ClearBuffer(self._watch.win.buffer)
     self._current_syntax = ''
Ejemplo n.º 19
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 ) ) )