shawncplus / phpcomplete.vim

Improved PHP omnicompletion
http://www.vim.org/scripts/script.php?script_id=3171
595 stars 110 forks source link

Namespaces not working, or is it my ctags? #90

Closed bitwombat closed 8 years ago

bitwombat commented 8 years ago

Possibly a duplicate of https://github.com/shawncplus/phpcomplete.vim/issues/84

I have:

class Screenrights extends \Uf\Console\Command\Command {
}

My ctags output is simply:

Command src/Uf/Console/Command/Command.php  /^abstract class Command extends \\deit\\console\\command\\Command {$/;"    c
Command vendor/digitaledgeit/console/src/deit/console/command/Command.php   /^abstract class Command implements CommandInterface, EventListenerInterface {$/;"  c

Same tag (first field), but different files and namespaces. For phpcomplete to jump to the correct one (the first one), should I be getting different output from exuberant ctags?

complex857 commented 8 years ago

By looking at your tags it seems to me that you are using an unmodified release 5.8 ctags (I don't see namespace or other extra fields in your tag lines.

The plugin needs these to be able to differentiate, can you try one of the alternative ctags to generate the tag files (for most of my tests and development i use the one bundled with the plugin)? Let me know if these were generated with one of these and still doesn't work, since this case is supposed to be covered.

bitwombat commented 8 years ago

gb_testcase.zip OK, here's a testcase.

Environment:

Steps to reproduce:

unzip gb_testcase.zip
cd ctags_test
ctags -R --fields=+aimlS --languages=php vendor src
vim src/Uf/Console/Command/Media/Screenrights.php
:set tags=tags
put cursor on line 12, \Uf\Console\Command\Command
press Ctrl-]

Expected: Vim jumps to src/Uf/Console/Command/Command.php Observed: (as above)

put cursor on line 15, \deit\console\command\Command
press Ctrl-]

Expected: Vim jumps to vendor/digitaledgeit/console/src/deit/console/command/Command.php Observed: no movement

This is the relevant line in tags (I think):

Command vendor/digitaledgeit/console/src/deit/console/command/Command.php   /^abstract class Command implements CommandInterface, EventListenerInterface {$/;"  c   namespace:deit\\console\\command  

Looks right to me (?).

:ts shows:

  # pri kind tag               file                                                                                                     
> 1 F C c    Command           ctags_test/src/Uf/Console/Command/Command.php                                                            
               namespace:Uf\\Console\\Command                                                                                           
               abstract class Command extends \\deit\\console\\command\\Command {                                                       
  2 F   c    Command           ctags_test/vendor/digitaledgeit/console/src/deit/console/command/Command.php                             
               namespace:deit\\console\\command                                                                                         
               abstract class Command implements CommandInterface, EventListenerInterface {                    

So that appears to be the problem. "Command" matches two things, and somebody/something isn't taking the name space into account.

complex857 commented 8 years ago

Thank you very much to take the time and prepare this for me. The issue are stemming from the fact that ctags.io generates namespaces in an escaped format, meaning the \ in the input (php source) are written in tags as \\, and when vim reads it back the plugin gets \\ and that screws things up.

There have been an effort to add an option to make this behaviour configurable ctags.io#815 but isn't really yielded end-user visible results.

The good news is that I can more likely safely can fix this in the plugin code for the mean time since having two \ right after each other is not really valid or useful in any of the tag fields, so i can safely (famous last words... please let me know if I'm wrong) can replace them. I've pushed a commit that do just that, to me it seems it fixes your test case (once again, thank you very much for preparing it), please give it a try.

bitwombat commented 8 years ago

Your workaround works! Thanks so much for that. Hero++ ! It seems to be significantly slower (1-2 seconds for a jump). Will let you know if I see any other side-effects.

Thanks again!