@@ -24,7 +24,7 @@ type Stdio struct {
24
24
25
25
cmd * exec.Cmd
26
26
stdin io.WriteCloser
27
- stdout * bufio.Reader
27
+ stdout * bufio.Scanner
28
28
stderr io.ReadCloser
29
29
responses map [string ]chan * JSONRPCResponse
30
30
mu sync.RWMutex
@@ -39,7 +39,7 @@ type Stdio struct {
39
39
func NewIO (input io.Reader , output io.WriteCloser , logging io.ReadCloser ) * Stdio {
40
40
return & Stdio {
41
41
stdin : output ,
42
- stdout : bufio .NewReader (input ),
42
+ stdout : bufio .NewScanner (input ),
43
43
stderr : logging ,
44
44
45
45
responses : make (map [string ]chan * JSONRPCResponse ),
@@ -114,7 +114,7 @@ func (c *Stdio) spawnCommand(ctx context.Context) error {
114
114
c .cmd = cmd
115
115
c .stdin = stdin
116
116
c .stderr = stderr
117
- c .stdout = bufio .NewReader (stdout )
117
+ c .stdout = bufio .NewScanner (stdout )
118
118
119
119
if err := cmd .Start (); err != nil {
120
120
return fmt .Errorf ("failed to start command: %w" , err )
@@ -167,14 +167,18 @@ func (c *Stdio) readResponses() {
167
167
case <- c .done :
168
168
return
169
169
default :
170
- line , err := c .stdout .ReadString ('\n' )
170
+ if ! c .stdout .Scan () {
171
+ return
172
+ }
173
+
174
+ err := c .stdout .Err ()
171
175
if err != nil {
172
- if err != io .EOF {
173
- fmt .Printf ("Error reading response: %v\n " , err )
174
- }
176
+ fmt .Printf ("Error reading response: %v\n " , err )
175
177
return
176
178
}
177
179
180
+ line := c .stdout .Text ()
181
+
178
182
var baseMessage JSONRPCResponse
179
183
if err := json .Unmarshal ([]byte (line ), & baseMessage ); err != nil {
180
184
continue
0 commit comments