def _extract_def(d, path): d_line, d_column = d.start_pos # use full name for import type if d.type == 'function': try: params = [p.name for p in d.params] name = d.name + '(' + ', '.join(params) + ')' except AttributeError: name = d.name else: name = d.name definition = Definition(name, d_line - 1, d_column, icon_from_typename(d.name, d.type), file_path=path) # check for methods in class or nested methods/classes if d.type == "class" or d.type == 'function': try: sub_definitions = d.defined_names() for sub_d in sub_definitions: if (d.type == 'function' and sub_d.type == 'function') or \ d.type == 'class': definition.add_child(_extract_def(sub_d, path)) except (AttributeError, IndexError): pass return definition
def flatten(results): """ Flattens the document structure tree as a simple sequential list. """ ret_val = [] for de in results: ret_val.append(de) for sub_d in de.children: nd = Definition(sub_d.name, sub_d.line, sub_d.column, sub_d.icon) nd.name = " " + nd.name ret_val.append(nd) return ret_val
def to_definition(self): """ Converts the name instance to a pyqode.core.share.Definition """ icon = { Name.Type.Root: icons.ICON_MIMETYPE, Name.Type.Division: icons.ICON_DIVISION, Name.Type.Section: icons.ICON_SECTION, Name.Type.Variable: icons.ICON_VAR, Name.Type.Paragraph: icons.ICON_FUNC }[self.node_type] d = Definition(self.name, self.line, self.column, icon, self.description) for ch in self.children: d.add_child(ch.to_definition()) return d
def parse(self, path): return [Definition('spam', 1, 15, icon=("", ""))]