Patch 8.2.4909

8 views
Skip to first unread message

Bram Moolenaar

unread,
May 7, 2022, 11:38:59 AM5/7/22
to vim...@googlegroups.com

Patch 8.2.4909
Problem: MODE_ enum entries names are too generic.
Solution: use CH_MODE_.
Files: src/structs.h, src/channel.c, src/job.c, src/terminal.c


*** ../vim-8.2.4908/src/structs.h 2022-05-06 12:15:33.864427755 +0100
--- src/structs.h 2022-05-07 16:29:38.713356361 +0100
***************
*** 2198,2208 ****
// mode for a channel
typedef enum
{
! MODE_NL = 0,
! MODE_RAW,
! MODE_JSON,
! MODE_JS,
! MODE_LSP // Language Server Protocol (http + json)
} ch_mode_T;

typedef enum {
--- 2198,2208 ----
// mode for a channel
typedef enum
{
! CH_MODE_NL = 0,
! CH_MODE_RAW,
! CH_MODE_JSON,
! CH_MODE_JS,
! CH_MODE_LSP // Language Server Protocol (http + json)
} ch_mode_T;

typedef enum {
*** ../vim-8.2.4908/src/channel.c 2022-04-26 18:52:17.605206275 +0100
--- src/channel.c 2022-05-07 16:29:21.213356061 +0100
***************
*** 1274,1280 ****

// writing output to a buffer. Default mode is NL.
if (!(opt->jo_set & JO_OUT_MODE))
! channel->ch_part[PART_OUT].ch_mode = MODE_NL;
if (opt->jo_set & JO_OUT_BUF)
{
buf = buflist_findnr(opt->jo_io_buf[PART_OUT]);
--- 1274,1280 ----

// writing output to a buffer. Default mode is NL.
if (!(opt->jo_set & JO_OUT_MODE))
! channel->ch_part[PART_OUT].ch_mode = CH_MODE_NL;
if (opt->jo_set & JO_OUT_BUF)
{
buf = buflist_findnr(opt->jo_io_buf[PART_OUT]);
***************
*** 1320,1326 ****

// writing err to a buffer. Default mode is NL.
if (!(opt->jo_set & JO_ERR_MODE))
! channel->ch_part[PART_ERR].ch_mode = MODE_NL;
if (opt->jo_io[PART_ERR] == JIO_OUT)
buf = channel->ch_part[PART_OUT].ch_bufref.br_buf;
else if (opt->jo_set & JO_ERR_BUF)
--- 1320,1326 ----

// writing err to a buffer. Default mode is NL.
if (!(opt->jo_set & JO_ERR_MODE))
! channel->ch_part[PART_ERR].ch_mode = CH_MODE_NL;
if (opt->jo_io[PART_ERR] == JIO_OUT)
buf = channel->ch_part[PART_OUT].ch_bufref.br_buf;
else if (opt->jo_set & JO_ERR_BUF)
***************
*** 1445,1451 ****

// parse options
clear_job_options(&opt);
! opt.jo_mode = MODE_JSON;
opt.jo_timeout = 2000;
if (get_job_options(&argvars[1], &opt,
JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL
--- 1445,1451 ----

// parse options
clear_job_options(&opt);
! opt.jo_mode = CH_MODE_JSON;
opt.jo_timeout = 2000;
if (get_job_options(&argvars[1], &opt,
JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL
***************
*** 2051,2059 ****

last_node = node->rq_next;
len = node->rq_buflen + last_node->rq_buflen;
! if (want_nl || mode == MODE_LSP)
while (last_node->rq_next != NULL
! && (mode == MODE_LSP
|| channel_first_nl(last_node) == NULL))
{
last_node = last_node->rq_next;
--- 2051,2059 ----

last_node = node->rq_next;
len = node->rq_buflen + last_node->rq_buflen;
! if (want_nl || mode == CH_MODE_LSP)
while (last_node->rq_next != NULL
! && (mode == CH_MODE_LSP
|| channel_first_nl(last_node) == NULL))
{
last_node = last_node->rq_next;
***************
*** 2118,2124 ****
return FAIL; // out of memory
}

! if (channel->ch_part[part].ch_mode == MODE_NL)
{
// Drop any CR before a NL.
p = node->rq_buffer;
--- 2118,2124 ----
return FAIL; // out of memory
}

! if (channel->ch_part[part].ch_mode == CH_MODE_NL)
{
// Drop any CR before a NL.
p = node->rq_buffer;
***************
*** 2309,2315 ****
reader.js_cookie = channel;
reader.js_cookie_arg = part;

! if (chanpart->ch_mode == MODE_LSP)
status = channel_process_lsp_http_hdr(&reader);

// When a message is incomplete we wait for a short while for more to
--- 2309,2315 ----
reader.js_cookie = channel;
reader.js_cookie_arg = part;

! if (chanpart->ch_mode == CH_MODE_LSP)
status = channel_process_lsp_http_hdr(&reader);

// When a message is incomplete we wait for a short while for more to
***************
*** 2320,2339 ****
{
++emsg_silent;
status = json_decode(&reader, &listtv,
! chanpart->ch_mode == MODE_JS ? JSON_JS : 0);
--emsg_silent;
}
if (status == OK)
{
// Only accept the response when it is a list with at least two
// items.
! if (chanpart->ch_mode == MODE_LSP && listtv.v_type != VAR_DICT)
{
ch_error(channel, "Did not receive a LSP dict, discarding");
clear_tv(&listtv);
}
! else if (chanpart->ch_mode != MODE_LSP &&
! (listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2))
{
if (listtv.v_type != VAR_LIST)
ch_error(channel, "Did not receive a list, discarding");
--- 2320,2339 ----
{
++emsg_silent;
status = json_decode(&reader, &listtv,
! chanpart->ch_mode == CH_MODE_JS ? JSON_JS : 0);
--emsg_silent;
}
if (status == OK)
{
// Only accept the response when it is a list with at least two
// items.
! if (chanpart->ch_mode == CH_MODE_LSP && listtv.v_type != VAR_DICT)
{
ch_error(channel, "Did not receive a LSP dict, discarding");
clear_tv(&listtv);
}
! else if (chanpart->ch_mode != CH_MODE_LSP
! && (listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2))
{
if (listtv.v_type != VAR_LIST)
ch_error(channel, "Did not receive a list, discarding");
***************
*** 2563,2569 ****
list_T *l;
typval_T *tv;

! if (channel->ch_part[part].ch_mode != MODE_LSP)
{
l = item->jq_value->vval.v_list;
CHECK_LIST_MATERIALIZE(l);
--- 2563,2569 ----
list_T *l;
typval_T *tv;

! if (channel->ch_part[part].ch_mode != CH_MODE_LSP)
{
l = item->jq_value->vval.v_list;
CHECK_LIST_MATERIALIZE(l);
***************
*** 2684,2690 ****
{
char_u *cmd = argv[0].vval.v_string;
char_u *arg;
! int options = channel->ch_part[part].ch_mode == MODE_JS ? JSON_JS : 0;

if (argv[1].v_type != VAR_STRING)
{
--- 2684,2691 ----
{
char_u *cmd = argv[0].vval.v_string;
char_u *arg;
! int options = channel->ch_part[part].ch_mode == CH_MODE_JS
! ? JSON_JS : 0;

if (argv[1].v_type != VAR_STRING)
{
***************
*** 2964,2970 ****
{
ch_mode_T ch_mode = channel->ch_part[part].ch_mode;

! return ch_mode == MODE_JSON || ch_mode == MODE_JS || ch_mode == MODE_LSP;
}

/*
--- 2965,2972 ----
{
ch_mode_T ch_mode = channel->ch_part[part].ch_mode;

! return ch_mode == CH_MODE_JSON || ch_mode == CH_MODE_JS
! || ch_mode == CH_MODE_LSP;
}

/*
***************
*** 3021,3027 ****
// Get any json message in the queue.
if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL)
{
! if (ch_mode == MODE_LSP)
// In the "lsp" mode, the http header and the json payload may
// be received in multiple messages. So concatenate all the
// received messages.
--- 3023,3029 ----
// Get any json message in the queue.
if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL)
{
! if (ch_mode == CH_MODE_LSP)
// In the "lsp" mode, the http header and the json payload may
// be received in multiple messages. So concatenate all the
// received messages.
***************
*** 3033,3039 ****
return FALSE;
}

! if (ch_mode == MODE_LSP)
{
dict_T *d = listtv->vval.v_dict;
dictitem_T *di;
--- 3035,3041 ----
return FALSE;
}

! if (ch_mode == CH_MODE_LSP)
{
dict_T *d = listtv->vval.v_dict;
dictitem_T *di;
***************
*** 3092,3098 ****
return FALSE;
}

! if (ch_mode == MODE_NL)
{
char_u *nl = NULL;
char_u *buf;
--- 3094,3100 ----
return FALSE;
}

! if (ch_mode == CH_MODE_NL)
{
char_u *nl = NULL;
char_u *buf;
***************
*** 3169,3175 ****
}
}

! if (seq_nr > 0 && (ch_mode != MODE_LSP || called_otc))
{
if (!called_otc)
{
--- 3171,3177 ----
}
}

! if (seq_nr > 0 && (ch_mode != CH_MODE_LSP || called_otc))
{
if (!called_otc)
{
***************
*** 3356,3366 ****
STRCPY(namebuf + tail, "mode");
switch (chanpart->ch_mode)
{
! case MODE_NL: s = "NL"; break;
! case MODE_RAW: s = "RAW"; break;
! case MODE_JSON: s = "JSON"; break;
! case MODE_JS: s = "JS"; break;
! case MODE_LSP: s = "LSP"; break;
}
dict_add_string(dict, namebuf, (char_u *)s);

--- 3358,3368 ----
STRCPY(namebuf + tail, "mode");
switch (chanpart->ch_mode)
{
! case CH_MODE_NL: s = "NL"; break;
! case CH_MODE_RAW: s = "RAW"; break;
! case CH_MODE_JSON: s = "JSON"; break;
! case CH_MODE_JS: s = "JS"; break;
! case CH_MODE_LSP: s = "LSP"; break;
}
dict_add_string(dict, namebuf, (char_u *)s);

***************
*** 3901,3918 ****
readq_T *node;

ch_log(channel, "Blocking %s read, timeout: %d msec",
! mode == MODE_RAW ? "RAW" : "NL", timeout);

while (TRUE)
{
node = channel_peek(channel, part);
if (node != NULL)
{
! if (mode == MODE_RAW || (mode == MODE_NL
&& channel_first_nl(node) != NULL))
// got a complete message
break;
! if (channel_collapse(channel, part, mode == MODE_NL) == OK)
continue;
// If not blocking or nothing more is coming then return what we
// have.
--- 3903,3920 ----
readq_T *node;

ch_log(channel, "Blocking %s read, timeout: %d msec",
! mode == CH_MODE_RAW ? "RAW" : "NL", timeout);

while (TRUE)
{
node = channel_peek(channel, part);
if (node != NULL)
{
! if (mode == CH_MODE_RAW || (mode == CH_MODE_NL
&& channel_first_nl(node) != NULL))
// got a complete message
break;
! if (channel_collapse(channel, part, mode == CH_MODE_NL) == OK)
continue;
// If not blocking or nothing more is coming then return what we
// have.
***************
*** 3932,3938 ****
}

// We have a complete message now.
! if (mode == MODE_RAW || outlen != NULL)
{
msg = channel_get_all(channel, part, outlen);
}
--- 3934,3940 ----
}

// We have a complete message now.
! if (mode == CH_MODE_RAW || outlen != NULL)
{
msg = channel_get_all(channel, part, outlen);
}
***************
*** 4014,4020 ****

for (;;)
{
! if (mode == MODE_LSP)
// In the "lsp" mode, the http header and the json payload may be
// received in multiple messages. So concatenate all the received
// messages.
--- 4016,4022 ----

for (;;)
{
! if (mode == CH_MODE_LSP)
// In the "lsp" mode, the http header and the json payload may be
// received in multiple messages. So concatenate all the received
// messages.
***************
*** 4201,4207 ****
vim_free(p);
}
}
! else if (raw || mode == MODE_RAW || mode == MODE_NL)
rettv->vval.v_string = channel_read_block(channel, part,
timeout, raw, NULL);
else
--- 4203,4209 ----
vim_free(p);
}
}
! else if (raw || mode == CH_MODE_RAW || mode == CH_MODE_NL)
rettv->vval.v_string = channel_read_block(channel, part,
timeout, raw, NULL);
else
***************
*** 4578,4590 ****
part_send = channel_part_send(channel);

ch_mode = channel_get_mode(channel, part_send);
! if (ch_mode == MODE_RAW || ch_mode == MODE_NL)
{
emsg(_(e_cannot_use_evalexpr_sendexpr_with_raw_or_nl_channel));
return;
}

! if (ch_mode == MODE_LSP)
{
dict_T *d;
dictitem_T *di;
--- 4580,4592 ----
part_send = channel_part_send(channel);

ch_mode = channel_get_mode(channel, part_send);
! if (ch_mode == CH_MODE_RAW || ch_mode == CH_MODE_NL)
{
emsg(_(e_cannot_use_evalexpr_sendexpr_with_raw_or_nl_channel));
return;
}

! if (ch_mode == CH_MODE_LSP)
{
dict_T *d;
dictitem_T *di;
***************
*** 4637,4643 ****
{
id = ++channel->ch_last_msg_id;
text = json_encode_nr_expr(id, &argvars[1],
! (ch_mode == MODE_JS ? JSON_JS : 0) | JSON_NL);
}
if (text == NULL)
return;
--- 4639,4645 ----
{
id = ++channel->ch_last_msg_id;
text = json_encode_nr_expr(id, &argvars[1],
! (ch_mode == CH_MODE_JS ? JSON_JS : 0) | JSON_NL);
}
if (text == NULL)
return;
***************
*** 4654,4660 ****
if (channel_read_json_block(channel, part_read, timeout, id, &listtv)
== OK)
{
! if (ch_mode == MODE_LSP)
{
*rettv = *listtv;
// Change the type to avoid the value being freed.
--- 4656,4662 ----
if (channel_read_json_block(channel, part_read, timeout, id, &listtv)
== OK)
{
! if (ch_mode == CH_MODE_LSP)
{
*rettv = *listtv;
// Change the type to avoid the value being freed.
***************
*** 4674,4680 ****
}
}
free_job_options(&opt);
! if (ch_mode == MODE_LSP && !eval && callback_present)
{
// if ch_sendexpr() is used to send a LSP message and a callback
// function is specified, then return the generated identifier for the
--- 4676,4682 ----
}
}
free_job_options(&opt);
! if (ch_mode == CH_MODE_LSP && !eval && callback_present)
{
// if ch_sendexpr() is used to send a LSP message and a callback
// function is specified, then return the generated identifier for the
***************
*** 5126,5138 ****

/*
* Return the mode of "channel"/"part"
! * If "channel" is invalid returns MODE_JSON.
*/
static ch_mode_T
channel_get_mode(channel_T *channel, ch_part_T part)
{
if (channel == NULL)
! return MODE_JSON;
return channel->ch_part[part].ch_mode;
}

--- 5128,5140 ----

/*
* Return the mode of "channel"/"part"
! * If "channel" is invalid returns CH_MODE_JSON.
*/
static ch_mode_T
channel_get_mode(channel_T *channel, ch_part_T part)
{
if (channel == NULL)
! return CH_MODE_JSON;
return channel->ch_part[part].ch_mode;
}

*** ../vim-8.2.4908/src/job.c 2022-03-30 10:14:41.485657271 +0100
--- src/job.c 2022-05-07 16:29:28.677356209 +0100
***************
*** 24,38 ****

opt->jo_set |= jo;
if (STRCMP(val, "nl") == 0)
! *modep = MODE_NL;
else if (STRCMP(val, "raw") == 0)
! *modep = MODE_RAW;
else if (STRCMP(val, "js") == 0)
! *modep = MODE_JS;
else if (STRCMP(val, "json") == 0)
! *modep = MODE_JSON;
else if (STRCMP(val, "lsp") == 0)
! *modep = MODE_LSP;
else
{
semsg(_(e_invalid_argument_str), val);
--- 24,38 ----

opt->jo_set |= jo;
if (STRCMP(val, "nl") == 0)
! *modep = CH_MODE_NL;
else if (STRCMP(val, "raw") == 0)
! *modep = CH_MODE_RAW;
else if (STRCMP(val, "js") == 0)
! *modep = CH_MODE_JS;
else if (STRCMP(val, "json") == 0)
! *modep = CH_MODE_JSON;
else if (STRCMP(val, "lsp") == 0)
! *modep = CH_MODE_LSP;
else
{
semsg(_(e_invalid_argument_str), val);
***************
*** 1307,1313 ****
{
// Default mode is NL.
clear_job_options(&opt);
! opt.jo_mode = MODE_NL;
if (get_job_options(&argvars[1], &opt,
JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL + JO_STOPONEXIT
+ JO_EXIT_CB + JO_OUT_IO + JO_BLOCK_WRITE,
--- 1307,1313 ----
{
// Default mode is NL.
clear_job_options(&opt);
! opt.jo_mode = CH_MODE_NL;
if (get_job_options(&argvars[1], &opt,
JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL + JO_STOPONEXIT
+ JO_EXIT_CB + JO_OUT_IO + JO_BLOCK_WRITE,
*** ../vim-8.2.4908/src/terminal.c 2022-04-13 14:28:03.749082509 +0100
--- src/terminal.c 2022-05-07 16:27:04.853347954 +0100
***************
*** 326,332 ****

vim_snprintf((char *)buf, 100, "%dx%d",
term->tl_rows, term->tl_cols);
! set_option_value((char_u *)"termwinsize", 0L, buf, OPT_LOCAL);
}
}
}
--- 326,333 ----

vim_snprintf((char *)buf, 100, "%dx%d",
term->tl_rows, term->tl_cols);
! set_option_value_give_err((char_u *)"termwinsize",
! 0L, buf, OPT_LOCAL);
}
}
}
***************
*** 340,348 ****
{
clear_job_options(opt);

! opt->jo_mode = MODE_RAW;
! opt->jo_out_mode = MODE_RAW;
! opt->jo_err_mode = MODE_RAW;
opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
}

--- 341,349 ----
{
clear_job_options(opt);

! opt->jo_mode = CH_MODE_RAW;
! opt->jo_out_mode = CH_MODE_RAW;
! opt->jo_err_mode = CH_MODE_RAW;
opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE;
}

*** ../vim-8.2.4908/src/version.c 2022-05-07 15:43:48.973787528 +0100
--- src/version.c 2022-05-07 16:25:24.673334487 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4909,
/**/

--
hundred-and-one symptoms of being an internet addict:
128. You can access the Net -- via your portable and cellular phone.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages