From d75598cc4895c0dc68dbd00a5ed819943a31242f Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Wed, 10 Jun 2015 15:01:24 +0200 Subject: [PATCH] python: Fix resetting scope on anonymous blocks The previous fix, coming from [CTags bug #1988026], was incorrect if the parent was not a root-level element, as it checked the level name (unqualified) against the parent name (qualified). However, there is no need to check the level name, all what counts is the indentation level itself: if it's smaller than an existing level, it ends it. This fixes [CTags bug #356]. [CTags bug #1988026]: https://sourceforge.net/p/ctags/bugs/227/ [CTags bug #356]: https://sourceforge.net/p/ctags/bugs/356/ X-Universal-CTags-Commit-ID: ab91e6e1ae84b80870a1e8712fc7f3133e4b5542 --- tagmanager/ctags/python.c | 18 ++++++------------ tests/ctags/Makefile.am | 1 + ...python-anonymous-nestlevel_ctags-bug-356.py | 6 ++++++ ...n-anonymous-nestlevel_ctags-bug-356.py.tags | 4 ++++ 4 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py create mode 100644 tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py.tags 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