@@ -567,6 +567,13 @@ channel_read_json(int ch_idx)
567567 }
568568 }
569569 }
570+
571+ /* Put the unread part back into the channel.
572+ * TODO: insert in front */
573+ if (reader .js_buf [reader .js_used ] != NUL )
574+ channel_save (ch_idx , reader .js_buf + reader .js_used ,
575+ (int )(reader .js_end - reader .js_buf ) - reader .js_used );
576+ vim_free (reader .js_buf );
570577}
571578
572579/*
@@ -697,8 +704,9 @@ channel_exe_cmd(int idx, char_u *cmd, typval_T *arg2, typval_T *arg3)
697704
698705/*
699706 * Invoke a callback for channel "idx" if needed.
707+ * Return OK when a message was handled, there might be another one.
700708 */
701- static void
709+ static int
702710may_invoke_callback (int idx )
703711{
704712 char_u * msg = NULL ;
@@ -710,30 +718,30 @@ may_invoke_callback(int idx)
710718 int json_mode = channels [idx ].ch_json_mode ;
711719
712720 if (channel_peek (idx ) == NULL )
713- return ;
721+ return FALSE ;
714722 if (channels [idx ].ch_close_cb != NULL )
715723 /* this channel is handled elsewhere (netbeans) */
716- return ;
724+ return FALSE ;
717725
718726 if (json_mode )
719727 {
720728 /* Get any json message. Return if there isn't one. */
721729 channel_read_json (idx );
722730 if (channel_get_json (idx , -1 , & listtv ) == FAIL )
723- return ;
731+ return FALSE ;
724732 if (listtv -> v_type != VAR_LIST )
725733 {
726734 /* TODO: give error */
727735 clear_tv (listtv );
728- return ;
736+ return FALSE ;
729737 }
730738
731739 list = listtv -> vval .v_list ;
732740 if (list -> lv_len < 2 )
733741 {
734742 /* TODO: give error */
735743 clear_tv (listtv );
736- return ;
744+ return FALSE ;
737745 }
738746
739747 argv [1 ] = list -> lv_first -> li_next -> li_tv ;
@@ -748,14 +756,14 @@ may_invoke_callback(int idx)
748756 arg3 = & list -> lv_last -> li_tv ;
749757 channel_exe_cmd (idx , cmd , & argv [1 ], arg3 );
750758 clear_tv (listtv );
751- return ;
759+ return TRUE ;
752760 }
753761
754762 if (typetv -> v_type != VAR_NUMBER )
755763 {
756764 /* TODO: give error */
757765 clear_tv (listtv );
758- return ;
766+ return FALSE ;
759767 }
760768 seq_nr = typetv -> vval .v_number ;
761769 }
@@ -785,6 +793,8 @@ may_invoke_callback(int idx)
785793 if (listtv != NULL )
786794 clear_tv (listtv );
787795 vim_free (msg );
796+
797+ return TRUE;
788798}
789799
790800/*
@@ -1244,7 +1254,8 @@ channel_parse_messages(void)
12441254 int i ;
12451255
12461256 for (i = 0 ; i < channel_count ; ++ i )
1247- may_invoke_callback (i );
1257+ while (may_invoke_callback (i ) == OK )
1258+ ;
12481259}
12491260
12501261#endif /* FEAT_CHANNEL */
0 commit comments