Mercurial > vim
comparison src/eval.c @ 7933:1f0743f4f88f v7.4.1262
commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Feb 5 21:04:08 2016 +0100
patch 7.4.1262
Problem: The channel callback is not invoked.
Solution: Make a list of pending callbacks.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 05 Feb 2016 21:15:04 +0100 |
parents | 2679e636e862 |
children | 3f2e0b62003d |
comparison
equal
deleted
inserted
replaced
7932:77f8fc004593 | 7933:1f0743f4f88f |
---|---|
9798 * common for "sendexpr()" and "sendraw()" | 9798 * common for "sendexpr()" and "sendraw()" |
9799 * Returns the channel index if the caller should read the response. | 9799 * Returns the channel index if the caller should read the response. |
9800 * Otherwise returns -1. | 9800 * Otherwise returns -1. |
9801 */ | 9801 */ |
9802 static int | 9802 static int |
9803 send_common(typval_T *argvars, char_u *text, char *fun) | 9803 send_common(typval_T *argvars, char_u *text, int id, char *fun) |
9804 { | 9804 { |
9805 int ch_idx; | 9805 int ch_idx; |
9806 char_u *callback = NULL; | 9806 char_u *callback = NULL; |
9807 | 9807 |
9808 ch_idx = get_channel_arg(&argvars[0]); | 9808 ch_idx = get_channel_arg(&argvars[0]); |
9813 { | 9813 { |
9814 callback = get_callback(&argvars[2]); | 9814 callback = get_callback(&argvars[2]); |
9815 if (callback == NULL) | 9815 if (callback == NULL) |
9816 return -1; | 9816 return -1; |
9817 } | 9817 } |
9818 /* Set the callback or clear it. An empty callback means no callback and | 9818 /* Set the callback. An empty callback means no callback and not reading |
9819 * not reading the response. */ | 9819 * the response. */ |
9820 channel_set_req_callback(ch_idx, | 9820 if (callback != NULL && *callback != NUL) |
9821 callback != NULL && *callback == NUL ? NULL : callback); | 9821 channel_set_req_callback(ch_idx, callback, id); |
9822 | 9822 |
9823 if (channel_send(ch_idx, text, fun) == OK && callback == NULL) | 9823 if (channel_send(ch_idx, text, fun) == OK && callback == NULL) |
9824 return ch_idx; | 9824 return ch_idx; |
9825 return -1; | 9825 return -1; |
9826 } | 9826 } |
9843 id = channel_get_id(); | 9843 id = channel_get_id(); |
9844 text = json_encode_nr_expr(id, &argvars[1]); | 9844 text = json_encode_nr_expr(id, &argvars[1]); |
9845 if (text == NULL) | 9845 if (text == NULL) |
9846 return; | 9846 return; |
9847 | 9847 |
9848 ch_idx = send_common(argvars, text, "sendexpr"); | 9848 ch_idx = send_common(argvars, text, id, "sendexpr"); |
9849 vim_free(text); | 9849 vim_free(text); |
9850 if (ch_idx >= 0) | 9850 if (ch_idx >= 0) |
9851 { | 9851 { |
9852 if (channel_read_json_block(ch_idx, id, &listtv) == OK) | 9852 if (channel_read_json_block(ch_idx, id, &listtv) == OK) |
9853 { | 9853 { |
9881 /* return an empty string by default */ | 9881 /* return an empty string by default */ |
9882 rettv->v_type = VAR_STRING; | 9882 rettv->v_type = VAR_STRING; |
9883 rettv->vval.v_string = NULL; | 9883 rettv->vval.v_string = NULL; |
9884 | 9884 |
9885 text = get_tv_string_buf(&argvars[1], buf); | 9885 text = get_tv_string_buf(&argvars[1], buf); |
9886 ch_idx = send_common(argvars, text, "sendraw"); | 9886 ch_idx = send_common(argvars, text, 0, "sendraw"); |
9887 if (ch_idx >= 0) | 9887 if (ch_idx >= 0) |
9888 rettv->vval.v_string = channel_read_block(ch_idx); | 9888 rettv->vval.v_string = channel_read_block(ch_idx); |
9889 } | 9889 } |
9890 #endif | 9890 #endif |
9891 | 9891 |