Skip to content

Commit 7031bf9

Browse files
committed
Allow backgrounding server
Default b:start as well as :Server now background when a bang is given. If --daemon is given, the bang continues to enable killing the old server beforehand. Use :Server!! to kill a running server without restarting. :Rserver (currently) remains unchanged.
1 parent 2cdfd7b commit 7031bf9

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

autoload/rails.vim

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,8 +1614,8 @@ function! s:BufScriptWrappers()
16141614
command! -buffer -bang -bar -nargs=* -complete=customlist,s:Complete_generate Generate :execute rails#app().generator_command(<bang>0,'generate',<f-args>)
16151615
command! -buffer -bar -nargs=* -complete=customlist,s:Complete_destroy Rdestroy :execute rails#app().generator_command(1,'destroy',<f-args>)
16161616
command! -buffer -bar -nargs=* -complete=customlist,s:Complete_destroy Destroy :execute rails#app().generator_command(1,'destroy',<f-args>)
1617-
command! -buffer -bar -nargs=? -bang -complete=customlist,s:Complete_server Rserver :execute rails#app().server_command(<bang>0,<q-args>)
1618-
command! -buffer -bar -nargs=? -bang -complete=customlist,s:Complete_server Server :execute rails#app().server_command(<bang>0,<q-args>)
1617+
command! -buffer -bar -nargs=? -bang -complete=customlist,s:Complete_server Rserver :execute rails#app().server_command(<bang>0, 1, <q-args>)
1618+
command! -buffer -bar -nargs=? -bang -complete=customlist,s:Complete_server Server :execute rails#app().server_command(0, <bang>0, <q-args>)
16191619
command! -buffer -bang -nargs=? -range=0 -complete=customlist,s:Complete_edit Rrunner :execute rails#buffer().runner_command(<bang>0, <count>?<line1>:0, <q-args>)
16201620
command! -buffer -bang -nargs=? -range=0 -complete=customlist,s:Complete_edit Runner :execute rails#buffer().runner_command(<bang>0, <count>?<line1>:0, <q-args>)
16211621
command! -buffer -nargs=1 -range=0 -complete=customlist,s:Complete_ruby Rp :execute rails#app().output_command(<count>==<line2>?<count>:-1, 'p begin '.<q-args>.' end')
@@ -1757,7 +1757,7 @@ function! s:app_output_command(count, code) dict
17571757
return ''
17581758
endfunction
17591759

1760-
function! rails#get_binding_for(pid)
1760+
function! rails#get_binding_for(pid) abort
17611761
if empty(a:pid)
17621762
return ''
17631763
endif
@@ -1783,13 +1783,11 @@ function! rails#get_binding_for(pid)
17831783
return ''
17841784
endfunction
17851785

1786-
function! s:app_server_command(bang,arg) dict
1787-
if a:arg =~# '--help'
1788-
call self.execute_rails_command('server '.a:arg)
1789-
return ''
1790-
endif
1791-
let pidfile = self.path('tmp/pids/server.pid')
1792-
if a:bang && executable("ruby")
1786+
function! s:app_server_command(kill, bg, arg) dict abort
1787+
let arg = empty(a:arg) ? '' : ' '.a:arg
1788+
let flags = ' -d\| --daemon\| --help'
1789+
if a:kill || a:arg =~# '^ *[!-]$' || (a:bg && arg =~# flags)
1790+
let pidfile = self.path('tmp/pids/server.pid')
17931791
let pid = get(s:readfile(pidfile), 0, 0)
17941792
if pid
17951793
echo "Killing server with pid ".pid
@@ -1799,15 +1797,20 @@ function! s:app_server_command(bang,arg) dict
17991797
endif
18001798
call system("ruby -e 'Process.kill(9,".pid.")'")
18011799
sleep 100m
1800+
else
1801+
echo "No server running"
18021802
endif
1803-
if a:arg == "-"
1803+
if a:arg =~# '^ *[-!]$'
18041804
return
18051805
endif
18061806
endif
1807-
if (exists(':Start') == 2) || has('win32')
1808-
call self.start_rails_command('server '.a:arg, 1)
1807+
if exists(':Start') == 0 && !has('win32') && arg !~# flags
1808+
let arg .= ' -d'
1809+
endif
1810+
if a:arg =~# flags
1811+
call self.execute_rails_command('server '.a:arg)
18091812
else
1810-
call self.execute_rails_command('server '.a:arg.' -d')
1813+
call self.start_rails_command('server '.a:arg, a:bg)
18111814
endif
18121815
return ''
18131816
endfunction
@@ -4833,7 +4836,7 @@ function! rails#buffer_setup() abort
48334836
call self.setvar('dispatch', ':Preview')
48344837
endif
48354838
if empty(self.getvar('start'))
4836-
call self.setvar('start', ':Rserver')
4839+
call self.setvar('start', ':Server')
48374840
endif
48384841
endfunction
48394842

doc/rails.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ A limited amount of completion with <Tab> is supported.
460460

461461
*rails-:Rserver*
462462
:Rserver {options} Launches rails server {options} in the background.
463-
On win32, this means |!start|. Otherwise, the
464-
--daemon option is passed in.
463+
If dispatch.vim's :Start is available, that is used.
464+
Otherwise, the --daemon option is passed in.
465465

466466
*rails-:Rserver!*
467467
:Rserver! {options} Kill the pid found in tmp/pids/server.pid and then

0 commit comments

Comments
 (0)