-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgoto.vim
More file actions
107 lines (87 loc) · 2.59 KB
/
Copy pathgoto.vim
File metadata and controls
107 lines (87 loc) · 2.59 KB
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
" autoload/laravel/goto.vim - Go to thing under cursor
" Maintainer: Noah Frederick
""
" @private
" Go to thing under cursor in PHP buffer
function! laravel#goto#filetype_php() abort
let path = laravel#goto#view()
if !empty(path) | return 'Eview '.path | endif
let path = laravel#goto#config()
if !empty(path) | return 'Econfig '.path | endif
let path = laravel#goto#language()
if !empty(path) | return 'Elanguage '.laravel#app().locale().'/'.path | endif
try
let cmd = composer#autoload#find()
if !empty(cmd) | return cmd | endif
catch /^Vim\%((\a\+)\)\=:E117/
endtry
return 'normal! gf'
endfunction
""
" @private
" Go to thing under cursor in Blade buffer
function! laravel#goto#filetype_blade() abort
let path = laravel#goto#template()
if !empty(path) | return 'Eview '.path | endif
let path = laravel#goto#config()
if !empty(path) | return 'Econfig '.path | endif
let path = laravel#goto#language()
if !empty(path) | return 'Elanguage '.laravel#app().locale().'/'.path | endif
try
let cmd = composer#autoload#find()
if !empty(cmd) | return cmd | endif
catch /^Vim\%((\a\+)\)\=:E117/
endtry
return 'normal! gf'
endfunction
""
" Find name in context
function! s:find_name(pattern) abort
" Search position of thing on current line
let [lnum, col] = searchpos(a:pattern, 'cnb', line('.'))
let cursor = col('.')
if col == 0
return ''
endif
" Capture the name
let buf = getline('.')[col - 1:]
let name = substitute(buf, a:pattern, '\1', '')
return s:path(name)
endfunction
""
" Convert name with dot notation to file path
function! s:path(name) abort
return substitute(a:name, '\.', '/', 'g')
endfunction
""
" @private
" Capture config name at cursor
function! laravel#goto#config() abort
return s:find_name('\<config([''"]\([^''".]\+\)[^''"]*[''"][,)].*$')
endfunction
""
" @private
" Capture view name at cursor
function! laravel#goto#view() abort
return s:find_name('\<view([''"]\([^''"]\+\)[''"][,)].*$')
endfunction
""
" @private
" Capture component, layout, or include name at cursor
function! laravel#goto#template() abort
return s:find_name('@\%(component\|extends\|include\)([''"]\([^''"]\+\)[''"][,)].*$')
endfunction
""
" @private
" Capture language name at cursor using trans(), trans_choice() and __() method
function! laravel#goto#language() abort
return s:find_name('\<\%\(__\|trans\%(_choice\)\?\)([''"]\([^''".]\+\)[^''"]*[''"][,)].*$')
endfunction
""
" @private
" Hack for testing script-local functions.
function! laravel#goto#sid()
nnoremap <SID> <SID>
return maparg('<SID>', 'n')
endfunction
" vim: fdm=marker:sw=2:sts=2:et