Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing a configurable initial max_depth for the Watch Window #411

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugin/vdebug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ let g:vdebug_options_defaults = {
\ 'debug_file' : '',
\ 'path_maps' : {},
\ 'watch_window_style' : 'expanded',
\ 'watch_window_initial_max_depth': 0,
\ 'marker_default' : '⬦',
\ 'marker_closed_tree' : '▸',
\ 'marker_open_tree' : '▾',
Expand Down
28 changes: 15 additions & 13 deletions python3/vdebug/ui/vimui.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ def clear_eval_expression(self):
def write(self, msg, return_focus=True):
Window.write(self, msg, after="normal gg")

def accept_renderer(self, renderer):
self.clean()
self.write(renderer.render(0, opts.Options.get('watch_window_initial_max_depth', int)))


class StatusWindow(Window):

Expand Down Expand Up @@ -777,7 +781,7 @@ def __init__(self, response, title=None, contexts=None, current_context=0):
self.contexts = contexts if contexts is not None else {}
self.current_context = current_context

def render(self, indent=0):
def render(self, indent=0, max_depth=None):
res = self.__create_tabs()

if self.title:
Expand All @@ -787,14 +791,12 @@ def render(self, indent=0):
num_props = len(properties)
log.Log("Writing %i properties to the window" % num_props,
log.Logger.INFO)
for idx, prop in enumerate(properties):
final = False
try:
next_prop = properties[idx+1]
except IndexError:
final = True
next_prop = None
res += self.__render_property(prop, next_prop, final, indent)

depth_applied_properties = list(filter(lambda p: max_depth is None or p.depth <= max_depth, properties))
for idx, prop in enumerate(depth_applied_properties):
final = True if idx + 1 >= len(depth_applied_properties) else False
next_prop = None if final else depth_applied_properties[idx+1]
res += self.__render_property(prop, next_prop, final, indent, max_depth)

log.Log("Writing to window:\n"+res, log.Logger.DEBUG)

Expand All @@ -811,11 +813,11 @@ def __create_tabs(self):
return " ".join(res) + "\n\n"
return ""

def __render_property(self, p, next_p, last=False, indent=0):
def __render_property(self, p, next_p, last=False, indent=0, max_depth=None):
indent_str = "".rjust((p.depth * 2)+indent)
line = "%(indent)s %(marker)s %(name)s = (%(type)s)%(value)s" % {
'indent': indent_str,
'marker': self.__get_marker(p),
'marker': self.__get_marker(p, max_depth),
'name': p.display_name,
'type': p.type_and_size(),
'value': " " + p.value
Expand Down Expand Up @@ -847,10 +849,10 @@ def __render_property(self, p, next_p, last=False, indent=0):
line += "".rjust((depth * 2) - 1 + indent) + " /" + "\n"
return line

def __get_marker(self, property):
def __get_marker(self, property, max_depth=None):
char = opts.Options.get('marker_default')
if property.has_children:
if property.child_count() == 0:
if property.child_count() == 0 or (max_depth is not None and property.depth >= max_depth):
char = opts.Options.get('marker_closed_tree')
else:
char = opts.Options.get('marker_open_tree')
Expand Down