Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure ctags to index PHP namespaces and their aliases?

when using PHP namespaces the code I work on uses a large number of namespace aliases, e.g.

<?php
namespace foo;

use bar\baz\qux as bazQux;

...

$a = new bazQux();

Is it possible to configure Exuberant Ctags to index the use of these namespace aliases so that I can jump from a line where the alias is used (the instantiation above) straight to the real class? If that's not possible, what's the best compromise that can be achieved?

I've seen somewhere a not-yet-integrated patch for ctags to use a PHP tokenizer for PHP support instead of the current regex-based implementation; I'd like to continue to use a stock ctags if possible though, rather than having to patch and compile a version myself.

like image 850
Richard Turner Avatar asked Aug 22 '13 07:08

Richard Turner


3 Answers

I don't know well about php but I guess

use bar/baz/qux as bazQux;

should be

use bar\baz\qux as bazQux;

After replacing / with \ Universal-ctags(https://ctags.io) can capture bazQux well:

[jet@localhost]~/var/ctags% cat foo.php
cat foo.php
<?php
namespace foo;

use bar\baz\qux as bazQux;

[jet@localhost]~/var/ctags% ./ctags -o - foo.php
./ctags -o - foo.php
bazQux  foo.php /^use bar\\baz\\qux as bazQux;$/;"  a   namespace:foo   typeref:unknown:bar\\baz\\qux
foo foo.php /^namespace foo;$/;"    n
like image 157
Masatake YAMATO Avatar answered Oct 31 '22 07:10

Masatake YAMATO


For those, who don't wait in limbo, there is solution:

You can try improved PHP omni complete for ViM: https://github.com/shawncplus/phpcomplete.vim.

This project supports also things like "use" keyword and namespaces, but it unfortunately depends on patched version of CTags.

Here are instructions how to prepare ctags version, that support namespaces: https://github.com/shawncplus/phpcomplete.vim/wiki/Patched-ctags

I know it's not a braindead solution, and it requires making your hands dirty with your own compilation of ctags, but it worked for me perfectly :)

like image 27
harijari Avatar answered Oct 31 '22 06:10

harijari


This is the official changelog: http://ctags.sourceforge.net/news.html

They don't seem to merged yet this patch:

http://sourceforge.net/mailarchive/message.php?msg_id=30749245

So I don't think you can find a prebuilt package with php namespace support.

like image 25
Lajos Veres Avatar answered Oct 31 '22 06:10

Lajos Veres