VIM: hack ctags or tweak tagbar for better PHP support
Asked Answered
R

2

2

Recently, i gave up Taglist for Tagbar. Tagbar works as expected for all languages except PHP. It lists class, methods and variables into their respective categories instead of displaying methods and variables into their respective scope.

I came to know that ctags has poor support for PHP.

Is there any way to improve ctags and Tagbar's support for PHP? I am hopping for some kind of hack or tweak, or any other way around.

Ramburt answered 2/7, 2012 at 8:42 Comment(0)
D
5

I have just using PHP_Parser as syntax parsing backend written a tool called phpctags to generate ctags compatiable index file and an addon plugin for tagbar called tagbar-phpctags to enhance the PHP suport for tagbar.

Methods and properties even local variables assigned in functions could be listed in their own scope now as well as their access information.

Maybe these could help.

Dilatant answered 10/7, 2012 at 0:22 Comment(3)
Very nice! I'll add a link to your plugin to the Tagbar wiki.Bani
@Techlive Zheng - m getting phpctags not recognized as internal or external command, i have included it to the system path. Is there any detail guide???Ramburt
@user949293 Any luky? Both phpctags and tagbar-phpctags should be installed.Dilatant
B
2

Unfortunately there is no easy answer to this. The ctags PHP parser just uses regular expressions, and the result -- as you noticed -- is that support for scopes is missing.

There would be two ways to get proper scope support working: someone has to write either an actual recursive parser module for ctags, or some other program that can output tags in a ctags compatible format. That could theoretically even be written in PHP, which might make it easier -- maybe there already is some functionality available that allows access to the AST, which would then just need to be printed out in the correct format. But until someone does that I'm afraid there's no real way to properly display PHP scopes in Tagbar, since it has to rely on the information that ctags hands to it.

Bani answered 4/7, 2012 at 5:22 Comment(1)
Apparently there's nothing built-in that gives you an AST, but there are PHP parsers written in PHP: #5586858Menial

© 2022 - 2024 — McMap. All rights reserved.