Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim for php frameworks

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

like image 423
javier_domenech Avatar asked Oct 29 '15 10:10

javier_domenech


2 Answers

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

like image 185
javier_domenech Avatar answered Oct 13 '22 22:10

javier_domenech


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.

like image 45
Aleh Kashnikau Avatar answered Oct 13 '22 23:10

Aleh Kashnikau