@@ -2,7 +2,6 @@ package builtin
22
33import (
44 "bufio"
5- "bytes"
65 "cmp"
76 "context"
87 "encoding/json"
@@ -20,6 +19,7 @@ import (
2019 "sync/atomic"
2120 "time"
2221
22+ "github.com/docker/docker-agent/pkg/concurrent"
2323 "github.com/docker/docker-agent/pkg/tools"
2424)
2525
@@ -492,8 +492,8 @@ func (h *lspHandler) startLocked() error {
492492 return fmt .Errorf ("failed to create stdout pipe: %w" , err )
493493 }
494494
495- var stderrBuf bytes .Buffer
496- cmd .Stderr = & stderrBuf
495+ stderrBuf := & concurrent .Buffer {}
496+ cmd .Stderr = stderrBuf
497497
498498 if err := cmd .Start (); err != nil {
499499 stdin .Close ()
@@ -506,7 +506,7 @@ func (h *lspHandler) startLocked() error {
506506 h .stdin = stdin
507507 h .stdout = bufio .NewReader (stdout )
508508
509- go h .readNotifications (processCtx , & stderrBuf )
509+ go h .readNotifications (processCtx , stderrBuf )
510510
511511 slog .Debug ("LSP server started successfully" )
512512 return nil
@@ -1432,7 +1432,7 @@ func (h *lspHandler) readMessageLocked() ([]byte, error) {
14321432 return body , nil
14331433}
14341434
1435- func (h * lspHandler ) readNotifications (ctx context.Context , stderrBuf * bytes .Buffer ) {
1435+ func (h * lspHandler ) readNotifications (ctx context.Context , stderrBuf * concurrent .Buffer ) {
14361436 ticker := time .NewTicker (100 * time .Millisecond )
14371437 defer ticker .Stop ()
14381438
@@ -1441,9 +1441,8 @@ func (h *lspHandler) readNotifications(ctx context.Context, stderrBuf *bytes.Buf
14411441 case <- ctx .Done ():
14421442 return
14431443 case <- ticker .C :
1444- if stderrBuf .Len () > 0 {
1445- slog .Debug ("LSP stderr" , "content" , stderrBuf .String ())
1446- stderrBuf .Reset ()
1444+ if content := stderrBuf .Drain (); content != "" {
1445+ slog .Debug ("LSP stderr" , "content" , content )
14471446 }
14481447 }
14491448 }
0 commit comments