-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForceCli.vim
189 lines (150 loc) · 5.03 KB
/
ForceCli.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
" Config Variables {
if !exists("g:force_dispatch_background")
let g:force_dispatch_background = 0
end
if !exists('g:loaded_airline')
let g:force_disable_airline = 1
endif
if !exists("g:force_disable_airline")
let g:force_disable_airline = 0
endif
if !exists("g:force_status_line_func_added")
let g:force_status_line_func_added = 0
endif
" Config Variables }
" Main Functions {
function! ForceDeploy()
let filePath = expand("%")
let command = "force push -f \"" . filePath . "\""
call ForceTryStart(command)
endfunction
function! ForceTest()
let fileName = expand("%:t:r")
let command = "force test \"" . fileName ."\""
call ForceTryStart(command)
endfunction
" function! ForceRetrieve()
" let filePath = expand("%")
"
" let command =
" call ForceTryStart(command)
"
" endfunction
function! ForceActive(...)
if a:0 > 0
if a:1 == "?"
let command = "force logins"
else
let target = a:1
let command = "force active \"" . target . "\""
end
else
let command = "force active"
end
if exists("l:command")
call ForceTryStart(command)
end
endfunction
function! ForceLogin(...)
let command = "force login " . join(a:000, " ")
call ForceTryStart(command)
endfunction
" Try to run the command using vim-dispatch
" (https://github.com/tpope/vim-dispatch)
function! ForceTryStart(...)
" Make sure we have a parameter
if a:0 > 0
let command = a:1
if exists(':Neomake')
let command = "NeomakeSh " . command
elseif exists(":Dispatch")
" Determine foreground or background
if g:force_dispatch_background == 1
let fgbg = "! "
else
let fgbg = " "
end
let command = "Dispatch" . fgbg . command
else
let command = "!" . command
end
execute command
end
endfunction
command! -nargs=0 ForceDeploy call ForceDeploy() " Deploy current file
command! -nargs=0 ForceTest call ForceTest() " Deploy current file and run test
"command! -nargs=0 ForceRetrieve call ForceRetrieve() " Retrieve current file
command! -nargs=? ForceLogin call ForceLogin(<f-args>) " Retrieve current file
command! -nargs=? ForceTarget call ForceTarget(<f-args>) " Change deploy target
" Main Functions }
" Set SF Compiler
autocmd BufNewFile,BufRead *.cls,*.trigger,*.page,*.component compiler ForceCli
" Execute Anonymous {
" Run current buffer
" function! ForceRunCurrentBuffer()
" let a=join(getline(1, '$'), "\\\n")
" let cmd=join(["force apex <<END_APEX", a, "END_APEX"], "\\\n")
" execute '!' . cmd
" endfunction
" Run current file
" function! ForceRunCurrentFile()
" let anonapex=expand('%')
" botright new
" setlocal buftype=nofile bufhidden=wipe noswapfile nowrap filetype=apexlog
" silent execute '$read ! force apex ' . anonapex
" endfunction
" function! ForceExecAnon()
" let anonfile="~/.anon-apex"
" execute 'botright edit ' . anonfile
" setlocal filetype=apex makeprg="force apex"
" endfunction
function! ForceNewExecAnon()
botright new AnonApex
setlocal buftype=nofile bufhidden=wipe noswapfile filetype=apex
endfunction
" Run current file
function! ForceExecScratchAnon()
" TODO: Check if buffer name is AnonApex
" If not AnonApex, get current or selected lines and write to anonfile
let anonfile="~/.anon-apex"
silent execute 'w ' . anonfile
" TODO: Test if log exists already
botright new AnonApexLog
setlocal buftype=nofile bufhidden=wipe noswapfile nowrap filetype=apexlog
silent execute '$read ! force apex ' . anonfile
endfunction
command! -nargs=0 ForceNewExecAnon call ForceNewExecAnon()
command! -nargs=0 ForceExecScratchAnon call ForceExecScratchAnon()
" Execute Anonymous }
" Plugin Functions {
function! ForceCli#TargetName()
" Returns the name of the current force.com target
return system('force-target 2> /dev/null')[:-2]
endfunction
function! ForceCli#AirlineFunction(...)
if &filetype == 'apex' || &filetype == 'visualforce'
let force_target = ForceCli#TargetName()
if force_target != ''
call airline#extensions#append_to_section('b', ' ☁' . force_target)
endif
endif
endfunction
if g:force_disable_airline != 1 && g:loaded_airline == 1 && g:force_status_line_func_added != 1
call airline#add_statusline_func('ForceCli#AirlineFunction')
let g:force_status_line_func_added = 1
endif
" Neomake support
let g:neomake_apex_force_push_maker = {
\ 'exe': 'force',
\ 'args': ['push', '-f'],
\ 'errorformat': &errorformat,
\ }
let g:neomake_apex_force_test_maker = {
\ 'exe': 'echo',
\ 'args': ['test', '%:t:r', '||'],
\ 'errorformat': &errorformat,
\ }
let g:neomake_visualforce_force_push_maker = g:neomake_apex_force_push_maker
let g:neomake_apex_enabled_makers = ['force_push']
let g:neomake_visualforce_enabled_makers = ['force_push']
" Plugin Functions }