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
This commit is contained in:
Colomban Wendling 2015-06-10 15:01:24 +02:00
parent 935c389f28
commit d75598cc48
4 changed files with 17 additions and 12 deletions

View File

@ -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);

View File

@ -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 \

View File

@ -0,0 +1,6 @@
class Testclass():
def main(self):
variable = True
if __name__ == "__main__":
module_level_attribute = True

View File

@ -0,0 +1,4 @@
# format=tagmanager
TestclassÌ1Ö0
mainÌ128Í(self)ÎTestclassÖ0
module_level_attributeÌ16384Ö0