Code Monkey home page Code Monkey logo

phpcomplete-extended's Introduction

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,

  • Includes full core PHP documentation
  • See documentation of current word, be it class name, method or property. It is context aware.
  • Go to definition of a symbol. Also context aware.
  • Automatically add use statement of current completed word. Also added plugin command of this action.
  • If unite.vim plugin installed following sources are available,
    • phpcomplete/files : Lists PHP files of the project.
    • phpcomplete/vendors : Lists vendor directories
    • phpcomplete/extends : Lists classes that extends the class guessed from the current cursor word.
    • phpcomplete/implements : Lists classes that implements the class guessed from the current cursor word.

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,

  • vimproc.vim : Asynchronous library for vim. Required for auto-update index. C compiler is needed to build the plugiin. For windows install cygwin or msys to get the compiler.
  • unite.vim: Optional, but enables some good features.

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 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.

Minimal configuration for supertab support,

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

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.

phpcomplete-extended's People

Contributors

m2mdas avatar pmoust avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.