Skip to content

Commit

Permalink
feat: log stderr of nvim process
Browse files Browse the repository at this point in the history
  • Loading branch information
bomgar committed Oct 19, 2024
1 parent 01160c7 commit 658a076
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions nvimwrapper/nvim.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package nvimwrapper

import (
"bufio"
"context"
"fmt"
"io"
"log/slog"
"maps"
"os"
Expand Down Expand Up @@ -96,13 +98,11 @@ func spawnExternal(cmdline string, args []string) (*nvim.Nvim, error) {
return nil, err
}

// TODO: log this
// errr, err := cmdCtx.StderrPipe()
// if err != nil {
// return nil, err
// }
//
// go io.Copy(os.Stdout, errr)
errr, err := cmdCtx.StderrPipe()
if err != nil {
return nil, err
}
go logExternalCmdStdErr(errr)

err = cmdCtx.Start()
if err != nil {
Expand All @@ -124,6 +124,19 @@ func spawnExternal(cmdline string, args []string) (*nvim.Nvim, error) {
return v, nil
}

func logExternalCmdStdErr(errr io.Reader) {
scanner := bufio.NewScanner(errr)

for scanner.Scan() {
line := scanner.Text()
slog.Error("External process stderr", "line", line)
}

if scanner.Err() != nil {
slog.Error("Reading from external process failed", "err", scanner.Err())
}
}

func Spawn() (*NvimWrapper, error) {

args := []string{"run", "--rm", "-i", "nvim", "--embed"}
Expand Down

0 comments on commit 658a076

Please sign in to comment.