Skip to content

Commit ee5a8ff

Browse files
committed
initial commit
0 parents  commit ee5a8ff

30 files changed

Lines changed: 7183 additions & 0 deletions

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.vim text eol=lf
2+
*.php text eol=lf
3+
*.txt text eol=lf
4+
*.md text eol=lf
5+
bin/core_index binary

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tests/
2+
phpcompletePSR.rar

LICENSE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Permission is hereby granted, free of charge, to any person obtaining
2+
a copy of this software and associated documentation files (the
3+
"Software"), to deal in the Software without restriction, including
4+
without limitation the rights to use, copy, modify, merge, publish,
5+
distribute, sublicense, and/or sell copies of the Software, and to
6+
permit persons to whom the Software is furnished to do so, subject to
7+
the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included
10+
in all copies or substantial portions of the Software.
11+
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
13+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
16+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
17+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
phpcomplete-extended
2+
====================
3+
4+
phpcomplete-extended is a fast, extensible, context aware autocomplete plugin
5+
for PHP composer projects. Initially it reads autoload classmap of a composer
6+
project, parses doc-comments of each class and creates index from them. After
7+
that it auto updates index as you type thanks to
8+
[vimproc.vim](https://github.com/Shougo/vimproc.vim) plugin. Besides
9+
autocomplete this plugin have several code inspection features,
10+
11+
* Includes full core PHP documentation
12+
* See documentation of current word, be it class name, method or property. It is
13+
context aware.
14+
* Go to definition of a symbol. Also context aware.
15+
* Automatically add use statement of current completed word. Also added plugin
16+
command of this action.
17+
* If (Unite) plugin installed following sources are available,
18+
* `phpcomplete/files` : Lists PHP files of the project.
19+
* `phpcomplete/vendors` : Lists vendor directories
20+
* `phpcomplete/extends` : Lists classes that extends the class guessed from
21+
the current cursor word.
22+
* `phpcomplete/implements` : Lists classes that implements the class guessed
23+
from the current cursor word.
24+
25+
Installation
26+
-------------
27+
28+
The plugin depends on following plugins,
29+
30+
* [vimproc.vim](https://github.com/Shougo/vimproc.vim) : Asynchronous library for vim. Required for auto-update index. C
31+
compiler is needed to build the plugiin. For windows install cygwin or
32+
msys to get the compiler.
33+
* [unite.vim](https://github.com/Shougo/unite.vim/): Optional, but enables some good features.
34+
35+
Plugin managers are recommended for installing these plugins. Installation instructions for
36+
various plugin managers are given bellow.
37+
38+
## Pathogen
39+
40+
Issue following commands.
41+
42+
```sh
43+
git clone https://github.com/Shougo/vimproc.vim.git ~/.vim/bundle
44+
cd ~/.vim/bundle/vimproc.vim
45+
make
46+
cd ..
47+
git clone https://github.com/Shougo/unite.vim.git ~/.vim/bundle
48+
git clone https://github.com/m2mdas/phpcomplete-extended.git ~/.vim/bundle
49+
```
50+
51+
## NeoBundle (prefered)
52+
Put these lines in `.vimrc` and issue `source %` command
53+
54+
```vim
55+
NeoBundle 'Shougo/vimproc', {
56+
\ 'build' : {
57+
\ 'windows' : 'make -f make_mingw32.mak',
58+
\ 'cygwin' : 'make -f make_cygwin.mak',
59+
\ 'mac' : 'make -f make_mac.mak',
60+
\ 'unix' : 'make -f make_unix.mak',
61+
\ },
62+
\ }
63+
NeoBundle 'Shougo/unite.vim'
64+
NeoBundle 'm2mdas/phpcomplete-extended'
65+
"your other plugins
66+
NeoBundleCheck
67+
```
68+
69+
If C compiler found for respective environment, `neobundle` will automatically
70+
compile the library.
71+
72+
## Vundle
73+
74+
Put following lines in `.vimrc` and issue `:BundleInstall` command.
75+
```vim
76+
Bundle 'Shougo/vimproc'
77+
Bundle 'Shougo/unite.vim'
78+
Bundle 'm2mdas/phpcomplete-extended'
79+
"your other plugins
80+
"....
81+
```
82+
83+
After installation goto `vimproc` folder and issue `make` command from command
84+
line. C compiler must be installed.
85+
86+
Walk through of the plugin
87+
-------------------------
88+
89+
To enable omni complete add following line to `.vimrc`,
90+
91+
autocmd FileType php setlocal omnifunc=phpcomplete_extended#CompletePHP
92+
93+
Then issuing `<C-X><C-O>` in insert mode will open the completion pop-up menu.
94+
95+
This plugin is tested in Windows and Linux. It should work in OSX also.
96+
97+
For now this plugin supports [Composer](http://getcomposer.org/) PHP projects.
98+
Upon detecting a composer project the plugin scans classmap generated by `php
99+
composer.phar dumpautoload --optimize` command. By default composer command is
100+
set to `php composer.phar`. The command can be changed by setting
101+
`g:phpcomplete_index_composer_command` global variable.
102+
103+
The plugin is dependent on `@var`, `@param`, `@return` doc-comments to give proper context aware
104+
autocomplete. So documenting your class will help tremendously. It does not
105+
analyse full class. Just parses the variable declaration to get the relevant
106+
tokens. Does not provide autocomplete suggestion if there is error in code.
107+
108+
Indexing may take some time depending on project size. To decrease index creation time I
109+
would recommend disabling xdebug extension in cli. To do that go to the location
110+
where `php.ini` resides and copy the `php.ini` file as `php-cli.ini` and comment
111+
out the xdebug line. To verify issue `php -m | grep xdebug` in commandline.
112+
113+
For configuration reference see helpdoc.
114+
115+
116+
Auto complete plugin supports
117+
-----------------------------
118+
119+
## [neocomplete](https://github.com/Shougo/neocomplete.vim)
120+
121+
Neocomplete support is built-in and my preferred autocomplete plugin. It needs
122+
vim with lua bindings. To know more about installation refer to the plugin
123+
repository.
124+
125+
## [YouCompleteMe](https://github.com/Valloric/YouCompleteMe)
126+
127+
If `omnifunc` set the omni completer of `YouCompleteMe` should get the completion
128+
candidates. I haven't tested it though.
129+
130+
Extensions
131+
---------
132+
133+
Phpcomplete Extended pluign exposes api hooks so that it can be possible to
134+
provide framework specific autocomplete suggestion. For example facades in
135+
laravel, DIC services in Symfony2 etc. The plugin api divided in two part, `PHP`
136+
and `vim`. PHP part is responsible for creating index related to the framework,
137+
and vim part is responsible for providing autocomplete menu entries based on the
138+
index. For reference see
139+
[phpcomplete-extended-symfony](https://github.com/m2mdas/phpcomplete-extended-symfony)
140+
and
141+
[phpcomplete-extended-laravlel](https://github.com/m2mdas/phpcomplete-extended-laravlel) plugins.
142+
143+
License
144+
-------
145+
MIT licensed.
146+
147+
Acknowledgement
148+
---------------
149+
150+
This plugin would not be possible without the works of
151+
[Shougo](https://github.com/Shougo),
152+
[shawncplus](https://github.com/shawncplus/),
153+
[tpope](https://github.com/tpope/), [vim-jp](https://github.com/vim-jp),
154+
[thinca](https://github.com/thinca) and many others.
155+
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"=============================================================================
2+
" AUTHOR: Mun Mun Das <m2mdas at gmail.com>
3+
" FILE: php.vim
4+
" Last Modified: September 10, 2013
5+
" License: MIT license {{{
6+
" Permission is hereby granted, free of charge, to any person obtaining
7+
" a copy of this software and associated documentation files (the
8+
" "Software"), to deal in the Software without restriction, including
9+
" without limitation the rights to use, copy, modify, merge, publish,
10+
" distribute, sublicense, and/or sell copies of the Software, and to
11+
" permit persons to whom the Software is furnished to do so, subject to
12+
" the following conditions:
13+
"
14+
" The above copyright notice and this permission notice shall be included
15+
" in all copies or substantial portions of the Software.
16+
"
17+
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18+
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21+
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22+
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23+
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
" }}}
25+
"=============================================================================
26+
27+
28+
let s:save_cpo = &cpo
29+
set cpo&vim
30+
31+
let s:source = {
32+
\ 'name' : 'php',
33+
\ 'kind' : 'manual',
34+
\ 'mark' : '[P]',
35+
\ 'rank' : 6,
36+
\ 'hooks' : {},
37+
\ 'filetypes' : { 'php' : 1},
38+
\}
39+
40+
let s:List = vital#of('neocomplete').import('Data.List')
41+
42+
function! s:source.get_complete_position(context) "{{{
43+
return s:get_complete_position(a:context)
44+
endfunction "}}}
45+
46+
function! s:source.gather_candidates(context) "{{{
47+
if !phpcomplete_extended#is_phpcomplete_extended_project() || &ft != 'php'
48+
return []
49+
endif
50+
return s:gather_candidates(a:context)
51+
endfunction"}}}
52+
53+
function! s:get_complete_position(context) "{{{
54+
let b:neocomplete_sources = ['php', 'buffer']
55+
return phpcomplete_extended#CompletePHP(1, "")
56+
endfunction "}}}
57+
58+
function! s:gather_candidates(context) "{{{
59+
return phpcomplete_extended#CompletePHP(0, b:completeContext.base)
60+
endfunction "}}}
61+
62+
function! neocomplete#sources#php#define() "{{{
63+
return s:source
64+
endfunction"}}}
65+
66+
function! s:set_neocomplete_sources() "{{{
67+
if !phpcomplete_extended#is_phpcomplete_extended_project() || !g:loaded_neocomplete
68+
return
69+
endif
70+
71+
let avail_sources = keys(neocomplete#available_sources())
72+
if index(avail_sources, "omni") != -1
73+
call remove(avail_sources, index(avail_sources, 'omni'))
74+
endif
75+
76+
let b:neocomplete_sources = avail_sources
77+
endfunction "}}}
78+
79+
augroup neocomplete_php
80+
autocmd!
81+
autocmd BufEnter *.php :call <SID>set_neocomplete_sources()
82+
augroup END
83+
let &cpo = s:save_cpo
84+
unlet s:save_cpo
85+
86+
" vim: foldmethod=marker:expandtab:ts=4:sts=4:tw=78
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
snippet phpcomplete_extended_plugin
2+
<?php
3+
4+
class ${1:plugin_name}
5+
{
6+
7+
/**
8+
*
9+
* @var array
10+
*/
11+
private $index;
12+
13+
public function __construct()
14+
{
15+
$this->index = array();
16+
}
17+
18+
/**
19+
* called to check that this plugin script is valid for current project
20+
*
21+
* @return bool
22+
*/
23+
public function isValidForProject()
24+
{
25+
${2}
26+
//return is_file('projects/unique/file');
27+
}
28+
29+
/**
30+
* This hook is called before indexing started. Bootstraping code of the
31+
* framework goes here
32+
* @parem ClassLoader $loader the composer ClassLoader object
33+
*/
34+
public function init($loader)
35+
{
36+
37+
}
38+
39+
/**
40+
* Called after a class is processed
41+
*
42+
* @param string $fqcn FQCN of the class
43+
* @param string $file file name of the class
44+
* @param array $classData processed class info
45+
*/
46+
public function postProcess($fqcn, $file, $classData)
47+
{
48+
49+
}
50+
51+
/**
52+
* Called after main index is created
53+
*
54+
* @param mixed $fullIndex the main index
55+
* @param object $generatorObject the parant generator object
56+
*/
57+
public function postCreateIndex($fullIndex, $generatorObject)
58+
{
59+
60+
}
61+
62+
/**
63+
* Called after update script initialized
64+
*
65+
* @param mixed $prevIndex the previous index of this plugin
66+
*/
67+
public function preUpdateIndex($prevIndex)
68+
{
69+
70+
}
71+
72+
/**
73+
* Called after update index created
74+
*
75+
* @param mixed $classData class data of processed class
76+
* @param mixed $fullIndex the main index
77+
* @param object $generatorObject the parant generator object
78+
*/
79+
public function postUpdateIndex($classData, $fullIndex, $generatorObject)
80+
{
81+
82+
}
83+
84+
/**
85+
* Returns the plugin index
86+
*
87+
* @return mixed the index created by this plugin script
88+
*/
89+
public function getIndex()
90+
{
91+
return $this->index;
92+
}
93+
}

0 commit comments

Comments
 (0)