Fix the symbols tree hierarchy by considering the whole scope when adding a 
tag, avoiding choosing the wrong parent when several tags have the same name.  
Until now, to avoid such misbehavior we only used to choose the parent 
candidate that appeared last (line-wise) before the child.  It works in most 
typical situations as generally tag names are fairly unique, and children 
appear right after their parent.

However, there are cases that are trickier and cannot be handled that way.  In 
the following valid C++ snippet, it is impossible to know whether `function` 
should be listed under the namespace `A` or the
class `A` without looking at its full scope:

```C++
namespace A {
    namespace B {
        class A {
            void method() {}
        };
    };
    void function() {}
};
```

And it is a real-world problem for some parsers like the JSON parser that 
generates numeric indices for array elements name, often leading to several 
possibly close duplicates.

Additionally, to prevent trying to set a tag as its own parent, the code 
guarded against accepting a parent if the child had the same name, lading to 
incorrect hierarchy for `method` in cases like this:

```C++
namespace A {
    class A {
        void method() {}
    };
};
```

So to fix this, consider the whole hierarchy of a tag for choosing its parent, 
when that information is available from the parser.

Fixes #1583.
You can view, comment on, or merge this pull request online at:

  https://github.com/geany/geany/pull/1598

-- Commit Summary --

  * Fix the symbols tree hierarchy when several tags have the same name

-- File Changes --

    M HACKING (6)
    M src/symbols.c (78)
    M src/tagmanager/tm_tag.c (41)
    M src/tagmanager/tm_tag.h (2)

-- Patch Links --

https://github.com/geany/geany/pull/1598.patch
https://github.com/geany/geany/pull/1598.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/1598

Reply via email to