Vim for php frameworks
Asked Answered
D

3

8

I've already spent two days trying to make a good work environment with VIM for a framework, in this case, laravel.

All is perfect as always, but there is a very important issue:

  • I can't get omnicomplete properly working

I've tried all that I found via google:

-phpcomplete: despite in other of my projects works well, it seems that gets mad with composer. Doesn't recognize facades nor common methods for the framework.

-ctags: helps with some methods, but still a mess with omnicompletion.

-phpcomplete-extended and phpcomplete-extended for laravel: author doesn't maintain this plugin anymore (logical since frameworks change so quick) so does not work anymore.

-PIV, uses standart phpcomplete, so same issue.

-padawan.php I couldn't get it to work, IMHO poorly documented

Is there any vim user who could manage to get omnicompletion functionality properly? I'm starting to think I should move from vim since it's not ready for these new technologies :'(

enter image description here

Grep AppServiceProvider against tags file:

AppServiceProvider app/Providers/AppServiceProvider.php /^class AppServiceProvider extends ServiceProvider$/;" c namespace:Furbook\Providers Furbook\Providers app/Providers/AppServiceProvider.php /^namespace Furbook\Providers;$/;" n boot app/Providers/AppServiceProvider.php /^ public function boot()$/;" f class:Furbook\Providers::AppServiceProvider register app/Providers/AppServiceProvider.php /^ public function register()$/;" f class:Furbook\Providers::AppServiceProvider

Delve answered 29/10, 2015 at 10:43 Comment(3)
There are reports that ctags works OK stackoverflow.com/a/9864307 Could you expand on why it's not working for you?Decapod
It gives me a long list of methods (from another classes) and curiously the ones I need are not listed, a mess. Also, doesn't autocomplete classes. If anyone has tried, will understand what I'm sayingDelve
trying the example you gave, It happens exactly what OP comments, a long list of methods.Delve
D
6

This has been one of my top concerns, here are my preferred options:

  1. Phpactor. My current choice, works pretty well and it's main dev is really active. Fast and has A LOT of refactoring tools. Great for composer projects.

  2. ctags I use phpcomplete and ctags (patched for php), but still no autocompletion for facades, I resolved this with the Laravel 5 IDE Helper Generator. The idea is to generate a _ide_helper.php file with classes and methods for facades first, and then create the tags.

I also created a function in my vimrc, so I can automatically generate the tags.

function! GenTags()
    if isdirectory("./vendor")
    echo '(re)Generating framework tags'
    execute "!php artisan ide-helper:generate"
    echo '(re)Generating tags'
    execute "!ctags -R --filter-terminator=php"
    else
    echo 'Not in a framework project'
    if filereadable("tags")
    echo "Regenerating tags..."
    execute "!ctags -R --filter-terminator=php"
    else
    let choice = confirm("Create tags?", "&Yes\n&No", 2)
    if choice == 1
    echo "Generating tags..."
    execute "!ctags -R --filter-terminator=php"
    endif
    endif
    endif

    :endfunction

    command! -nargs=* GenTags call GenTags()
GenTags()
  1. eclim

-- install eclipse, don't use eclipse installer, better untar directly

-- install eclim, use the eclim installer.

-- For complete code completion change your models to extend Eloquentinstead of Model

-- and the plugin YouCompleteMe (you can try any other)

  1. PHP Language Server It's better and more automated than ctags.

Despite autocompletion is still a bit worse than eclipse (eclim), the Php Language server is developed on PHP, which means a lot of PHP users can contribute to the project and it's pretty active and improving.

Plug 'roxma/nvim-completion-manager'

" (optional) javascript

Plug 'roxma/nvim-cm-tern', {'do': 'npm install'} "

"(optional) language server protocol framework

Plug 'autozimu/LanguageClient-neovim', { 'do': ':UpdateRemotePlugins' } "

"(optional) php completion via LanguageClient-neovim

Plug 'roxma/LanguageServer-php-neovim', {'do': 'composer install && composer run-script parse-stubs'}

If anyone wants to know more can check my vimrc at github

Delve answered 1/11, 2015 at 12:30 Comment(2)
Hi, can you provide video How did you implement it, because I tried to install eclim but it seems not work, it no complete anything.Dottydoty
Have you followed the project's Readme? Once installed you have to launch the daemon executing !~/eclipse/eclimd (or wherever is yours). BTW, I'll try to improve that Readme, but I can't tell you when :/Delve
T
2

Talking about padawan.php that's true about documentation, I haven't spent enough time to make it more or less useful, but installation of padawan shouldn't be that hard:

  1. Install padawan.php via composer global require mkusher/padawan
  2. Configure your $PATH
  3. Install padawan.vim
  4. Generate index for your project

I'm not sure whether Laravel projects will work out of the box or you still will need ide helper, but general php things should work well.

Turnedon answered 18/5, 2016 at 9:59 Comment(1)
I'm currently happy with my set up, but it's good to know. I may give it another try some day. ThanksDelve
D
1

Disclaimer: I am not a PHP programmer and I know nothing about PHP.

First of all, if an auto-completion mechanism is essential for your work, then you should probably choose a proper IDE for the programming language you're working with. Vim includes a framework for auto-completion, which does not mean that it is implemented for all supported languages. And even if there is an omni-completion function available you mileage may vary, depending on how well developed it is.

From what I can gather in other questions (in particular Vim PHP omni completion), the best PGP completion plugin is phpcomplete, so I've installed it.

I then downloaded laraval from here and ran ctags 5.9~svn20110310 (available in Debian Jessie) using the following command:

ctags -R --filter-terminator=php

Using the following test file:

<?php
  $example = new AppServiceProvider();
  $example->
?>

when I press i_ctrl-x_ctrl-o I get the following suggestions:

boot(     f )
register( f )

As it can be seen, there is no long list of methods.

I've also tried to use Universal Ctags that includes the patches required by phpcomplete plugin, but in order to make it work I had to use the following syntax:

ctags -R --fields=+aimS-s --filter-terminator=php .

That is, the extra -s was required. Maybe you can work from here and test this in more detail in your environment.

Decapod answered 30/10, 2015 at 11:56 Comment(9)
I've tried your example regenerating the tags as you suggested: first, I couldn't autocomplet the class once I wrote AppS.. and then, I saw a huge list of methods when $example->. I'll play with it more getting a fresh install of all you said whenever I can (this afternoon or tomorrow). BTW thank youDelve
Look at the bottom left corner of your screen when the list of completions appears. It should tell you the type of completion. I'm almost sure it says keyword completion and not omni completion.Decapod
unfortunately no, check the imgDelve
also, it's obvious phpcomplete is trying some kind of "smart" completion, as you can see, all the suggestions are f (methods or functions)Delve
Share the grep output of that class name against the tags file please.Decapod
It is possible that there's a bug in phpcomplete. So it may be a good idea that you re-post this information as an issue at github.com/shawncplus/phpcomplete.vim/issues ?Decapod
but it's working well for you, isn't it? Maybe in my case it's because it's interfering with some other plugin installed. How can I know that the one that triggers the omnicompletion is in fact phpcomplete?Delve
Also don't know that, sorry! :( You can always temporarily remove all plugins and configurations and test phpcomplete alone.Decapod
what a mess :( I'll check it tomorrow and let you know. Thanks for your time mateDelve

© 2022 - 2024 — McMap. All rights reserved.