1
0
forked from aniani/vim

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)
This commit is contained in:
Yegappan Lakshmanan
2022-04-16 10:41:27 +01:00
committed by Bram Moolenaar
parent b9e99e58bb
commit 3b470ae88f
5 changed files with 146 additions and 35 deletions

View File

@@ -4520,6 +4520,7 @@ ch_expr_common(typval_T *argvars, typval_T *rettv, int eval)
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 @@ ch_expr_common(typval_T *argvars, typval_T *rettv, int eval)
{
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 @@ ch_expr_common(typval_T *argvars, typval_T *rettv, int eval)
}
}
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);
}
}
/*