@@ -97,20 +97,19 @@ function! s:call_jsonrpc(method, ...) abort
97
97
let l: ch = s: state [' ch' ]
98
98
if has (' nvim' )
99
99
call chansend (l: ch , l: req_json )
100
- while len (s: state .data) == 0
101
- sleep 50 m
102
- if get (s: state , ' ready' , 0 ) == 0
103
- return
104
- endif
105
- endwhile
106
- let resp_json = s: state .data[0 ]
107
- let s: state .data = s: state .data[1 :]
108
100
else
109
101
call ch_sendraw (l: ch , req_json)
110
- let l: resp_raw = ch_readraw (l: ch )
111
- let resp_json = json_decode (l: resp_raw )
112
102
endif
113
103
104
+ while len (s: state .data) == 0
105
+ sleep 50 m
106
+ if get (s: state , ' ready' , 0 ) == 0
107
+ return
108
+ endif
109
+ endwhile
110
+ let resp_json = s: state .data[0 ]
111
+ let s: state .data = s: state .data[1 :]
112
+
114
113
if go#util#HasDebug (' debugger-commands' )
115
114
let g: go_debug_commands = add (go#config#DebugCommands (), {
116
115
\ ' request' : l: req_json ,
@@ -521,10 +520,10 @@ function! s:out_cb(ch, msg) abort
521
520
let s: state [' message' ] += [a: msg ]
522
521
523
522
if stridx (a: msg , go#config#DebugAddress ()) != -1
524
- if has (' nvim' )
525
- let s: state [' data' ] = []
526
- let l: state = {' databuf' : ' ' }
523
+ let s: state [' data' ] = []
524
+ let l: state = {' databuf' : ' ' }
527
525
526
+ if has (' nvim' )
528
527
" explicitly bind callback to state so that within it, self will
529
528
" always refer to state. See :help Partial for more information.
530
529
let l: state .on_data = function (' s:on_data' , [], l: state )
@@ -535,7 +534,10 @@ function! s:out_cb(ch, msg) abort
535
534
return
536
535
endif
537
536
else
538
- let l: ch = ch_open (go#config#DebugAddress (), {' mode' : ' raw' , ' timeout' : 20000 })
537
+ " explicitly bind callback to state so that within it, self will
538
+ " always refer to state. See :help Partial for more information.
539
+ let l: state .on_data = function (' s:on_data' , [], l: state )
540
+ let l: ch = ch_open (go#config#DebugAddress (), {' mode' : ' raw' , ' timeout' : 20000 , ' callback' : l: state .on_data})
539
541
if ch_status (l: ch ) !=# ' open'
540
542
call go#util#EchoError (" could not connect to debugger" )
541
543
call go#job#Stop (s: state [' job' ])
@@ -561,11 +563,10 @@ function! s:out_cb(ch, msg) abort
561
563
endif
562
564
endfunction
563
565
564
- function ! s: on_data (ch , data, event ) dict abort
565
- let l: data = self .databuf
566
- for l: msg in a: data
567
- let l: data .= l: msg
568
- endfor
566
+ " s:on_data's third optional argument is provided, but not used, so that the
567
+ " same function can be used for Vim's 'callback' and Neovim's 'data'.
568
+ function ! s: on_data (ch , data, ... ) dict abort
569
+ let l: data = s: message (self .databuf, a: data )
569
570
570
571
try
571
572
let l: res = json_decode (l: data )
@@ -579,6 +580,19 @@ function! s:on_data(ch, data, event) dict abort
579
580
endtry
580
581
endfunction
581
582
583
+ function ! s: message (buf , data) abort
584
+ let l: data = a: buf
585
+ if has (' nvim' )
586
+ for l: msg in a: data
587
+ let l: data .= l: msg
588
+ endfor
589
+
590
+ return l: data
591
+ endif
592
+
593
+ return printf (' %s%s' , a: buf , a: data )
594
+ endfunction
595
+
582
596
" Start the debug mode. The first argument is the package name to compile and
583
597
" debug, anything else will be passed to the running program.
584
598
function ! go#debug#Start (is_test, ... ) abort
0 commit comments