def _DrawScope( self, indent, scope ): icon = '+' if ( scope[ 'variablesReference' ] > 0 and '_variables' not in scope ) else '-' line = utils.AppendToBuffer( self._vars.win.buffer, '{0}{1} Scope: {2}'.format( ' ' * indent, icon, scope[ 'name' ] ) ) self._vars.lines[ line ] = scope if '_variables' in scope: indent += 2 self._DrawVariables( self._vars, scope[ '_variables' ], indent )
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')
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)
def _DrawVariables( self, view, variables, indent ): for variable in variables: line = utils.AppendToBuffer( view.win.buffer, '{indent}{icon} {name} ({type_}): {value}'.format( indent = ' ' * indent, icon = '+' if ( variable[ 'variablesReference' ] > 0 and '_variables' not in variable ) else '-', name = variable[ 'name' ], type_ = variable.get( 'type', '<unknown type>' ), value = variable.get( 'value', '<unknown value>' ) ).split( '\n' ) ) view.lines[ line ] = variable if '_variables' in variable: self._DrawVariables( view, variable[ '_variables' ], indent + 2 )
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)
def _DrawStackTrace(self, thread): if '_frames' not in thread: return stackFrames = thread['_frames'] for frame in stackFrames: if frame.get('source'): source = frame['source'] else: source = {'name': '<unknown>'} line = utils.AppendToBuffer( self._buf, ' {0}: {1}@{2}:{3}'.format(frame['id'], frame['name'], source['name'], frame['line'])) self._line_to_frame[line] = frame
def _DrawWatchResult( self, indent, watch ): if '_result' not in watch: return result = watch[ '_result' ] icon = '+' if ( result[ 'variablesReference' ] > 0 and '_variables' not in result ) else '-' line = '{0}{1} Result: {2} '.format( ' ' * indent, icon, result[ 'result' ] ) line = utils.AppendToBuffer( self._watch.win.buffer, line.split( '\n' ) ) self._watch.lines[ line ] = result if '_variables' in result: indent = 4 self._DrawVariables( self._watch, result[ '_variables' ], indent )
def _DrawVariables(self, view, variables, indent): assert indent > 0 for variable in variables: line = utils.AppendToBuffer( view.buf, '{indent}{marker}{icon} {name} ({type_}): {value}'.format( # We borrow 1 space of indent to draw the change marker indent=' ' * (indent - 1), marker='*' if variable.changed else ' ', icon='+' if (variable.IsExpandable() and not variable.IsExpanded()) else '-', name=variable.variable['name'], type_=variable.variable.get('type', ''), value=variable.variable.get('value', '<unknown>')).split('\n')) view.lines[line] = variable if variable.ShouldDrawDrillDown(): self._DrawVariables(view, variable.variables, indent + 2)
def Evaluate(self, frame, expression): if not frame: return console = self._buffers['Console'] utils.AppendToBuffer(console, expression) def print_result(message): utils.AppendToBuffer(console, message['body']['result']) self._connection.DoRequest( print_result, { 'command': 'evaluate', 'arguments': { 'expression': expression, 'context': 'repl', 'frameId': frame['id'], } })
def _DrawWatchResult(self, indent, watch): if not watch.result: return assert indent > 0 icon = '+' if (watch.result.IsExpandable() and not watch.result.IsExpanded()) else '-' line = '{indent}{marker}{icon} Result: {result}'.format( # We borrow 1 space of indent to draw the change marker indent=' ' * (indent - 1), marker='*' if watch.result.changed else ' ', icon=icon, result=watch.result.result.get('result', '<unknown>')) line = utils.AppendToBuffer(self._watch.buf, line.split('\n')) self._watch.lines[line] = watch.result if watch.result.ShouldDrawDrillDown(): indent = 4 self._DrawVariables(self._watch, watch.result.variables, indent)
def _DrawVariables(self, view, variables, indent_len, is_short=False): assert indent_len > 0 for variable in variables: text = '' # We borrow 1 space of indent to draw the change marker indent = ' ' * (indent_len - 1) marker = '*' if variable.changed else ' ' icon = '+' if (variable.IsExpandable() and not variable.IsExpanded()) else '-' name = variable.variable.get('name', '') kind = variable.variable.get('type', '') value = variable.variable.get('value', '<unknown>') # FIXME: If 'value' is multi-line, somehow turn it into an expandable item # where the expansion is done "internally", resolving to the multi-line # value if is_short: value = variable.variable.get('value', '<unknown>') text = f'{indent}{icon} {name}: {value}' elif settings.Get('variables_display_mode') == 'compact': value = variable.variable.get('value', '<unknown>').splitlines() if len(value) > 0: value = value[0] else: value = '' text = f'{indent}{marker}{icon} {name}: {value}' else: text = f'{indent}{marker}{icon} {name} ({kind}): {value}' line = utils.AppendToBuffer(view.buf, text.split('\n')) view.lines[line] = variable if variable.ShouldDrawDrillDown(): self._DrawVariables(view, variable.variables, indent_len + 2, is_short)
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)
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)
def _DrawWatchResult(self, view, indent_len, watch, is_short=False): if not watch.result: return assert is_short or indent_len > 0 if is_short: # The first result is always expanded in a hover (short format) icon = '' marker = '' leader = '' else: icon = '+' if (watch.result.IsExpandable() and not watch.result.IsExpanded()) else '-' marker = '*' if watch.result.changed else ' ' leader = ' Result: ' value = watch.result.result.get('result', '<unknown>') # We borrow 1 space of indent to draw the change marker indent = ' ' * (indent_len - 1) if settings.Get('variables_display_mode') == 'compact': value = value.splitlines() if len(value) > 0: value = value[0] else: value = '' line = f'{indent}{marker}{icon}{leader}{value}' line = utils.AppendToBuffer(view.buf, line.split('\n')) view.lines[line] = watch.result if watch.result.ShouldDrawDrillDown(): self._DrawVariables(view, watch.result.variables, indent_len + 2, is_short)
def print_result(message): utils.AppendToBuffer(console, message['body']['result'])