def set_layout(layout): """ Toggle between debug and default window layouts. """ # Get active window and set reference to active view window = sublime.active_window() previous_active = window.active_view() # Do not set layout when disabled if get_value(S.KEY_DISABLE_LAYOUT): S.RESTORE_LAYOUT = window.get_layout() set_window_value('restore_layout', S.RESTORE_LAYOUT) S.RESTORE_INDEX = H.new_dictionary() set_window_value('restore_index', S.RESTORE_INDEX) return # Show debug layout if layout == 'debug': debug_layout = get_value(S.KEY_DEBUG_LAYOUT, S.LAYOUT_DEBUG) if window.get_layout() != debug_layout: # Save current layout S.RESTORE_LAYOUT = window.get_layout() set_window_value('restore_layout', S.RESTORE_LAYOUT) # Remember view indexes S.RESTORE_INDEX = H.new_dictionary() for view in window.views(): view_id = '%d' % view.id() group, index = window.get_view_index(view) S.RESTORE_INDEX[view_id] = {'group': group, 'index': index} set_window_value('restore_index', S.RESTORE_INDEX) # Set debug layout window.set_layout(S.LAYOUT_NORMAL) window.set_layout(debug_layout) # Show previous (single) layout else: # Get previous layout configuration if S.RESTORE_LAYOUT is None: S.RESTORE_LAYOUT = get_window_value('restore_layout', S.LAYOUT_NORMAL) if S.RESTORE_INDEX is None: S.RESTORE_INDEX = get_window_value('restore_index', {}) # Restore layout window.set_layout(S.LAYOUT_NORMAL) window.set_layout(S.RESTORE_LAYOUT) for view in window.views(): view_id = '%d' % view.id() # Set view indexes if view_id in H.dictionary_keys(S.RESTORE_INDEX): v = S.RESTORE_INDEX[view_id] window.set_view_index(view, v['group'], v['index']) # Restore focus to previous active view if previous_active is not None: window.focus_view(previous_active)
def set_layout(layout): """ Toggle between debug and default window layouts. """ # Get active window and set reference to active view window = sublime.active_window() previous_active = window.active_view() # Do not set layout when disabled if get_value(S.KEY_DISABLE_LAYOUT): S.RESTORE_LAYOUT = window.get_layout() set_window_value('restore_layout', S.RESTORE_LAYOUT) S.RESTORE_INDEX = H.new_dictionary() set_window_value('restore_index', S.RESTORE_INDEX) return # Show debug layout if layout == 'debug': debug_layout = get_value(S.KEY_DEBUG_LAYOUT, S.LAYOUT_DEBUG) if window.get_layout() != debug_layout: # Save current layout S.RESTORE_LAYOUT = window.get_layout() set_window_value('restore_layout', S.RESTORE_LAYOUT) # Remember view indexes S.RESTORE_INDEX = H.new_dictionary() for view in window.views(): view_id = "%d" % view.id() group, index = window.get_view_index(view) S.RESTORE_INDEX[view_id] = { "group": group, "index": index } set_window_value('restore_index', S.RESTORE_INDEX) # Set debug layout window.set_layout(S.LAYOUT_NORMAL) window.set_layout(debug_layout) # Show previous (single) layout else: # Get previous layout configuration if S.RESTORE_LAYOUT is None: S.RESTORE_LAYOUT = get_window_value('restore_layout', S.LAYOUT_NORMAL) if S.RESTORE_INDEX is None: S.RESTORE_INDEX = get_window_value('restore_index', {}) # Restore layout window.set_layout(S.LAYOUT_NORMAL) window.set_layout(S.RESTORE_LAYOUT) for view in window.views(): view_id = "%d" % view.id() # Set view indexes if view_id in H.dictionary_keys(S.RESTORE_INDEX): v = S.RESTORE_INDEX[view_id] window.set_view_index(view, v["group"], v["index"]) # Restore focus to previous active view if not previous_active is None: window.focus_view(previous_active)
def show_context_output(view): """ Show selected variable in an output panel when clicked in context window. Keyword arguments: view -- View reference which holds the context window. """ # Check if there is a debug session and context data if S.SESSION and S.SESSION.connected and S.CONTEXT_DATA: try: # Get selected point in view point = view.sel()[0] # Check if selected point uses variable scope if point.size() == 0 and sublime.score_selector(view.scope_name(point.a), 'variable'): # Find variable in line which contains the point line = view.substr(view.line(point)) pattern = re.compile('^\\s*(\\$.*?)\\s+\\=') match = pattern.match(line) if match: # Get variable details from context data variable_name = match.group(1) variable = get_context_variable(S.CONTEXT_DATA, variable_name) if variable: # Convert details to text output variables = H.new_dictionary() variables[variable_name] = variable data = generate_context_output(variables) # Show context variables and children in output panel window = sublime.active_window() panel = window.get_output_panel('xdebug') panel.run_command("xdebug_view_update", {'data' : data} ) panel.run_command('set_setting', {"setting": 'word_wrap', "value": True}) window.run_command('show_panel', {"panel": 'output.xdebug'}) except: pass
def get_context_values(): """ Get variables in current context. """ if S.SESSION: context = H.new_dictionary() try: # Super global variables if S.get_project_value('super_globals') or S.get_package_value('super_globals'): S.SESSION.send(dbgp.CONTEXT_GET, c=1) response = S.SESSION.read() context.update(get_response_properties(response)) # Local variables S.SESSION.send(dbgp.CONTEXT_GET) response = S.SESSION.read() context.update(get_response_properties(response)) except (socket.error, ProtocolConnectionException): e = sys.exc_info()[1] connection_error("%s" % e) # Store context variables in session S.CONTEXT_DATA = context return generate_context_output(context)
def get_context_values(self): """ Get variables in current context. """ if not is_connected(): return context = H.new_dictionary() try: # Super global variables if get_value(S.KEY_SUPER_GLOBALS): S.SESSION.send(dbgp.CONTEXT_GET, c=dbgp.CONTEXT_ID_SUPERGLOBALS) response = S.SESSION.read() context.update(get_response_properties(response)) # Local variables S.SESSION.send(dbgp.CONTEXT_GET) response = S.SESSION.read() context.update(get_response_properties(response)) except ProtocolConnectionException: e = sys.exc_info()[1] self.timeout(lambda: connection_error('%s' % e)) # Store context variables in session S.CONTEXT_DATA = context return generate_context_output(context)
def get_context_values(self): """ Get variables in current context. """ if not is_connected(): return context = H.new_dictionary() try: # Super global variables if get_value(S.KEY_SUPER_GLOBALS): S.SESSION.send(dbgp.CONTEXT_GET, c=1) response = S.SESSION.read() context.update(get_response_properties(response)) # Local variables S.SESSION.send(dbgp.CONTEXT_GET) response = S.SESSION.read() context.update(get_response_properties(response)) except ProtocolConnectionException: e = sys.exc_info()[1] self.timeout(lambda: connection_error("%s" % e)) # Store context variables in session S.CONTEXT_DATA = context return generate_context_output(context)
def get_context_values(self, thread, stack_level): """ Get variables in current context. """ if not is_connected(): return context = H.new_dictionary() try: # local variables #if get_value(S.KEY_SUPER_GLOBALS): with S.PROTOCOL as protocol: protocol.send("locals") protocol.send(thread) protocol.send(stack_level) response = protocol.read() properties = self.transform_grld_context_response( response, "local") context.update(properties) # upvalues protocol.send("upvalues") protocol.send(thread) protocol.send(stack_level) response = protocol.read() properties = self.transform_grld_context_response( response, "upvalue") context.update(properties) except ProtocolConnectionException as e: self.timeout(lambda: connection_error(e)) # Store context variables in session S.CONTEXT_DATA = context return generate_context_output(context)
def get_context_values(): """ Get variables in current context. """ if S.SESSION: context = H.new_dictionary() try: # Super global variables if S.get_project_value('super_globals') or S.get_package_value( 'super_globals'): S.SESSION.send(dbgp.CONTEXT_GET, c=1) response = S.SESSION.read() context.update(get_response_properties(response)) # Local variables S.SESSION.send(dbgp.CONTEXT_GET) response = S.SESSION.read() context.update(get_response_properties(response)) except (socket.error, ProtocolConnectionException): e = sys.exc_info()[1] connection_error("%s" % e) # Store context variables in session S.CONTEXT_DATA = context return generate_context_output(context)
def set_layout(layout): """ Toggle between debug and default window layouts. """ # Get active window and set reference to active view window = sublime.active_window() previous_active = window.active_view() # Show debug layout if layout == 'debug': if window.get_layout() != S.LAYOUT_DEBUG: # Save current layout S.RESTORE_LAYOUT = window.get_layout() S.set_window_value('restore_layout', S.RESTORE_LAYOUT) # Remember view indexes S.RESTORE_INDEX = H.new_dictionary() for view in window.views(): view_id = "%d" % view.id() group, index = window.get_view_index(view) S.RESTORE_INDEX[view_id] = {"group": group, "index": index} S.set_window_value('restore_index', S.RESTORE_INDEX) # Set debug layout window.set_layout(S.LAYOUT_NORMAL) window.set_layout(S.LAYOUT_DEBUG) # Show previous (single) layout else: # Get previous layout configuration if S.RESTORE_LAYOUT is None: S.RESTORE_LAYOUT = S.get_window_value('restore_layout', S.LAYOUT_NORMAL) if S.RESTORE_INDEX is None: S.RESTORE_INDEX = S.get_window_value('restore_index', {}) # Restore layout window.set_layout(S.LAYOUT_NORMAL) window.set_layout(S.RESTORE_LAYOUT) for view in window.views(): view_id = "%d" % view.id() # Set view indexes if view_id in H.dictionary_keys(S.RESTORE_INDEX): v = S.RESTORE_INDEX[view_id] window.set_view_index(view, v["group"], v["index"]) # Close all debugging related windows if view.name() == TITLE_WINDOW_BREAKPOINT or view.name( ) == TITLE_WINDOW_CONTEXT or view.name( ) == TITLE_WINDOW_STACK or view.name() == TITLE_WINDOW_WATCH: window.focus_view(view) window.run_command('close') window.run_command('hide_panel', {"panel": 'output.xdebug'}) # Restore focus to previous active view if not previous_active is None: window.focus_view(previous_active)
def set_layout(layout): """ Toggle between debug and default window layouts. """ # Get active window and set reference to active view window = sublime.active_window() previous_active = window.active_view() # Show debug layout if layout == 'debug': if window.get_layout() != S.LAYOUT_DEBUG: # Save current layout S.RESTORE_LAYOUT = window.get_layout() S.set_window_value('restore_layout', S.RESTORE_LAYOUT) # Remember view indexes S.RESTORE_INDEX = H.new_dictionary() for view in window.views(): view_id = "%d" % view.id() group, index = window.get_view_index(view) S.RESTORE_INDEX[view_id] = { "group": group, "index": index } S.set_window_value('restore_index', S.RESTORE_INDEX) # Set debug layout window.set_layout(S.LAYOUT_NORMAL) window.set_layout(S.LAYOUT_DEBUG) # Show previous (single) layout else: # Get previous layout configuration if S.RESTORE_LAYOUT is None: S.RESTORE_LAYOUT = S.get_window_value('restore_layout', S.LAYOUT_NORMAL) if S.RESTORE_INDEX is None: S.RESTORE_INDEX = S.get_window_value('restore_index', {}) # Restore layout window.set_layout(S.LAYOUT_NORMAL) window.set_layout(S.RESTORE_LAYOUT) for view in window.views(): view_id = "%d" % view.id() # Set view indexes if view_id in H.dictionary_keys(S.RESTORE_INDEX): v = S.RESTORE_INDEX[view_id] window.set_view_index(view, v["group"], v["index"]) # Close all debugging related windows if view.name() == TITLE_WINDOW_BREAKPOINT or view.name() == TITLE_WINDOW_CONTEXT or view.name() == TITLE_WINDOW_STACK or view.name() == TITLE_WINDOW_WATCH: window.focus_view(view) window.run_command('close') window.run_command('hide_panel', {"panel": 'output.xdebug'}) # Restore focus to previous active view if not previous_active is None: window.focus_view(previous_active)
def get_response_properties(response, default_key=None): """ Return a dictionary with available properties from response. Keyword arguments: response -- Response from debugger engine. default_key -- Index key to use when property has no name. """ properties = H.new_dictionary() # Walk through elements in response for child in response: # Read property elements if child.tag == dbgp.ELEMENT_PROPERTY or child.tag == dbgp.ELEMENT_PATH_PROPERTY: # Get property attribute values property_name_short = child.get(dbgp.PROPERTY_NAME) property_name = child.get(dbgp.PROPERTY_FULLNAME, property_name_short) property_type = child.get(dbgp.PROPERTY_TYPE) property_children = child.get(dbgp.PROPERTY_CHILDREN) property_numchildren = child.get(dbgp.PROPERTY_NUMCHILDREN) property_classname = child.get(dbgp.PROPERTY_CLASSNAME) property_encoding = child.get(dbgp.PROPERTY_ENCODING) property_value = None # Set property value if child.text: property_value = child.text # Try to decode property value when encoded with base64 if property_encoding is not None and property_encoding == 'base64': try: property_value = H.base64_decode(child.text) except: pass if property_name is not None and len(property_name) > 0: property_key = property_name # Ignore following properties if property_name == "::": continue # Avoid nasty static functions/variables from turning in an infinitive loop if property_name.count("::") > 1: continue # Filter password values if get_value(S.KEY_HIDE_PASSWORD, True) and property_name.lower().find('password') != -1 and property_value is not None: property_value = '******' else: property_key = default_key # Store property if property_key: properties[property_key] = { 'name': property_name, 'type': property_type, 'value': property_value, 'numchildren': property_numchildren, 'children' : None } # Get values for children if property_children: properties[property_key]['children'] = get_response_properties(child, default_key) # Set classname, if available, as type for object if property_classname and property_type == 'object': properties[property_key]['type'] = property_classname # Handle error elements elif child.tag == dbgp.ELEMENT_ERROR or child.tag == dbgp.ELEMENT_PATH_ERROR: message = 'error' for step_child in child: if step_child.tag == dbgp.ELEMENT_MESSAGE or step_child.tag == dbgp.ELEMENT_PATH_MESSAGE and step_child.text: message = step_child.text break if default_key: properties[default_key] = { 'name': None, 'type': message, 'value': None, 'numchildren': None, 'children': None } return properties