mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-13 02:05:40 +08:00
Add tasks options cwd support (#3385)
This commit is contained in:
parent
3796ceba19
commit
68f821be40
@ -1 +1,6 @@
|
|||||||
|
[file-run]
|
||||||
|
command = "dir"
|
||||||
|
isBackground = false
|
||||||
|
[file-run.options]
|
||||||
|
cwd = '${workspaceFolder}bin/'
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ endfunction
|
|||||||
|
|
||||||
let s:target = ''
|
let s:target = ''
|
||||||
|
|
||||||
function! s:async_run(runner) abort
|
function! s:async_run(runner, ...) abort
|
||||||
if type(a:runner) == type('')
|
if type(a:runner) == type('')
|
||||||
" the runner is a string, the %s will be replaced as a file name.
|
" the runner is a string, the %s will be replaced as a file name.
|
||||||
try
|
try
|
||||||
@ -68,11 +68,12 @@ function! s:async_run(runner) abort
|
|||||||
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 3, 0, ['[Running] ' . cmd, '', repeat('-', 20)])
|
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 3, 0, ['[Running] ' . cmd, '', repeat('-', 20)])
|
||||||
let s:lines += 3
|
let s:lines += 3
|
||||||
let s:start_time = reltime()
|
let s:start_time = reltime()
|
||||||
let s:job_id = s:JOB.start(cmd,{
|
let opts = get(a:000, 0, {})
|
||||||
|
let s:job_id = s:JOB.start(cmd,extend({
|
||||||
\ 'on_stdout' : function('s:on_stdout'),
|
\ 'on_stdout' : function('s:on_stdout'),
|
||||||
\ 'on_stderr' : function('s:on_stderr'),
|
\ 'on_stderr' : function('s:on_stderr'),
|
||||||
\ 'on_exit' : function('s:on_exit'),
|
\ 'on_exit' : function('s:on_exit'),
|
||||||
\ })
|
\ }, opts))
|
||||||
elseif type(a:runner) ==# type([]) && len(a:runner) ==# 2
|
elseif type(a:runner) ==# type([]) && len(a:runner) ==# 2
|
||||||
" the runner is a list with two items
|
" 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.
|
||||||
@ -222,9 +223,10 @@ function! SpaceVim#plugins#runner#open(...) abort
|
|||||||
\ 'exit_code' : 0
|
\ 'exit_code' : 0
|
||||||
\ }
|
\ }
|
||||||
let runner = get(a:000, 0, get(s:runners, &filetype, ''))
|
let runner = get(a:000, 0, get(s:runners, &filetype, ''))
|
||||||
|
let opts = get(a:000, 1, {})
|
||||||
if !empty(runner)
|
if !empty(runner)
|
||||||
call s:open_win()
|
call s:open_win()
|
||||||
call s:async_run(runner)
|
call s:async_run(runner, opts)
|
||||||
call s:update_statusline()
|
call s:update_statusline()
|
||||||
else
|
else
|
||||||
let s:selected_language = get(s:, 'selected_language', '')
|
let s:selected_language = get(s:, 'selected_language', '')
|
||||||
@ -390,13 +392,17 @@ function! SpaceVim#plugins#runner#run_task(task)
|
|||||||
if !empty(a:task)
|
if !empty(a:task)
|
||||||
let cmd = get(a:task, 'command', '')
|
let cmd = get(a:task, 'command', '')
|
||||||
let args = get(a:task, 'args', [])
|
let args = get(a:task, 'args', [])
|
||||||
|
let opts = get(a:task, 'options', {})
|
||||||
if !empty(args) && !empty(cmd)
|
if !empty(args) && !empty(cmd)
|
||||||
let cmd = cmd . ' ' . join(args, ' ')
|
let cmd = cmd . ' ' . join(args, ' ')
|
||||||
endif
|
endif
|
||||||
|
if !empty(opts) && has_key(opts, 'cwd') && !empty(opts.cwd)
|
||||||
|
let opts = {'cwd' : opts.cwd}
|
||||||
|
endif
|
||||||
if isBackground
|
if isBackground
|
||||||
call s:run_backgroud(cmd)
|
call s:run_backgroud(cmd, opts)
|
||||||
else
|
else
|
||||||
call SpaceVim#plugins#runner#open(cmd)
|
call SpaceVim#plugins#runner#open(cmd, opts)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
@ -407,10 +413,11 @@ function! s:on_backgroud_exit(job_id, data, event) abort
|
|||||||
echo 'task finished with code=' . a:data . ' in ' . s:STRING.trim(reltimestr(s:end_time)) . ' seconds'
|
echo 'task finished with code=' . a:data . ' in ' . s:STRING.trim(reltimestr(s:end_time)) . ' seconds'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:run_backgroud(cmd) abort
|
function! s:run_backgroud(cmd, ...) abort
|
||||||
echo "task running"
|
echo "task running"
|
||||||
|
let opts = get(a:000, 0, {})
|
||||||
let s:start_time = reltime()
|
let s:start_time = reltime()
|
||||||
call s:JOB.start(a:cmd,{
|
call s:JOB.start(a:cmd,extend({
|
||||||
\ 'on_exit' : function('s:on_backgroud_exit'),
|
\ 'on_exit' : function('s:on_backgroud_exit'),
|
||||||
\ })
|
\ }, opts))
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -102,6 +102,11 @@ function! SpaceVim#plugins#tasks#get()
|
|||||||
if has_key(task, 'command') && type(task.command) ==# 1
|
if has_key(task, 'command') && type(task.command) ==# 1
|
||||||
let task.command = s:replace_variables(task.command)
|
let task.command = s:replace_variables(task.command)
|
||||||
endif
|
endif
|
||||||
|
if has_key(task, 'options') && type(task.options) ==# 4
|
||||||
|
if has_key(task.options, 'cwd') && type(task.options.cwd) ==# 1
|
||||||
|
let task.options.cwd = s:replace_variables(task.options.cwd)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
return task
|
return task
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -158,7 +163,7 @@ function! s:detect_npm_tasks() abort
|
|||||||
let detect_task = {}
|
let detect_task = {}
|
||||||
let conf = {}
|
let conf = {}
|
||||||
if filereadable('package.json')
|
if filereadable('package.json')
|
||||||
let conf = s:JSON.json_decode(join(readfile('package.json', ''), ''))
|
let conf = s:JSON.json_decode(join(readfile('package.json', ''), ''))
|
||||||
endif
|
endif
|
||||||
if has_key(conf, 'scripts')
|
if has_key(conf, 'scripts')
|
||||||
for task_name in keys(conf.scripts)
|
for task_name in keys(conf.scripts)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user