forked from aniani/vim
patch 7.4.1541
Problem: Missing job_info(). Solution: Implement it.
This commit is contained in:
@@ -4527,6 +4527,8 @@ job_status({job}) *job_status()* *E916*
|
|||||||
If an exit callback was set with the "exit-cb" option and the
|
If an exit callback was set with the "exit-cb" option and the
|
||||||
job is now detected to be "dead" the callback will be invoked.
|
job is now detected to be "dead" the callback will be invoked.
|
||||||
|
|
||||||
|
For more information see |job_info()|.
|
||||||
|
|
||||||
{only available when compiled with the |+job| feature}
|
{only available when compiled with the |+job| feature}
|
||||||
|
|
||||||
job_stop({job} [, {how}]) *job_stop()*
|
job_stop({job} [, {how}]) *job_stop()*
|
||||||
|
@@ -3725,6 +3725,40 @@ job_status(job_T *job)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Implementation of job_info().
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
job_info(job_T *job, dict_T *dict)
|
||||||
|
{
|
||||||
|
dictitem_T *item;
|
||||||
|
varnumber_T nr;
|
||||||
|
|
||||||
|
dict_add_nr_str(dict, "status", 0L, (char_u *)job_status(job));
|
||||||
|
|
||||||
|
item = dictitem_alloc((char_u *)"channel");
|
||||||
|
if (item == NULL)
|
||||||
|
return;
|
||||||
|
item->di_tv.v_lock = 0;
|
||||||
|
item->di_tv.v_type = VAR_CHANNEL;
|
||||||
|
item->di_tv.vval.v_channel = job->jv_channel;
|
||||||
|
if (job->jv_channel != NULL)
|
||||||
|
++job->jv_channel->ch_refcount;
|
||||||
|
if (dict_add(dict, item) == FAIL)
|
||||||
|
dictitem_free(item);
|
||||||
|
|
||||||
|
#ifdef UNIX
|
||||||
|
nr = job->jv_pid;
|
||||||
|
#else
|
||||||
|
nr = job->jv_proc_info.dwProcessId;
|
||||||
|
#endif
|
||||||
|
dict_add_nr_str(dict, "process", nr, NULL);
|
||||||
|
|
||||||
|
dict_add_nr_str(dict, "exitval", job->jv_exitval, NULL);
|
||||||
|
dict_add_nr_str(dict, "exit-cb", 0L, job->jv_exit_cb);
|
||||||
|
dict_add_nr_str(dict, "stoponexit", 0L, job->jv_stoponexit);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
job_stop(job_T *job, typval_T *argvars)
|
job_stop(job_T *job, typval_T *argvars)
|
||||||
{
|
{
|
||||||
|
18
src/eval.c
18
src/eval.c
@@ -632,6 +632,7 @@ static void f_isnan(typval_T *argvars, typval_T *rettv);
|
|||||||
static void f_items(typval_T *argvars, typval_T *rettv);
|
static void f_items(typval_T *argvars, typval_T *rettv);
|
||||||
#ifdef FEAT_JOB_CHANNEL
|
#ifdef FEAT_JOB_CHANNEL
|
||||||
static void f_job_getchannel(typval_T *argvars, typval_T *rettv);
|
static void f_job_getchannel(typval_T *argvars, typval_T *rettv);
|
||||||
|
static void f_job_info(typval_T *argvars, typval_T *rettv);
|
||||||
static void f_job_setoptions(typval_T *argvars, typval_T *rettv);
|
static void f_job_setoptions(typval_T *argvars, typval_T *rettv);
|
||||||
static void f_job_start(typval_T *argvars, typval_T *rettv);
|
static void f_job_start(typval_T *argvars, typval_T *rettv);
|
||||||
static void f_job_stop(typval_T *argvars, typval_T *rettv);
|
static void f_job_stop(typval_T *argvars, typval_T *rettv);
|
||||||
@@ -8208,6 +8209,7 @@ static struct fst
|
|||||||
{"items", 1, 1, f_items},
|
{"items", 1, 1, f_items},
|
||||||
#ifdef FEAT_JOB_CHANNEL
|
#ifdef FEAT_JOB_CHANNEL
|
||||||
{"job_getchannel", 1, 1, f_job_getchannel},
|
{"job_getchannel", 1, 1, f_job_getchannel},
|
||||||
|
{"job_info", 1, 1, f_job_info},
|
||||||
{"job_setoptions", 2, 2, f_job_setoptions},
|
{"job_setoptions", 2, 2, f_job_setoptions},
|
||||||
{"job_start", 1, 2, f_job_start},
|
{"job_start", 1, 2, f_job_start},
|
||||||
{"job_status", 1, 1, f_job_status},
|
{"job_status", 1, 1, f_job_status},
|
||||||
@@ -14341,6 +14343,18 @@ f_job_getchannel(typval_T *argvars, typval_T *rettv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "job_info()" function
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
f_job_info(typval_T *argvars, typval_T *rettv)
|
||||||
|
{
|
||||||
|
job_T *job = get_job_arg(&argvars[0]);
|
||||||
|
|
||||||
|
if (job != NULL && rettv_dict_alloc(rettv) != FAIL)
|
||||||
|
job_info(job, rettv->vval.v_dict);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "job_setoptions()" function
|
* "job_setoptions()" function
|
||||||
*/
|
*/
|
||||||
@@ -14375,13 +14389,11 @@ f_job_start(typval_T *argvars, typval_T *rettv)
|
|||||||
f_job_status(typval_T *argvars, typval_T *rettv)
|
f_job_status(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
job_T *job = get_job_arg(&argvars[0]);
|
job_T *job = get_job_arg(&argvars[0]);
|
||||||
char *result;
|
|
||||||
|
|
||||||
if (job != NULL)
|
if (job != NULL)
|
||||||
{
|
{
|
||||||
result = job_status(job);
|
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = VAR_STRING;
|
||||||
rettv->vval.v_string = vim_strsave((char_u *)result);
|
rettv->vval.v_string = vim_strsave((char_u *)job_status(job));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,5 +54,6 @@ void job_stop_on_exit(void);
|
|||||||
void job_check_ended(void);
|
void job_check_ended(void);
|
||||||
job_T *job_start(typval_T *argvars);
|
job_T *job_start(typval_T *argvars);
|
||||||
char *job_status(job_T *job);
|
char *job_status(job_T *job);
|
||||||
|
void job_info(job_T *job, dict_T *dict);
|
||||||
int job_stop(job_T *job, typval_T *argvars);
|
int job_stop(job_T *job, typval_T *argvars);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
@@ -479,6 +479,12 @@ func Test_raw_pipe()
|
|||||||
finally
|
finally
|
||||||
call job_stop(job)
|
call job_stop(job)
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
|
let s:job = job
|
||||||
|
call s:waitFor('"dead" == job_status(s:job)')
|
||||||
|
let info = job_info(job)
|
||||||
|
call assert_equal("dead", info.status)
|
||||||
|
call assert_equal("term", info.stoponexit)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_nl_pipe()
|
func Test_nl_pipe()
|
||||||
@@ -1051,6 +1057,7 @@ endfunc
|
|||||||
function s:test_exit_callback(port)
|
function s:test_exit_callback(port)
|
||||||
call job_setoptions(s:job, {'exit-cb': 'MyExitCb'})
|
call job_setoptions(s:job, {'exit-cb': 'MyExitCb'})
|
||||||
let s:exit_job = s:job
|
let s:exit_job = s:job
|
||||||
|
call assert_equal('MyExitCb', job_info(s:job)['exit-cb'])
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_exit_callback()
|
func Test_exit_callback()
|
||||||
@@ -1069,6 +1076,7 @@ func Test_exit_callback()
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
call assert_equal('done', s:job_exit_ret)
|
call assert_equal('done', s:job_exit_ret)
|
||||||
|
call assert_equal('dead', job_info(s:exit_job).status)
|
||||||
unlet s:exit_job
|
unlet s:exit_job
|
||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
@@ -743,6 +743,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1541,
|
||||||
/**/
|
/**/
|
||||||
1540,
|
1540,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user