-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlaravel.vim
157 lines (136 loc) · 4.75 KB
/
laravel.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
" plugin/laravel.vim - Detect a Laravel/Lumen project
" Maintainer: Noah Frederick (https://noahfrederick.com)
""
" @section Introduction, intro
" @stylized Laravel.vim
" @plugin(stylized) provides conveniences for working with Laravel/Lumen
" projects. Some features include:
"
" * The |:Artisan| command wraps artisan with intelligent completion.
" * Includes projections for projectionist.vim.
" * Use |:Homestead| to send commands over SSH to your development VM.
" * Use |:Console| to fire up a REPL (artisan tinker).
"
" This plug-in is only available if 'compatible' is not set.
""
" @setting g:laravel_homestead_dir
" The directory where Homestead is installed. Default: >
" '~/Homestead'
" <
""
" @section About, about
" @plugin(stylized) is distributed under the same terms as Vim itself (see
" |license|)
"
" You can find the latest version of this plug-in on GitHub:
" https://github.com/noahfrederick/vim-@plugin(name)
"
" Please report issues on GitHub as well:
" https://github.com/noahfrederick/vim-@plugin(name)/issues
if (exists('g:loaded_laravel') && g:loaded_laravel) || &cp
finish
endif
let g:loaded_laravel = 1
" Detection {{{
""
" Determine whether the current or supplied [path] belongs to a Laravel project
function! s:laravel_detect(...) abort
if exists('b:laravel_root')
return 1
endif
let fn = fnamemodify(a:0 ? a:1 : expand('%'), ':p')
if !isdirectory(fn)
let fn = fnamemodify(fn, ':h')
endif
let bootstrap = findfile('bootstrap/app.php', escape(fn, ', ') . ';')
let artisan = findfile('artisan', escape(fn, ', ') . ';')
if !empty(bootstrap) && !empty(artisan)
let b:laravel_root = fnamemodify(artisan, ':p:h')
return 1
endif
endfunction
" }}}
" Initialization {{{
augroup laravel_detect
autocmd!
" Project detection
autocmd BufNewFile,BufReadPost *
\ if s:laravel_detect(expand("<afile>:p")) && empty(&filetype) |
\ call laravel#buffer_setup() |
\ endif
autocmd VimEnter *
\ if empty(expand("<amatch>")) && s:laravel_detect(getcwd()) |
\ call laravel#buffer_setup() |
\ endif
autocmd FileType * if s:laravel_detect() | call laravel#buffer_setup() | endif
autocmd BufNewFile,BufReadPost */storage/logs/*.log if s:laravel_detect() | call laravel#log_buffer_setup() | endif
" File-type-specific setup
autocmd Syntax php
\ if s:laravel_detect() | call laravel#buffer_syntax() | endif
augroup END
nnoremap <Plug>(laravel-goto-php) :<C-u>execute laravel#goto#filetype_php()<CR>
nnoremap <Plug>(laravel-goto-blade) :<C-u>execute laravel#goto#filetype_blade()<CR>
" }}}
" Projections {{{
" Ensure that projectionist gets loaded first
if !exists('g:loaded_projectionist')
runtime! plugin/projectionist.vim
endif
augroup laravel_projections
autocmd!
autocmd User ProjectionistDetect
\ if s:laravel_detect(get(g:, 'projectionist_file', '')) |
\ call laravel#projectionist#append() |
\ endif
augroup END
" }}}
" Completion {{{
augroup laravel_completion
autocmd!
" Set up nvim-completion-manager sources
" :help NCM-source-examples
autocmd User CmSetup call cm#register_source({'name' : 'Laravel Route',
\ 'abbreviation': 'Route',
\ 'priority': 9,
\ 'scoping': 1,
\ 'scopes': ['php', 'blade'],
\ 'word_pattern': '[A-Za-z0-9_.:-]+',
\ 'cm_refresh_patterns': ['\broute\([''"]'],
\ 'cm_refresh': 'laravel#completion#cm_routes',
\ })
autocmd User CmSetup call cm#register_source({'name' : 'Laravel View',
\ 'abbreviation': 'View',
\ 'priority': 9,
\ 'scoping': 1,
\ 'scopes': ['php', 'blade'],
\ 'word_pattern': '[A-Za-z0-9_.:-]+',
\ 'cm_refresh_patterns': ['\bview\([''"]', '@(component|extends|include)\([''"]'],
\ 'cm_refresh': 'laravel#completion#cm_views',
\ })
" Set up ncm2 sources
" :help ncm2#register_source-example
autocmd User Ncm2Plugin call ncm2#register_source({
\ 'name': 'Laravel Route',
\ 'priority': 9,
\ 'subscope_enable': 1,
\ 'scope': ['php', 'blade'],
\ 'mark': 'Route',
\ 'word_pattern': '[A-Za-z0-9_.:-]+',
\ 'complete_length': -1,
\ 'complete_pattern': ['\broute\([''"]'],
\ 'on_complete': 'laravel#completion#ncm2_routes',
\ })
autocmd User Ncm2Plugin call ncm2#register_source({
\ 'name': 'Laravel View',
\ 'priority': 9,
\ 'subscope_enable': 1,
\ 'scope': ['php', 'blade'],
\ 'mark': 'View',
\ 'word_pattern': '[A-Za-z0-9_.:-]+',
\ 'complete_length': -1,
\ 'complete_pattern': ['\bview\([''"]', '@(component|extends|include)\([''"]'],
\ 'on_complete': 'laravel#completion#ncm2_views',
\ })
augroup END
" }}}
" vim: fdm=marker:sw=2:sts=2:et