Problem: Missing job_info().
Solution: Implement it.
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.
+ For more information see |job_info()|.
+
{only available when compiled with the |+job| feature}
job_stop({job} [, {how}]) *job_stop()*
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
job_stop(job_T *job, typval_T *argvars)
{
static void f_items(typval_T *argvars, typval_T *rettv);
#ifdef FEAT_JOB_CHANNEL
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_start(typval_T *argvars, typval_T *rettv);
static void f_job_stop(typval_T *argvars, typval_T *rettv);
{"items", 1, 1, f_items},
#ifdef FEAT_JOB_CHANNEL
{"job_getchannel", 1, 1, f_job_getchannel},
+ {"job_info", 1, 1, f_job_info},
{"job_setoptions", 2, 2, f_job_setoptions},
{"job_start", 1, 2, f_job_start},
{"job_status", 1, 1, f_job_status},
}
}
+/*
+ * "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
*/
f_job_status(typval_T *argvars, typval_T *rettv)
{
job_T *job = get_job_arg(&argvars[0]);
- char *result;
if (job != NULL)
{
- result = job_status(job);
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));
}
}
void job_check_ended(void);
job_T *job_start(typval_T *argvars);
char *job_status(job_T *job);
+void job_info(job_T *job, dict_T *dict);
int job_stop(job_T *job, typval_T *argvars);
/* vim: set ft=c : */
finally
call job_stop(job)
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
func Test_nl_pipe()
function s:test_exit_callback(port)
call job_setoptions(s:job, {'exit-cb': 'MyExitCb'})
let s:exit_job = s:job
+ call assert_equal('MyExitCb', job_info(s:job)['exit-cb'])
endfunc
func Test_exit_callback()
endfor
call assert_equal('done', s:job_exit_ret)
+ call assert_equal('dead', job_info(s:exit_job).status)
unlet s:exit_job
endif
endfunc
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1541,
/**/
1540,
/**/