1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-23 17:49:57 +08:00

Fix code runner (#3292)

This commit is contained in:
Wang Shidong 2020-01-20 01:29:03 +08:00 committed by GitHub
parent e9e3639bdc
commit 129271243c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -73,8 +73,8 @@ function! s:async_run(runner) abort
\ 'on_stderr' : function('s:on_stderr'), \ 'on_stderr' : function('s:on_stderr'),
\ 'on_exit' : function('s:on_exit'), \ 'on_exit' : function('s:on_exit'),
\ }) \ })
elseif type(a:runner) == type([]) elseif type(a:runner) ==# type([]) && len(a:runner) ==# 2
" the runner is a list " the runner is a list with two items
" the first item is compile cmd, and the second one is running cmd. " the first item is compile cmd, and the second one is running cmd.
let s:target = s:FILE.unify_path(tempname(), ':p') let s:target = s:FILE.unify_path(tempname(), ':p')
let dir = fnamemodify(s:target, ':h') let dir = fnamemodify(s:target, ':h')
@ -94,12 +94,12 @@ function! s:async_run(runner) abort
else else
let compile_cmd = compile_cmd + a:runner[0].opt + [get(s:, 'selected_file', bufname('%'))] let compile_cmd = compile_cmd + a:runner[0].opt + [get(s:, 'selected_file', bufname('%'))]
endif endif
else elseif type(a:runner[0]) ==# type('')
let usestdin = 0 let usestdin = 0
let compile_cmd = [substitute(printf(a:runner[0], bufname('%')), '#TEMP#', s:target, 'g')] let compile_cmd = substitute(printf(a:runner[0], bufname('%')), '#TEMP#', s:target, 'g')
endif endif
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 3, 0, [ call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 3, 0, [
\ '[Compile] ' . join(compile_cmd) . (usestdin ? ' STDIN' : ''), \ '[Compile] ' . compile_cmd . (usestdin ? ' STDIN' : ''),
\ '[Running] ' . s:target, \ '[Running] ' . s:target,
\ '', \ '',
\ repeat('-', 20)]) \ repeat('-', 20)])
@ -110,7 +110,7 @@ function! s:async_run(runner) abort
\ 'on_stderr' : function('s:on_stderr'), \ 'on_stderr' : function('s:on_stderr'),
\ 'on_exit' : function('s:on_compile_exit'), \ 'on_exit' : function('s:on_compile_exit'),
\ }) \ })
if usestdin if usestdin && s:job_id > 0
let range = get(a:runner[0], 'range', [1, '$']) let range = get(a:runner[0], 'range', [1, '$'])
call s:JOB.send(s:job_id, call('getline', range)) call s:JOB.send(s:job_id, call('getline', range))
call s:JOB.chanclose(s:job_id, 'stdin') call s:JOB.chanclose(s:job_id, 'stdin')
@ -144,7 +144,7 @@ function! s:async_run(runner) abort
\ 'on_stderr' : function('s:on_stderr'), \ 'on_stderr' : function('s:on_stderr'),
\ 'on_exit' : function('s:on_exit'), \ 'on_exit' : function('s:on_exit'),
\ }) \ })
if usestdin if usestdin && s:job_id > 0
let range = get(a:runner, 'range', [1, '$']) let range = get(a:runner, 'range', [1, '$'])
call s:JOB.send(s:job_id, call('getline', range)) call s:JOB.send(s:job_id, call('getline', range))
call s:JOB.chanclose(s:job_id, 'stdin') call s:JOB.chanclose(s:job_id, 'stdin')
@ -277,7 +277,7 @@ else
function! s:on_stdout(job_id, data, event) abort function! s:on_stdout(job_id, data, event) abort
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data) call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data)
let s:lines += len(a:data) let s:lines += len(a:data)
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1]) call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
call s:update_statusline() call s:update_statusline()
endfunction endfunction
@ -285,7 +285,7 @@ else
let s:status.has_errors = 1 let s:status.has_errors = 1
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data) call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data)
let s:lines += len(a:data) let s:lines += len(a:data)
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1]) call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
call s:update_statusline() call s:update_statusline()
endfunction endfunction
endif endif