m2mdas / phpcomplete-extended

A fast, extensible, context aware autocomplete plugin for PHP composer projects with code inspection features.
MIT License
216 stars 23 forks source link

phpcomplete-extended

phpcomplete-extended is a fast, extensible, context aware autocomplete plugin for PHP composer projects. Initially it reads autoload classmap of a composer project, parses doc-comments of each class and creates index from them. After that it auto updates index as you type thanks to vimproc.vim plugin. Besides autocomplete this plugin have several code inspection features,

Demo videos (click on the image to goto youtube)

Autocomplete demo video:

ScreenShot

Unite sources demo video:

ScreenShot

Installation

The plugin depends on following plugins,

Plugin managers are recommended for installing these plugins. Installation instructions for various plugin managers are given bellow.

Pathogen

Issue following commands.

git clone https://github.com/Shougo/vimproc.vim.git ~/.vim/bundle/vimproc.vim
cd ~/.vim/bundle/vimproc.vim
make
cd ..
git clone https://github.com/Shougo/unite.vim.git ~/.vim/bundle/unit.vim
git clone https://github.com/m2mdas/phpcomplete-extended.git ~/.vim/bundle/phpcomplete-extended

NeoBundle (preferred)

Put these lines in .vimrc and issue source % command

NeoBundle 'Shougo/vimproc', {
      \ 'build' : {
      \     'windows' : 'make -f make_mingw32.mak',
      \     'cygwin' : 'make -f make_cygwin.mak',
      \     'mac' : 'make -f make_mac.mak',
      \     'unix' : 'make -f make_unix.mak',
      \    },
     \ }
NeoBundle 'Shougo/unite.vim'
NeoBundle 'm2mdas/phpcomplete-extended'
"your other plugins
NeoBundleCheck

If C compiler found for respective environment, neobundle will automatically compile the library.

Vundle

Put following lines in .vimrc and issue :BundleInstall command.

Bundle 'Shougo/vimproc'
Bundle 'Shougo/unite.vim'
Bundle 'm2mdas/phpcomplete-extended'
"your other plugins
"....

After installation goto vimproc folder and issue make command from command line. C compiler must be installed.

Walk through of the plugin

To enable omni complete add following line to .vimrc,

autocmd  FileType  php setlocal omnifunc=phpcomplete_extended#CompletePHP

Then issuing <C-X><C-O> in insert mode will open the completion pop-up menu.

This plugin is tested in Windows and Linux. It should work in OSX also.

For now this plugin supports Composer PHP projects. Upon detecting a composer project the plugin scans classmap generated by php composer.phar dumpautoload --optimize command. By default composer command is set to php composer.phar. The command can be changed by setting g:phpcomplete_index_composer_command global variable.

The plugin is dependent on @var, @param, @return doc-comments to give proper context aware autocomplete. So documenting your class will help tremendously. It does not analyse full class. Just parses the variable declaration to get the relevant tokens. Does not provide autocomplete suggestion if there is error in code.

Indexing may take some time depending on project size. To decrease index creation time I would recommend disabling xdebug extension in cli. To do that go to the location where php.ini resides and copy the php.ini file as php-cli.ini and comment out the xdebug line. To verify issue php -m | grep xdebug in commandline.

For configuration reference see helpdoc.

Auto complete plugin supports

neocomplete

Neocomplete support is built-in and my preferred autocomplete plugin. It needs vim with lua bindings. To know more about installation refer to the plugin repository.

supertab

Minimal configuration for supertab support,

autocmd  FileType  php setlocal omnifunc=phpcomplete_extended#CompletePHP
let g:SuperTabDefaultCompletionType = "<c-x><c-o>"

YouCompleteMe

If omnifunc set the omni completer of YouCompleteMe should get the completion candidates. I haven't tested it though.

Extensions

Phpcomplete Extended pluign exposes api hooks so that it can be possible to provide framework specific autocomplete suggestion. For example facades in laravel, DIC services in Symfony2 etc. The plugin api divided in two part, PHP and vim. PHP part is responsible for creating index related to the framework, and vim part is responsible for providing autocomplete menu entries based on the index. For reference see phpcomplete-extended-symfony and phpcomplete-extended-laravlel plugins.

License

MIT licensed.

Acknowledgement


This plugin would not be possible without the works of Shougo, shawncplus, tpope, vim-jp, thinca and many others.