patch 7.4.1541
Problem: Missing job_info().
Solution: Implement it.
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 5284293..0bb4b83 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -4527,6 +4527,8 @@
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()*
diff --git a/src/channel.c b/src/channel.c
index 10f1bc8..8f70da2 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -3725,6 +3725,40 @@
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)
{
diff --git a/src/eval.c b/src/eval.c
index 5807707..f4843e2 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -632,6 +632,7 @@
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);
@@ -8208,6 +8209,7 @@
{"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},
@@ -14342,6 +14344,18 @@
}
/*
+ * "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
*/
static void
@@ -14375,13 +14389,11 @@
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));
}
}
diff --git a/src/proto/channel.pro b/src/proto/channel.pro
index e6e5446..eb50b2f 100644
--- a/src/proto/channel.pro
+++ b/src/proto/channel.pro
@@ -54,5 +54,6 @@
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 : */
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index a2d4125..ed62e66 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -479,6 +479,12 @@
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()
@@ -1051,6 +1057,7 @@
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()
@@ -1069,6 +1076,7 @@
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
diff --git a/src/version.c b/src/version.c
index 3e802b5..ed48bb0 100644
--- a/src/version.c
+++ b/src/version.c
@@ -744,6 +744,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1541,
+/**/
1540,
/**/
1539,