From 3c7904a97ac30313aad48836c221279d3a00f276 Mon Sep 17 00:00:00 2001 From: Patrick Haun Date: Fri, 18 Oct 2024 20:30:33 +0200 Subject: [PATCH] fix: need to forward some env vars --- nvimwrapper/nvim.go | 27 ++++++++++++++++++++++++++- server/server.go | 5 +++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/nvimwrapper/nvim.go b/nvimwrapper/nvim.go index 8ef55dd..3b86819 100644 --- a/nvimwrapper/nvim.go +++ b/nvimwrapper/nvim.go @@ -5,6 +5,7 @@ import ( "fmt" "log/slog" "maps" + "os" "os/exec" "strings" "sync" @@ -63,9 +64,25 @@ func (r NvimResult) Col() int { return r.CursorPosition[1] } +func forwardEnv() []string { + + forwardVars := []string{"DOCKER_HOST"} + + env := []string{} + + for _, varName := range forwardVars { + varValue := os.Getenv(varName) + env = append(env, fmt.Sprintf("DOCKER_HOST=%s", varValue)) + } + slog.Info("Spawn with env", "env", env) + + return env + +} + func spawnExternal(cmdline string, args []string) (*nvim.Nvim, error) { cmdCtx := exec.CommandContext(context.Background(), cmdline, args...) - cmdCtx.Env = []string{} + cmdCtx.Env = forwardEnv() cmdCtx.Dir = "" inw, err := cmdCtx.StdinPipe() @@ -79,6 +96,14 @@ 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) + err = cmdCtx.Start() if err != nil { return nil, err diff --git a/server/server.go b/server/server.go index e8920ca..d9599ac 100644 --- a/server/server.go +++ b/server/server.go @@ -8,6 +8,7 @@ import ( "log/slog" "net/http" "os" + "time" "github.com/brocode/neoweb/components" "github.com/brocode/neoweb/key" @@ -26,6 +27,10 @@ func NewServer() *Server { nvimWrapper, err := nvimwrapper.Spawn() if err != nil { slog.Error("Failed to spawn neovim", "Error", err) + + // TODO this sleep is so that async stuff can print errors. + // Need to remove the entire nvim spawn handling anyway + time.Sleep(1 * time.Second) os.Exit(1) }