diff --git a/tagmanager/ctags/python.c b/tagmanager/ctags/python.c index 16191e64..a0fbba30 100644 --- a/tagmanager/ctags/python.c +++ b/tagmanager/ctags/python.c @@ -463,10 +463,8 @@ static boolean constructParentString(NestingLevels *nls, int indent, return is_class; } -/* Check whether parent's indentation level is higher than the current level and - * if so, remove it. - */ -static void checkParent(NestingLevels *nls, int indent, vString *parent) +/* Check indentation level and truncate nesting levels accordingly */ +static void checkIndent(NestingLevels *nls, int indent) { int i; NestingLevel *n; @@ -474,14 +472,10 @@ static void checkParent(NestingLevels *nls, int indent, vString *parent) for (i = 0; i < nls->n; i++) { n = nls->levels + i; - /* is there a better way to compare two vStrings? */ - if (n && strcmp(vStringValue(parent), vStringValue(n->name)) == 0) + if (n && indent <= n->indentation) { - if (indent <= n->indentation) - { - /* remove this level by clearing its name */ - vStringClear(n->name); - } + /* truncate levels */ + nls->n = i; break; } } @@ -749,7 +743,7 @@ static void findPythonTags (void) continue; } - checkParent(nesting_levels, indent, parent); + checkIndent(nesting_levels, indent); /* Find global and class variables */ variable = findVariable(line); diff --git a/tests/ctags/Makefile.am b/tests/ctags/Makefile.am index f7f5970a..16e4af76 100644 --- a/tests/ctags/Makefile.am +++ b/tests/ctags/Makefile.am @@ -235,6 +235,7 @@ test_sources = \ pure_elem.f95 \ py_constructor_arglist.py \ py-skipped-string.py \ + python-anonymous-nestlevel_ctags-bug-356.py \ qualified_types.f90 \ random.sql \ readlob.sql \ diff --git a/tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py b/tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py new file mode 100644 index 00000000..b85584e2 --- /dev/null +++ b/tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py @@ -0,0 +1,6 @@ +class Testclass(): + def main(self): + variable = True + +if __name__ == "__main__": + module_level_attribute = True diff --git a/tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py.tags b/tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py.tags new file mode 100644 index 00000000..31a1aac2 --- /dev/null +++ b/tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py.tags @@ -0,0 +1,4 @@ +# format=tagmanager +TestclassÌ1Ö0 +mainÌ128Í(self)ÎTestclassÖ0 +module_level_attributeÌ16384Ö0