diff src/channel.c @ 28769:78fc778de076 v8.2.4909

patch 8.2.4909: MODE_ enum entries names are too generic Commit: https://github.com/vim/vim/commit/ac4174e166dd76c72907caa76db0e7cd878ac667 Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 7 16:38:24 2022 +0100 patch 8.2.4909: MODE_ enum entries names are too generic Problem: MODE_ enum entries names are too generic. Solution: use CH_MODE_.
author Bram Moolenaar <Bram@vim.org>
date Sat, 07 May 2022 17:45:02 +0200
parents 352806724e12
children d0241e74bfdb
line wrap: on
line diff
--- a/src/channel.c
+++ b/src/channel.c
@@ -1274,7 +1274,7 @@ channel_set_options(channel_T *channel, 
 
 	// 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;
+	    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,7 +1320,7 @@ channel_set_options(channel_T *channel, 
 
 	// 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;
+	    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,7 +1445,7 @@ channel_open_func(typval_T *argvars)
 
     // parse options
     clear_job_options(&opt);
-    opt.jo_mode = MODE_JSON;
+    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,9 +2051,9 @@ channel_collapse(channel_T *channel, ch_
 
     last_node = node->rq_next;
     len = node->rq_buflen + last_node->rq_buflen;
-    if (want_nl || mode == MODE_LSP)
+    if (want_nl || mode == CH_MODE_LSP)
 	while (last_node->rq_next != NULL
-		&& (mode == MODE_LSP
+		&& (mode == CH_MODE_LSP
 		    || channel_first_nl(last_node) == NULL))
 	{
 	    last_node = last_node->rq_next;
@@ -2118,7 +2118,7 @@ channel_save(channel_T *channel, ch_part
 	return FAIL;	    // out of memory
     }
 
-    if (channel->ch_part[part].ch_mode == MODE_NL)
+    if (channel->ch_part[part].ch_mode == CH_MODE_NL)
     {
 	// Drop any CR before a NL.
 	p = node->rq_buffer;
@@ -2309,7 +2309,7 @@ channel_parse_json(channel_T *channel, c
     reader.js_cookie = channel;
     reader.js_cookie_arg = part;
 
-    if (chanpart->ch_mode == MODE_LSP)
+    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,20 +2320,20 @@ channel_parse_json(channel_T *channel, c
     {
 	++emsg_silent;
 	status = json_decode(&reader, &listtv,
-				chanpart->ch_mode == MODE_JS ? JSON_JS : 0);
+				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 == MODE_LSP && listtv.v_type != VAR_DICT)
+	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 != MODE_LSP &&
-		(listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2))
+	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,7 +2563,7 @@ channel_get_json(
 	list_T	    *l;
 	typval_T    *tv;
 
-	if (channel->ch_part[part].ch_mode != MODE_LSP)
+	if (channel->ch_part[part].ch_mode != CH_MODE_LSP)
 	{
 	    l = item->jq_value->vval.v_list;
 	    CHECK_LIST_MATERIALIZE(l);
@@ -2684,7 +2684,8 @@ channel_exe_cmd(channel_T *channel, ch_p
 {
     char_u  *cmd = argv[0].vval.v_string;
     char_u  *arg;
-    int	    options = channel->ch_part[part].ch_mode == MODE_JS ? JSON_JS : 0;
+    int	    options = channel->ch_part[part].ch_mode == CH_MODE_JS
+								 ? JSON_JS : 0;
 
     if (argv[1].v_type != VAR_STRING)
     {
@@ -2964,7 +2965,8 @@ channel_use_json_head(channel_T *channel
 {
     ch_mode_T	ch_mode = channel->ch_part[part].ch_mode;
 
-    return ch_mode == MODE_JSON || ch_mode == MODE_JS || ch_mode == MODE_LSP;
+    return ch_mode == CH_MODE_JSON || ch_mode == CH_MODE_JS
+						     || ch_mode == CH_MODE_LSP;
 }
 
 /*
@@ -3021,7 +3023,7 @@ may_invoke_callback(channel_T *channel, 
 	// Get any json message in the queue.
 	if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL)
 	{
-	    if (ch_mode == MODE_LSP)
+	    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,7 +3035,7 @@ may_invoke_callback(channel_T *channel, 
 		return FALSE;
 	}
 
-	if (ch_mode == MODE_LSP)
+	if (ch_mode == CH_MODE_LSP)
 	{
 	    dict_T	*d = listtv->vval.v_dict;
 	    dictitem_T	*di;
@@ -3092,7 +3094,7 @@ may_invoke_callback(channel_T *channel, 
 	    return FALSE;
 	}
 
-	if (ch_mode == MODE_NL)
+	if (ch_mode == CH_MODE_NL)
 	{
 	    char_u  *nl = NULL;
 	    char_u  *buf;
@@ -3169,7 +3171,7 @@ may_invoke_callback(channel_T *channel, 
 	    }
     }
 
-    if (seq_nr > 0 && (ch_mode != MODE_LSP || called_otc))
+    if (seq_nr > 0 && (ch_mode != CH_MODE_LSP || called_otc))
     {
 	if (!called_otc)
 	{
@@ -3356,11 +3358,11 @@ channel_part_info(channel_T *channel, di
     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;
+	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,18 +3903,18 @@ channel_read_block(
     readq_T	*node;
 
     ch_log(channel, "Blocking %s read, timeout: %d msec",
-				     mode == MODE_RAW ? "RAW" : "NL", timeout);
+				  mode == CH_MODE_RAW ? "RAW" : "NL", timeout);
 
     while (TRUE)
     {
 	node = channel_peek(channel, part);
 	if (node != NULL)
 	{
-	    if (mode == MODE_RAW || (mode == MODE_NL
+	    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 == MODE_NL) == OK)
+	    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,7 +3934,7 @@ channel_read_block(
     }
 
     // We have a complete message now.
-    if (mode == MODE_RAW || outlen != NULL)
+    if (mode == CH_MODE_RAW || outlen != NULL)
     {
 	msg = channel_get_all(channel, part, outlen);
     }
@@ -4014,7 +4016,7 @@ channel_read_json_block(
 
     for (;;)
     {
-	if (mode == MODE_LSP)
+	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,7 +4203,7 @@ common_channel_read(typval_T *argvars, t
 		vim_free(p);
 	    }
 	}
-	else if (raw || mode == MODE_RAW || mode == MODE_NL)
+	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,13 +4580,13 @@ ch_expr_common(typval_T *argvars, typval
     part_send = channel_part_send(channel);
 
     ch_mode = channel_get_mode(channel, part_send);
-    if (ch_mode == MODE_RAW || ch_mode == MODE_NL)
+    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 == MODE_LSP)
+    if (ch_mode == CH_MODE_LSP)
     {
 	dict_T		*d;
 	dictitem_T	*di;
@@ -4637,7 +4639,7 @@ ch_expr_common(typval_T *argvars, typval
     {
 	id = ++channel->ch_last_msg_id;
 	text = json_encode_nr_expr(id, &argvars[1],
-				(ch_mode == MODE_JS ? JSON_JS : 0) | JSON_NL);
+			      (ch_mode == CH_MODE_JS ? JSON_JS : 0) | JSON_NL);
     }
     if (text == NULL)
 	return;
@@ -4654,7 +4656,7 @@ ch_expr_common(typval_T *argvars, typval
 	if (channel_read_json_block(channel, part_read, timeout, id, &listtv)
 									== OK)
 	{
-	    if (ch_mode == MODE_LSP)
+	    if (ch_mode == CH_MODE_LSP)
 	    {
 		*rettv = *listtv;
 		// Change the type to avoid the value being freed.
@@ -4674,7 +4676,7 @@ ch_expr_common(typval_T *argvars, typval
 	}
     }
     free_job_options(&opt);
-    if (ch_mode == MODE_LSP && !eval && callback_present)
+    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,13 +5128,13 @@ channel_part_read(channel_T *channel)
 
 /*
  * Return the mode of "channel"/"part"
- * If "channel" is invalid returns MODE_JSON.
+ * 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 MODE_JSON;
+	return CH_MODE_JSON;
     return channel->ch_part[part].ch_mode;
 }