shawncplus/phpcomplete.vim

Jump to definition and omnicomplete not working

Closed this issue · 4 comments

Hey, I'm setting up phpcomplete and having some trouble

When I use jump_to_def, it falls back to the default vim (autoload/phpcomplete.vim:1027)

here's a repo that doesn't work: https://github.com/dkjii-gg/phpcomplete-test
I added the tags file and the .ctags too as I think they're alright

log (I added a bunch of echom):

symbol: test contxt: new testnamespace2\ namespace: testnamespace2
search_namespace: testnamespace2
found namespace: testnamespace2
filename: test2.php
symbol_file: test2.php
tag_line: class test extends \testnamespace\test {
matching /^class test {$/ against class test extends \testnamespace\test {
matching /^class test extends \\testnamespace\\test {$/ against class test extends \testnamespace\test {
matching /^namespace testnamespace;$/ against class test extends \testnamespace\test {
matching /^namespace testnamespace2;$/ against class test extends \testnamespace\test {
matching /^^Ifunction __construct() { echo "a"; }$/ against class test extends \testnamespace\test {
matching /^class test extends \\testnamespace\\test {$/ against class test extends \testnamespace\test {
matching /^class test {$/ against class test extends \testnamespace\test {
matching /^^Ifunction __construct() {$/ against class test extends \testnamespace\test {
tag_pos: -1

I'm not sure how to fix this, as I don't understand why this happens:
echo '/^class test extends \\testnamespace\\test {$/' =~ 'class test extends \testnamespace\test {'
-> gives 0

This fixes the problem, not sure if PR-worthy
fix.patch.txt

Thank you for the extensive investigation and the patch!

Once I get back to my machine and have a moment I'll check it. From the description only, it seems that the way the tags were generated makes them double the \ chards there and we either need to use some flags to make regexp matching literal, or the match pattern needs to be escaped too...

I remember struggling with something like too and had some provisions for it here in the past:
c916d0a#diff-47d2d7f7a9b98dff804b2dc9a197bf0aR1452

Apparently they've since added a new flag to the ctags.io version of ctags named --output-format=e-ctags to make these doubled \\s go away, might worth a try generating your tags with that flag and see if the issue goes away

I forgot to specify I use universal-ctags 0+git20181215-2 and the tagfile is created using the .ctags file in the repo (ctags --options=.ctags), so the --output-format=e-ctags is used

I'm pretty sure the doubled \\ are needed since the first field is a regex

I was confused in my initial bug report, looks like the current phpcomplete interprets the matched text as a regex and searches this text inside the cmd field, whereas the inverse should happen (match the cmd field to the text found)

e.g. this is what happens:
cmd =~ tag_line, whereas it should be:
tag_line =~ cmd[1:-2] (to remove the // around the regex)

Sorry for all the delay. You are absolutely correct here, the cmd =~ line should have been line =~ cmd all along, and the =~ condition doesn't need the / ... / pair around it.
I was trying to figure out how to make an unit test around here, but would couldn't (this part is not tested, surprise-surprise). Need to be extracted this part into a method to make it more manageable.