Skip to content

Commit e1fc515

Browse files
committed
patch 8.0.1742: cannot get a list of all the jobs
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)
1 parent 259a90f commit e1fc515

File tree

7 files changed

+81
-10
lines changed

7 files changed

+81
-10
lines changed

Diff for: runtime/doc/eval.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ islocked({expr}) Number |TRUE| if {expr} is locked
22342234
isnan({expr}) Number |TRUE| if {expr} is NaN
22352235
items({dict}) List key-value pairs in {dict}
22362236
job_getchannel({job}) Channel get the channel handle for {job}
2237-
job_info({job}) Dict get information about {job}
2237+
job_info([{job}]) Dict get information about {job}
22382238
job_setoptions({job}, {options}) none set options for {job}
22392239
job_start({command} [, {options}])
22402240
Job start a job

Diff for: src/channel.c

+50-1
Original file line numberDiff line numberDiff line change
@@ -5002,6 +5002,8 @@ static job_T *first_job = NULL;
50025002
static void
50035003
job_free_contents(job_T *job)
50045004
{
5005+
int i;
5006+
50055007
ch_log(job->jv_channel, "Freeing job");
50065008
if (job->jv_channel != NULL)
50075009
{
@@ -5019,6 +5021,12 @@ job_free_contents(job_T *job)
50195021
vim_free(job->jv_tty_out);
50205022
vim_free(job->jv_stoponexit);
50215023
free_callback(job->jv_exit_cb, job->jv_exit_partial);
5024+
if (job->argv != NULL)
5025+
{
5026+
for (i = 0; job->argv[i] != NULL; i++)
5027+
vim_free(job->argv[i]);
5028+
vim_free(job->argv);
5029+
}
50225030
}
50235031

50245032
static void
@@ -5463,6 +5471,8 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
54635471
#endif
54645472
jobopt_T opt;
54655473
ch_part_T part;
5474+
int len;
5475+
int i;
54665476

54675477
job = job_alloc();
54685478
if (job == NULL)
@@ -5593,11 +5603,21 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
55935603
#endif
55945604
}
55955605

5606+
/* Save the command used to start the job */
5607+
len = 0;
5608+
for (i = 0; argv[i] != NULL; i++)
5609+
len++;
5610+
job->argv = (char_u **)alloc(sizeof(char_u *) * (len + 1));
5611+
if (job->argv == NULL)
5612+
goto theend;
5613+
for (i = 0; argv[i] != NULL; i++)
5614+
job->argv[i] = vim_strsave((char_u *)argv[i]);
5615+
job->argv[i] = NULL;
5616+
55965617
#ifdef USE_ARGV
55975618
if (ch_log_active())
55985619
{
55995620
garray_T ga;
5600-
int i;
56015621

56025622
ga_init2(&ga, (int)sizeof(char), 200);
56035623
for (i = 0; i < argc; ++i)
@@ -5661,6 +5681,8 @@ job_info(job_T *job, dict_T *dict)
56615681
{
56625682
dictitem_T *item;
56635683
varnumber_T nr;
5684+
list_T *l;
5685+
int i;
56645686

56655687
dict_add_nr_str(dict, "status", 0L, (char_u *)job_status(job));
56665688

@@ -5689,6 +5711,33 @@ job_info(job_T *job, dict_T *dict)
56895711
dict_add_nr_str(dict, "exitval", job->jv_exitval, NULL);
56905712
dict_add_nr_str(dict, "exit_cb", 0L, job->jv_exit_cb);
56915713
dict_add_nr_str(dict, "stoponexit", 0L, job->jv_stoponexit);
5714+
5715+
l = list_alloc();
5716+
if (l != NULL)
5717+
{
5718+
dict_add_list(dict, "cmd", l);
5719+
for (i = 0; job->argv[i] != NULL; i++)
5720+
list_append_string(l, job->argv[i], -1);
5721+
}
5722+
}
5723+
5724+
/*
5725+
* Implementation of job_info() to return info for all jobs.
5726+
*/
5727+
void
5728+
job_info_all(list_T *l)
5729+
{
5730+
job_T *job;
5731+
typval_T tv;
5732+
5733+
for (job = first_job; job != NULL; job = job->jv_next)
5734+
{
5735+
tv.v_type = VAR_JOB;
5736+
tv.vval.v_job = job;
5737+
5738+
if (list_append_tv(l, &tv) != OK)
5739+
return;
5740+
}
56925741
}
56935742

56945743
/*

Diff for: src/evalfunc.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static struct fst
682682
{"items", 1, 1, f_items},
683683
#ifdef FEAT_JOB_CHANNEL
684684
{"job_getchannel", 1, 1, f_job_getchannel},
685-
{"job_info", 1, 1, f_job_info},
685+
{"job_info", 0, 1, f_job_info},
686686
{"job_setoptions", 2, 2, f_job_setoptions},
687687
{"job_start", 1, 2, f_job_start},
688688
{"job_status", 1, 1, f_job_status},
@@ -7007,10 +7007,15 @@ f_job_getchannel(typval_T *argvars, typval_T *rettv)
70077007
static void
70087008
f_job_info(typval_T *argvars, typval_T *rettv)
70097009
{
7010-
job_T *job = get_job_arg(&argvars[0]);
7010+
if (argvars[0].v_type != VAR_UNKNOWN)
7011+
{
7012+
job_T *job = get_job_arg(&argvars[0]);
70117013

7012-
if (job != NULL && rettv_dict_alloc(rettv) != FAIL)
7013-
job_info(job, rettv->vval.v_dict);
7014+
if (job != NULL && rettv_dict_alloc(rettv) != FAIL)
7015+
job_info(job, rettv->vval.v_dict);
7016+
}
7017+
else if (rettv_list_alloc(rettv) == OK)
7018+
job_info_all(rettv->vval.v_list);
70147019
}
70157020

70167021
/*

Diff for: src/proto/channel.pro

+1
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,6 @@ void job_check_ended(void);
6868
job_T *job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg);
6969
char *job_status(job_T *job);
7070
void job_info(job_T *job, dict_T *dict);
71+
void job_info_all(list_T *l);
7172
int job_stop(job_T *job, typval_T *argvars, char *type);
7273
/* vim: set ft=c : */

Diff for: src/structs.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ typedef struct
271271
# define w_p_scl w_onebuf_opt.wo_scl /* 'signcolumn' */
272272
#endif
273273
#ifdef FEAT_TERMINAL
274-
char_u *wo_tk;
275-
#define w_p_tk w_onebuf_opt.wo_tk /* 'termkey' */
276-
char_u *wo_tms;
277-
#define w_p_tms w_onebuf_opt.wo_tms /* 'termsize' */
274+
char_u *wo_twk;
275+
# define w_p_twk w_onebuf_opt.wo_twk /* 'termwinkey' */
276+
char_u *wo_tws;
277+
# define w_p_tws w_onebuf_opt.wo_tws /* 'termwinsize' */
278278
#endif
279279

280280
#ifdef FEAT_EVAL
@@ -1488,6 +1488,7 @@ struct jobvar_S
14881488
int jv_copyID;
14891489

14901490
channel_T *jv_channel; /* channel for I/O, reference counted */
1491+
char_u **argv; /* command line used to start the job */
14911492
};
14921493

14931494
/*
@@ -2262,6 +2263,9 @@ struct file_buffer
22622263
#ifdef FEAT_LISP
22632264
char_u *b_p_lw; /* 'lispwords' local value */
22642265
#endif
2266+
#ifdef FEAT_TERMINAL
2267+
long b_p_twsl; /* 'termwinscroll' */
2268+
#endif
22652269

22662270
/* end of buffer options */
22672271

Diff for: src/testdir/test_channel.vim

+10
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,16 @@ func Test_raw_pipe()
508508
let info = job_info(job)
509509
call assert_equal("dead", info.status)
510510
call assert_equal("term", info.stoponexit)
511+
call assert_equal(2, len(info.cmd))
512+
call assert_equal("test_channel_pipe.py", info.cmd[1])
513+
514+
let found = 0
515+
for j in job_info()
516+
if j == job
517+
let found += 1
518+
endif
519+
endfor
520+
call assert_equal(1, found)
511521
endfunc
512522

513523
func Test_nl_pipe()

Diff for: src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1742,
764766
/**/
765767
1741,
766768
/**/

0 commit comments

Comments
 (0)