Skip to content

Commit 4596929

Browse files
committed
Implement laravel#app().routes()
Returns a Dictionary of the app's named routes in the form { 'route.name': 'GET|POST route/url', ... } which can be used for completion. Also fixes a bug in the 1-argument version of laravel#app().makeprg().
1 parent 38fcde6 commit 4596929

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

autoload/laravel.vim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,24 @@ endfunction
295295
" { 'route.name': 'GET|POST route/url', ... }
296296
function! s:app_routes() abort dict
297297
if self.cache.needs('routes')
298+
let lines = laravel#artisan#capture('route:list')
299+
call filter(lines, 'v:val =~# ''^| ''')
300+
" Remove header line
301+
call remove(lines, 0)
302+
call map(lines, 'substitute(v:val, ''^|\(.*\)|$'', ''\1'', '''')')
303+
call map(lines, 'split(v:val, '' | '', 1)')
304+
" Remove unnamed routes
305+
call filter(lines, 'v:val[3] !~# ''^\s*$''')
306+
298307
let routes = {}
299308

309+
for line in lines
310+
let name = substitute(line[3], '\s\+$', '', '')
311+
let method = substitute(line[1], '\s\+$', '', '')
312+
let uri = substitute(line[2], '\s\+$', '', '')
313+
let routes[name] = method . ' ' . uri
314+
endfor
315+
300316
call self.cache.set('routes', routes)
301317
endif
302318

@@ -348,7 +364,7 @@ call s:add_methods('app', ['facades', 'routes', 'templates'])
348364
function! s:app_makeprg(...) abort dict
349365
if a:0 == 1 && type(a:1) == type([])
350366
let args = a:1
351-
elseif a:0 > 1
367+
elseif a:0 > 0
352368
let args = copy(a:000)
353369
else
354370
let args = []

autoload/laravel/artisan.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ endfunction
3737

3838
""
3939
" Get output from Artisan with {args} in project's root directory.
40-
function! s:artisan_exec(args) abort
40+
function! laravel#artisan#capture(args) abort
4141
try
4242
let cwd = s:cd(laravel#app().path())
4343
let result = systemlist(laravel#app().makeprg(a:args))
@@ -52,7 +52,7 @@ endfunction
5252
" Get Dict of artisan subcommands.
5353
function! s:artisan_commands() abort
5454
if laravel#app().cache.needs('artisan_commands')
55-
let lines = s:artisan_exec(['list', '--raw'])
55+
let lines = laravel#artisan#capture(['list', '--raw'])
5656

5757
if v:shell_error != 0
5858
return []

0 commit comments

Comments
 (0)