2012-02-10 10:26:20 -05:00
|
|
|
if !exists("g:symfony_app_console_path")
|
|
|
|
let g:symfony_app_console_path = "app/console"
|
2012-02-10 10:14:17 -05:00
|
|
|
endif
|
|
|
|
|
2012-02-10 10:26:20 -05:00
|
|
|
if !exists("g:symfony_app_console_caller")
|
|
|
|
let g:symfony_app_console_caller = "php"
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists("g:symfony_enable_shell_mapping")
|
2012-02-16 04:11:34 -05:00
|
|
|
let g:symfony_enable_shell_mapping = 0
|
2012-02-10 10:14:17 -05:00
|
|
|
endif
|
2011-11-15 12:05:06 -05:00
|
|
|
|
|
|
|
fun! CompleteSymfonyContainer(base, res)
|
2016-04-08 07:48:39 -04:00
|
|
|
let shellcmd = g:symfony_app_console_caller. ' '.g:symfony_app_console_path.' debug:container'
|
2011-11-15 12:05:06 -05:00
|
|
|
let output = system(shellcmd)
|
|
|
|
if v:shell_error
|
2016-04-08 07:48:39 -04:00
|
|
|
echo output
|
2011-11-15 12:05:06 -05:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
for m in split(output, "\n")
|
|
|
|
let row = split(m)
|
2016-04-08 07:48:39 -04:00
|
|
|
if len(row) == 2
|
|
|
|
let [service, class] = row
|
2011-11-15 12:05:06 -05:00
|
|
|
if service =~ '^' . a:base
|
2016-04-08 07:48:39 -04:00
|
|
|
let menu = 'class: '. class
|
2011-11-15 12:05:06 -05:00
|
|
|
call add(a:res, { 'word': service, 'menu': menu })
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfun
|
|
|
|
|
|
|
|
fun! CompleteSymfonyRouter(base, res)
|
2016-04-08 07:48:39 -04:00
|
|
|
let shellcmd = g:symfony_app_console_caller. ' '.g:symfony_app_console_path.' debug:router'
|
2011-11-15 12:05:06 -05:00
|
|
|
let output = system(shellcmd)
|
|
|
|
if v:shell_error
|
2016-04-08 07:48:39 -04:00
|
|
|
echo output
|
2011-11-15 12:05:06 -05:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
for m in split(output, "\n")
|
|
|
|
let row = split(m)
|
2013-12-24 09:46:21 -05:00
|
|
|
if len(row) == 5
|
|
|
|
let [route, method, scheme, host, url] = row
|
2011-11-15 12:05:06 -05:00
|
|
|
if route =~ '^' . a:base
|
2013-12-24 09:46:21 -05:00
|
|
|
let menu = method.' '.scheme.' '.host.' '.url
|
2011-11-15 12:05:06 -05:00
|
|
|
call add(a:res, { 'word': route, 'menu': menu })
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfun
|
|
|
|
|
|
|
|
fun! CompleteSymfony(findstart, base)
|
|
|
|
if a:findstart
|
|
|
|
" locate the start of the word
|
|
|
|
let line = getline('.')
|
|
|
|
let start = col('.') - 1
|
|
|
|
while start > 0 && line[start - 1] =~ '[a-zA-Z_\-.]'
|
|
|
|
let start -= 1
|
|
|
|
endwhile
|
|
|
|
return start
|
|
|
|
else
|
|
|
|
" find symfony services id / routes matching with "a:base"
|
|
|
|
let res = []
|
|
|
|
call CompleteSymfonyContainer(a:base, res)
|
|
|
|
call CompleteSymfonyRouter(a:base, res)
|
|
|
|
|
|
|
|
return res
|
|
|
|
endfun
|
2012-02-09 15:04:14 -05:00
|
|
|
|
2012-02-16 04:26:35 -05:00
|
|
|
" activate completefunc only in twig, php, xml and yaml buffers
|
|
|
|
let oldcompletefunc = &completefunc
|
|
|
|
|
|
|
|
au BufEnter *.twig setlocal completefunc=CompleteSymfony
|
|
|
|
au BufEnter *.php setlocal completefunc=CompleteSymfony
|
|
|
|
au BufEnter *.yml setlocal completefunc=CompleteSymfony
|
|
|
|
au BufEnter *.xml setlocal completefunc=CompleteSymfony
|
|
|
|
|
|
|
|
" once leaved these buffers, switch back to the old completefunc, if any
|
|
|
|
au BufLeave *.twig setlocal completefunc=oldcompletefunc
|
|
|
|
au BufLeave *.php setlocal completefunc=oldcompletefunc
|
|
|
|
au BufLeave *.yml setlocal completefunc=oldcompletefunc
|
|
|
|
au BufLeave *.xml setlocal completefunc=oldcompletefunc
|
2012-02-10 10:14:17 -05:00
|
|
|
|
2012-02-16 04:26:35 -05:00
|
|
|
|
|
|
|
" Open console
|
2012-02-10 10:26:20 -05:00
|
|
|
let g:symfony_enable_shell_cmd = g:symfony_app_console_caller." ".g:symfony_app_console_path." -s"
|
|
|
|
|
|
|
|
if(g:symfony_enable_shell_mapping == 1)
|
2012-02-10 10:58:31 -05:00
|
|
|
map <C-F> :execute ":!"g:symfony_enable_shell_cmd<CR>
|
2012-02-10 10:26:20 -05:00
|
|
|
endif
|