]> granicus.if.org Git - vim/commitdiff
patch 8.0.1742: cannot get a list of all the jobs v8.0.1742
authorBram Moolenaar <Bram@vim.org>
Sat, 21 Apr 2018 17:49:08 +0000 (19:49 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 21 Apr 2018 17:49:08 +0000 (19:49 +0200)
Problem:    Cannot get a list of all the jobs.  Cannot get the command of
            the job.
Solution:   When job_info() is called without an argument return a list of
            jobs.  Otherwise, include the command that the job is running.
            (Yegappan Lakshmanan)

runtime/doc/eval.txt
src/channel.c
src/evalfunc.c
src/proto/channel.pro
src/structs.h
src/testdir/test_channel.vim
src/version.c

index bcf14ee83f2ab586dd4a9638ed14d3e066dbd5e6..8961a33c011ff8979fa3e8f19a60f6a2300c57df 100644 (file)
@@ -2234,7 +2234,7 @@ islocked({expr})          Number  |TRUE| if {expr} is locked
 isnan({expr})                  Number  |TRUE| if {expr} is NaN
 items({dict})                  List    key-value pairs in {dict}
 job_getchannel({job})          Channel get the channel handle for {job}
-job_info({job})                        Dict    get information about {job}
+job_info([{job}])              Dict    get information about {job}
 job_setoptions({job}, {options}) none  set options for {job}
 job_start({command} [, {options}])
                                Job     start a job
index f5d86ed057012166a52b0d6d15806974a6da4591..98a668c147fd07e8fda69cf42091c4bd6df10a2d 100644 (file)
@@ -5002,6 +5002,8 @@ static job_T *first_job = NULL;
     static void
 job_free_contents(job_T *job)
 {
+    int                i;
+
     ch_log(job->jv_channel, "Freeing job");
     if (job->jv_channel != NULL)
     {
@@ -5019,6 +5021,12 @@ job_free_contents(job_T *job)
     vim_free(job->jv_tty_out);
     vim_free(job->jv_stoponexit);
     free_callback(job->jv_exit_cb, job->jv_exit_partial);
+    if (job->argv != NULL)
+    {
+       for (i = 0; job->argv[i] != NULL; i++)
+           vim_free(job->argv[i]);
+       vim_free(job->argv);
+    }
 }
 
     static void
@@ -5463,6 +5471,8 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
 #endif
     jobopt_T   opt;
     ch_part_T  part;
+    int                len;
+    int                i;
 
     job = job_alloc();
     if (job == NULL)
@@ -5593,11 +5603,21 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
 #endif
     }
 
+    /* Save the command used to start the job */
+    len = 0;
+    for (i = 0; argv[i] != NULL; i++)
+       len++;
+    job->argv = (char_u **)alloc(sizeof(char_u *) * (len + 1));
+    if (job->argv == NULL)
+       goto theend;
+    for (i = 0; argv[i] != NULL; i++)
+       job->argv[i] = vim_strsave((char_u *)argv[i]);
+    job->argv[i] = NULL;
+
 #ifdef USE_ARGV
     if (ch_log_active())
     {
        garray_T    ga;
-       int         i;
 
        ga_init2(&ga, (int)sizeof(char), 200);
        for (i = 0; i < argc; ++i)
@@ -5661,6 +5681,8 @@ job_info(job_T *job, dict_T *dict)
 {
     dictitem_T *item;
     varnumber_T        nr;
+    list_T     *l;
+    int                i;
 
     dict_add_nr_str(dict, "status", 0L, (char_u *)job_status(job));
 
@@ -5689,6 +5711,33 @@ job_info(job_T *job, dict_T *dict)
     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);
+
+    l = list_alloc();
+    if (l != NULL)
+    {
+       dict_add_list(dict, "cmd", l);
+       for (i = 0; job->argv[i] != NULL; i++)
+           list_append_string(l, job->argv[i], -1);
+    }
+}
+
+/*
+ * Implementation of job_info() to return info for all jobs.
+ */
+    void
+job_info_all(list_T *l)
+{
+    job_T      *job;
+    typval_T   tv;
+
+    for (job = first_job; job != NULL; job = job->jv_next)
+    {
+       tv.v_type = VAR_JOB;
+       tv.vval.v_job = job;
+
+       if (list_append_tv(l, &tv) != OK)
+           return;
+    }
 }
 
 /*
index 599d61ab81244251bb372f99bc5d6246a4e3ca4f..62dc40e1d7eb3b7e177dc61cd7b8c4521c789373 100644 (file)
@@ -682,7 +682,7 @@ static struct fst
     {"items",          1, 1, f_items},
 #ifdef FEAT_JOB_CHANNEL
     {"job_getchannel", 1, 1, f_job_getchannel},
-    {"job_info",       1, 1, f_job_info},
+    {"job_info",       0, 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},
@@ -7007,10 +7007,15 @@ f_job_getchannel(typval_T *argvars, typval_T *rettv)
     static void
 f_job_info(typval_T *argvars, typval_T *rettv)
 {
-    job_T      *job = get_job_arg(&argvars[0]);
+    if (argvars[0].v_type != VAR_UNKNOWN)
+    {
+       job_T   *job = get_job_arg(&argvars[0]);
 
-    if (job != NULL && rettv_dict_alloc(rettv) != FAIL)
-       job_info(job, rettv->vval.v_dict);
+       if (job != NULL && rettv_dict_alloc(rettv) != FAIL)
+           job_info(job, rettv->vval.v_dict);
+    }
+    else if (rettv_list_alloc(rettv) == OK)
+       job_info_all(rettv->vval.v_list);
 }
 
 /*
index dcf29b8420ee16463bed518ca00c79deeceee51d..2505df578647aa021e5e10ddc5e35b32f77708a4 100644 (file)
@@ -68,5 +68,6 @@ void job_check_ended(void);
 job_T *job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg);
 char *job_status(job_T *job);
 void job_info(job_T *job, dict_T *dict);
+void job_info_all(list_T *l);
 int job_stop(job_T *job, typval_T *argvars, char *type);
 /* vim: set ft=c : */
index 35433b1b24342c1c461012af671992c5b4096df0..55dd1fe6f0718c8cdf95606885755424cefadb29 100644 (file)
@@ -271,10 +271,10 @@ typedef struct
 # define w_p_scl w_onebuf_opt.wo_scl   /* 'signcolumn' */
 #endif
 #ifdef FEAT_TERMINAL
-    char_u     *wo_tk;
-#define w_p_tk w_onebuf_opt.wo_tk      /* 'termkey' */
-    char_u     *wo_tms;
-#define w_p_tms w_onebuf_opt.wo_tms    /* 'termsize' */
+    char_u     *wo_twk;
+# define w_p_twk w_onebuf_opt.wo_twk   /* 'termwinkey' */
+    char_u     *wo_tws;
+# define w_p_tws w_onebuf_opt.wo_tws   /* 'termwinsize' */
 #endif
 
 #ifdef FEAT_EVAL
@@ -1488,6 +1488,7 @@ struct jobvar_S
     int                jv_copyID;
 
     channel_T  *jv_channel;    /* channel for I/O, reference counted */
+    char_u     **argv;         /* command line used to start the job */
 };
 
 /*
@@ -2262,6 +2263,9 @@ struct file_buffer
 #ifdef FEAT_LISP
     char_u     *b_p_lw;        /* 'lispwords' local value */
 #endif
+#ifdef FEAT_TERMINAL
+    long       b_p_twsl;       /* 'termwinscroll' */
+#endif
 
     /* end of buffer options */
 
index ce573f9431ffa9a7abb51731ece1cffa67fe3f0b..805fa8dcaceee94264cb6895078780f5157a6b46 100644 (file)
@@ -508,6 +508,16 @@ func Test_raw_pipe()
   let info = job_info(job)
   call assert_equal("dead", info.status)
   call assert_equal("term", info.stoponexit)
+  call assert_equal(2, len(info.cmd))
+  call assert_equal("test_channel_pipe.py", info.cmd[1])
+
+  let found = 0
+  for j in job_info()
+    if j == job
+      let found += 1
+    endif
+  endfor
+  call assert_equal(1, found)
 endfunc
 
 func Test_nl_pipe()
index b1b7f4afadee3b779a698a39921cbe4ec79815d2..53aba0d2b3b94660333064eea1ed7b48bd7db570 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1742,
 /**/
     1741,
 /**/