preservim / tagbar

Vim plugin that displays tags in a window, ordered by scope
https://preservim.github.io/tagbar
Other
6.13k stars 488 forks source link

Current function not identified if it contains a #define #376

Closed BenoitDuffez closed 4 years ago

BenoitDuffez commented 7 years ago

This simple code can reproduce the issue on 01f57ac5 (vim 7.4, ctags 5.9~svn20110310,):

#define WORKING 1

int main() {
#define NOTWORKING 2

    return 1;
}

Place the cursor on the return statement and open tag bar. It show the current context as in NOTWORKING macro, instead of the main function.

See this example:

Screenshot of problem reproduced live

While if the cursor is above the macro, it's working as expected:

Screenshot of problem not reproduced with caret above the macro

majutsushi commented 7 years ago

This is tricky to solve. With the information that ctags provides Tagbar can't really know that it is "inside" a function, it can only know what the nearest tag above the cursor is. You would also need some kind of precedence between tag types to define which should be preferred in cases like these. I'll think about what the best thing to do here would be.