Skip to content

Commit fc70428

Browse files
committed
Add nvim-completion-manager sources
Adds completion sources for view and route names. If you have nvim-completion-manager installed, these sources will be registered automatically. In a buffer belonging to a Laravel project, typing e.g. view('| or route('| will offer completion candidates based on the app's views and routes.
1 parent 062a62a commit fc70428

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,20 @@ Vim support for [Laravel/Lumen 5+][laravel] projects. [![Release][release]](http
4444
| `:Eview` | Blade templates |
4545

4646
* Enhanced `gf` command works on class names, template names, config and translation keys.
47+
* Complete view/route names in insert mode.
4748
* Use `:Console` to fire up a REPL (`artisan tinker`).
4849

4950
## Installation
5051

5152
Laravel.vim has optional dependencies on [composer.vim][vim-composer],
52-
[dispatch.vim][dispatch] (the `:Console` command), and
53-
[projectionist.vim][projectionist] (navigation commands):
53+
[dispatch.vim][dispatch] (the `:Console` command),
54+
[projectionist.vim][projectionist] (navigation commands), and
55+
[nvim-completion-manager][ncm] (insert-mode completion):
5456

55-
Plug 'tpope/vim-dispatch'
56-
Plug 'tpope/vim-projectionist'
57-
Plug 'noahfrederick/vim-composer'
57+
Plug 'tpope/vim-dispatch' "| Optional
58+
Plug 'tpope/vim-projectionist' "|
59+
Plug 'roxma/nvim-completion-manager' "|
60+
Plug 'noahfrederick/vim-composer' "|
5861
Plug 'noahfrederick/vim-laravel'
5962

6063
## Credits and License
@@ -67,4 +70,5 @@ See `:help license`.
6770
[vim-composer]: https://github.com/noahfrederick/vim-composer
6871
[projectionist]: https://github.com/tpope/vim-projectionist
6972
[dispatch]: https://github.com/tpope/vim-dispatch
73+
[ncm]: https://github.com/roxma/nvim-completion-manager
7074
[rails]: https://github.com/tpope/vim-rails

autoload/laravel/completion.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
" autoload/laravel/completion.vim - Completion sources
2+
" Maintainer: Noah Frederick
3+
4+
function! laravel#completion#cm_routes(opt, ctx) abort
5+
if exists('b:laravel_root')
6+
call s:cm_complete(laravel#app().routes(), a:opt, a:ctx)
7+
endif
8+
endfunction
9+
10+
function! laravel#completion#cm_views(opt, ctx) abort
11+
if exists('b:laravel_root')
12+
call s:cm_complete(laravel#app().templates(), a:opt, a:ctx)
13+
endif
14+
endfunction
15+
16+
function! s:cm_complete(candidates, opt, ctx) abort
17+
let matches = map(keys(a:candidates), '{"word": v:val, "info": a:candidates[v:val]}')
18+
call cm#complete(a:opt, a:ctx, a:ctx['startcol'], matches)
19+
endfunction
20+
21+
" vim: fdm=marker:sw=2:sts=2:et

plugin/laravel.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,32 @@ augroup laravel_projections
9393
\ endif
9494
augroup END
9595

96+
" }}}
97+
" Completion {{{
98+
99+
augroup laravel_completion
100+
autocmd!
101+
" Set up nvim-completion-manager sources
102+
" :help NCM-source-examples
103+
autocmd User CmSetup call cm#register_source({'name' : 'Laravel Route',
104+
\ 'abbreviation': 'Route',
105+
\ 'priority': 9,
106+
\ 'scoping': 1,
107+
\ 'scopes': ['php', 'blade'],
108+
\ 'word_pattern': '[A-Za-z0-9_.:-]+',
109+
\ 'cm_refresh_patterns': ['\broute\([''"]'],
110+
\ 'cm_refresh': 'laravel#completion#cm_routes',
111+
\ })
112+
autocmd User CmSetup call cm#register_source({'name' : 'Laravel View',
113+
\ 'abbreviation': 'View',
114+
\ 'priority': 9,
115+
\ 'scoping': 1,
116+
\ 'scopes': ['php', 'blade'],
117+
\ 'word_pattern': '[A-Za-z0-9_.:-]+',
118+
\ 'cm_refresh_patterns': ['\bview\([''"]', '@(component|extends|include)\([''"]'],
119+
\ 'cm_refresh': 'laravel#completion#cm_views',
120+
\ })
121+
augroup END
122+
96123
" }}}
97124
" vim: fdm=marker:sw=2:sts=2:et

0 commit comments

Comments
 (0)