patch 8.2.4758: when using an LSP channel want to get the message ID
Problem: When using an LSP channel want to get the message ID.
Solution: Have ch_sendexpr() return the ID. (Yegappan Lakshmanan,
closes #10202)
diff --git a/src/channel.c b/src/channel.c
index 85089cb..ef747d0 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -4520,6 +4520,7 @@
ch_part_T part_read;
jobopt_T opt;
int timeout;
+ int callback_present = FALSE;
// return an empty string by default
rettv->v_type = VAR_STRING;
@@ -4546,7 +4547,9 @@
{
dict_T *d;
dictitem_T *di;
- int callback_present = FALSE;
+
+ // return an empty dict by default
+ rettv_dict_alloc(rettv);
if (argvars[1].v_type != VAR_DICT)
{
@@ -4629,6 +4632,14 @@
}
}
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
+ // message. The user can use this to cancel the request (if needed).
+ if (rettv->vval.v_dict != NULL)
+ dict_add_number(rettv->vval.v_dict, "id", id);
+ }
}
/*