11

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.

2
  • 1
    It doesn't answer your question (it doesn't help inter-class navigation) but I recently found phpctags, which is very helpful if you also use the vim tagbar plugin: stackoverflow.com/questions/11290352/…
    – Lambart
    Apr 21, 2014 at 19:49
  • @Lambart Thanks for that info; phpctags looks interesting. Apr 22, 2014 at 10:42

3 Answers 3

4
+100

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.

2
  • I suspect you're right, which is a shame. It looks like ctags isn't being actively maintained any longer; the last commit was 11 months ago. It's a shame this PHP parser patch has been waiting in limbo for so long. Oct 30, 2013 at 9:49
  • github.com/fishman/ctags is a fork that has updated the php parser. It may work. Apr 22, 2015 at 17:24
2

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
1
  • 1
    Thanks for catching the syntax error with the namespace separators. Apr 30, 2017 at 8:56
1

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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.