Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log stderr of nvim process #4

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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