From 8e3a8986c41a07598f3c7d556ba6c39af4f40ac1 Mon Sep 17 00:00:00 2001 From: Gareth Parker Date: Fri, 5 Jul 2019 12:26:47 +0100 Subject: [PATCH 1/2] Starting by allowing a max_depth --- python3/vdebug/ui/vimui.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/python3/vdebug/ui/vimui.py b/python3/vdebug/ui/vimui.py index d543ad54..fa370590 100644 --- a/python3/vdebug/ui/vimui.py +++ b/python3/vdebug/ui/vimui.py @@ -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, 0)) + class StatusWindow(Window): @@ -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: @@ -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) @@ -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 @@ -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') From 8268f0c714eb266a68caec263dee98026602e9e2 Mon Sep 17 00:00:00 2001 From: Gareth Parker Date: Fri, 5 Jul 2019 12:29:44 +0100 Subject: [PATCH 2/2] Adding the initial max_depth as a config --- plugin/vdebug.vim | 1 + python3/vdebug/ui/vimui.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/vdebug.vim b/plugin/vdebug.vim index 084e640d..e3f4783f 100644 --- a/plugin/vdebug.vim +++ b/plugin/vdebug.vim @@ -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' : '▾', diff --git a/python3/vdebug/ui/vimui.py b/python3/vdebug/ui/vimui.py index fa370590..52835936 100644 --- a/python3/vdebug/ui/vimui.py +++ b/python3/vdebug/ui/vimui.py @@ -643,7 +643,7 @@ def write(self, msg, return_focus=True): def accept_renderer(self, renderer): self.clean() - self.write(renderer.render(0, 0)) + self.write(renderer.render(0, opts.Options.get('watch_window_initial_max_depth', int))) class StatusWindow(Window):