@@ -2035,22 +2035,24 @@ channel_consume(channel_T *channel, ch_part_T part, int len)
20352035 int
20362036channel_collapse (channel_T * channel , ch_part_T part , int want_nl )
20372037{
2038- readq_T * head = & channel -> ch_part [part ].ch_head ;
2039- readq_T * node = head -> rq_next ;
2040- readq_T * last_node ;
2041- readq_T * n ;
2042- char_u * newbuf ;
2043- char_u * p ;
2044- long_u len ;
2038+ ch_mode_T mode = channel -> ch_part [part ].ch_mode ;
2039+ readq_T * head = & channel -> ch_part [part ].ch_head ;
2040+ readq_T * node = head -> rq_next ;
2041+ readq_T * last_node ;
2042+ readq_T * n ;
2043+ char_u * newbuf ;
2044+ char_u * p ;
2045+ long_u len ;
20452046
20462047 if (node == NULL || node -> rq_next == NULL )
20472048 return FAIL ;
20482049
20492050 last_node = node -> rq_next ;
20502051 len = node -> rq_buflen + last_node -> rq_buflen ;
2051- if (want_nl )
2052+ if (want_nl || mode == MODE_LSP )
20522053 while (last_node -> rq_next != NULL
2053- && channel_first_nl (last_node ) == NULL )
2054+ && (mode == MODE_LSP
2055+ || channel_first_nl (last_node ) == NULL ))
20542056 {
20552057 last_node = last_node -> rq_next ;
20562058 len += last_node -> rq_buflen ;
@@ -3006,6 +3008,12 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
30063008 // Get any json message in the queue.
30073009 if (channel_get_json (channel , part , -1 , FALSE, & listtv ) == FAIL )
30083010 {
3011+ if (ch_mode == MODE_LSP )
3012+ // In the "lsp" mode, the http header and the json payload may
3013+ // be received in multiple messages. So concatenate all the
3014+ // received messages.
3015+ (void )channel_collapse (channel , part , FALSE);
3016+
30093017 // Parse readahead, return when there is still no message.
30103018 channel_parse_json (channel , part );
30113019 if (channel_get_json (channel , part , -1 , FALSE, & listtv ) == FAIL )
@@ -3974,6 +3982,7 @@ channel_read_json_block(
39743982 sock_T fd ;
39753983 int timeout ;
39763984 chanpart_T * chanpart = & channel -> ch_part [part ];
3985+ ch_mode_T mode = channel -> ch_part [part ].ch_mode ;
39773986 int retval = FAIL ;
39783987
39793988 ch_log (channel , "Blocking read JSON for id %d" , id );
@@ -3984,6 +3993,12 @@ channel_read_json_block(
39843993
39853994 for (;;)
39863995 {
3996+ if (mode == MODE_LSP )
3997+ // In the "lsp" mode, the http header and the json payload may be
3998+ // received in multiple messages. So concatenate all the received
3999+ // messages.
4000+ (void )channel_collapse (channel , part , FALSE);
4001+
39874002 more = channel_parse_json (channel , part );
39884003
39894004 // search for message "id"
0 commit comments