shawncplus / phpcomplete.vim

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

Unknown function JumpToDefinition #106

Closed FatBoyXPC closed 5 years ago

FatBoyXPC commented 7 years ago

I've generated a new tags file with universal ctags, but when I hit Ctrl+] I get this error: E117: Unknown function: phpcomplete#JumpToDefinition

Not really sure how to troubleshoot this. I'm using the SPF13 VIM distribution, if that could make any difference!

complex857 commented 7 years ago

From the error message, it sounds like you are not using the version from this repo.

From what I could gather the SPF13 version of the phpcomplete plugin is a bit older (5 years). The phpcomplete.vim plugin distributed with vim by default also lacks this function. What would be nice to know how did you get the mapping to this function to. Neither the SPF version or the built-in one should have a key binding on this.

Did you tried to install the plugin from this repository on top of the SPF13 package? Could be that the ftplugin loads from this plugin, while the phpcomplete.vim file is from their PIV package. The way autoloading works in vim is a bit problematic if you have multiple plugins giving you the same filenames. If this is the case, i think you can workaround it by explicitly loading the file in by something like this in you ~/.vimrc:

source ~/.vim/bundle/path/to/phpcomplete.vim/autoload/phpcomplete.vim`

But this kinda defeats the purpose of having it autoloaded. Let me know if you find out what's going on!

FatBoyXPC commented 7 years ago

I'm new-ish to the vim ecosystem, so forgive my ignorance! I didn't realize that this was meant to replace a file that ships VIM itself. I've looked at that SPF13 page quite a few times, I'm not sure why I didn't put it together that phpcomplete.vim was used in both places, my bad! Yes, I tried installing this on top of SPF13. I threw this in the recommended .vimrc.bundles.local.

So I did run that source command in VIM. That took care of the unknown function problem. However, I'm not sure I like the new behavior compared to the old behavior. Maybe I need to configure it properly, though.

So, the first thing I notice is browsing tags with g+]. There's a lot of extra stuff in there now, which seems expected, but it seems to add to the confusion for it to know which thing to choose.

I was hoping this would be a little more "type aware" and take me to the right definition with Ctrl+]. For example. in my laravel project. I'm doing something like UserProfile::getStatuses() but I also have a userProfile() method defined on another object. When I try to go to the UserProfile definition it takes me to the userProfile() method definition. At least with the old ctrl+] mapping it would take me to the corresponding use statement, and that would take me to the UserProfile model.

taoso commented 7 years ago

@FatBoyXPC sorry for disturb, you may try phpcd.vim

FatBoyXPC commented 7 years ago

@lvht Thanks! I tried to give that a shot but ran into some issues that I'll be posting over there!

complex857 commented 7 years ago

@FatBoyXPC, never worry about being new, these details around plugins are cryptic for everyone and on top of that this plugin in general a bit complicated now.

So in general the lay of the land is like this:

  1. There's a phpcomplete.vim file shipping with vim. I maintain that code too, it's almost the same as this plugin except some extra functionality that is not strictly omni-complete related (omni-complete is the thing you trigger with ctrl+xo).
  2. Based on that code about 7 years ago this plugin has been created with better support
  3. The SPF13 and PIV projects picked up that version 5 or so years ago
  4. Later this plugin have been revived and I've started - with a lot of help from others - adding new features.
  5. Few years ago I've started to maintain the vim distributed version of this file too based on the code we have here (as mentioned before by stripping it down a bit).

So what we end up with if you install SPF13 is 3 versions of the plugin, one from vim by default, one with the SPF install and one from directly here. What vim's autoloading system will do when you see a method call like phpcomplete#.... if that method doesn't exists is to try and find a file named phpcomplete.vim in an autoload/ folder somewhere in the directories in the &runtimepath setting.

So at the end you don't have to override anything, you just have to have the files you want to be autoloaded (and other folders detailed in the runtimepath docs) earlier than the built-in one's folder and it will pick it up automatically. In general you don't deal with these stuff by hand nowdays. There are numerous plugin managemenet libraries that manage all these for you, with installing / updating. Projects like (in no particular order):

With these generally just have a list of project's in your .vimrc, you have one command to update all those nicely directly from git and they try to make it so that your vim still loads fast.


As for the quality of completion / jumping: In theory, it will try to detect the class your function was in, however, you'll probably need something called a tags file to have as a database. Please take a look at our getting started guide. I personally never tried to do laravel with it, it might be that the class-detection breaks down with with the way laravel is built unfortunately.

FatBoyXPC commented 7 years ago

Regarding auto complete, whatever I have right now with spf13 is working great. Yes, there are times, where type inference would allow me to get the method name a little bit easier, but that's probably the minority case rather than majority.

The SPF13 stuff - so the idea I guess is that you put your plugins in .vimrc.bundle.local or I could put it in .vimrc.before.local and it would load it properly. I'm using Vundle under the hood (I believe spf13 provides this).

Jumping quality: So I actually do have a tags file generated, that I used universal ctags to generate. With my limited knowledge, I feel like my complaint here would be be about the thing consuming the tags file. I can often hit g+] to look at a list of definitions that match, but that kind of destroys the entire point. If I already knew what file I wanted to be in, I'd ctrlp my way there rather than search a list of matched definitions.

Sydney-o9 commented 6 years ago

For those who have this error and have been trying to remove this plugin which is enabled by default with spf13:

1 Disable the plugin shawncplus/phpcomplete in your ~/.vimrc.bundles.local

UnBundle `shawncplus/phpcomplete`

2 Clean your .vimviews files

rm -rf ~/.vimviews/*

Now you can use ctags as per usual.