Skip to content

Commit

Permalink
WIP: debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnStarich committed Feb 21, 2022
1 parent 9a150f5 commit 909d19d
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 35 deletions.
46 changes: 25 additions & 21 deletions cmd/editor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func main() {

consoleBuilder := terminal.New(newXTermFunc)
taskConsoleBuilder := taskconsole.New()
win, tasks := ide.New(app, editorBuilder, consoleBuilder, taskConsoleBuilder)
win, _ := ide.New(app, editorBuilder, consoleBuilder, taskConsoleBuilder)

if _, err := tasks.Start(goBinaryPath, "go", "version"); err != nil {
log.Error("Failed to start go version: ", err)
return
}
//if _, err := tasks.Start(goBinaryPath, "go", "version"); err != nil {
//log.Error("Failed to start go version: ", err)
//return
//}

if err := os.MkdirAll("playground", 0700); err != nil {
log.Error("Failed to make playground dir", err)
Expand All @@ -62,15 +62,17 @@ func main() {
return
}

_, err := os.Stat("go.mod")
makeNewModule := os.IsNotExist(err)
if makeNewModule {
_, err := tasks.Start(goBinaryPath, "go", "mod", "init", "playground")
if err != nil {
log.Error("Failed to start module init: ", err)
return
/*
_, err := os.Stat("go.mod")
makeNewModule := os.IsNotExist(err)
if makeNewModule {
_, err := tasks.Start(goBinaryPath, "go", "mod", "init", "playground")
if err != nil {
log.Error("Failed to start module init: ", err)
return
}
}
}
*/

if _, err := os.Stat("main.go"); os.IsNotExist(err) {
mainGoContents := `package main
Expand All @@ -92,17 +94,19 @@ func main() {
}
}

if makeNewModule {
_, err := tasks.Start(goBinaryPath, "go", "mod", "tidy")
if err != nil {
log.Error("Failed to start go mod tidy: ", err)
return
/*
if makeNewModule {
_, err := tasks.Start(goBinaryPath, "go", "mod", "tidy")
if err != nil {
log.Error("Failed to start go mod tidy: ", err)
return
}
}
}
*/

win.NewConsole()
//win.NewConsole()
editor := win.NewEditor()
err = editor.OpenFile("main.go")
err := editor.OpenFile("main.go")
if err != nil {
log.Error("Failed to open main.go in editor: ", err)
}
Expand Down
6 changes: 4 additions & 2 deletions internal/js/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ func (p *workerProcess) Start() (err error) {
message["files"] = true
}

log.Warn("Starting process:", message)
log.Print("Starting process:", message)
log.PrintJSValues("kernel start proc message", message)
// TODO is p.kernel definitely the right port? this needs to be received by the kernel, but it's not making it there. in fact, seems like _nothing_ makes it there
resp, err := jsworker.DoRequest(context.Background(), p.kernel, js.ValueOf(message), nil)
log.Warn("Process started:", resp, err)
log.Print("Process started:", resp, err)
if err != nil {
p.startErr = err
return err
Expand Down
2 changes: 2 additions & 0 deletions internal/js/process/spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (

"github.com/hack-pad/hackpad/internal/fs"
"github.com/hack-pad/hackpad/internal/interop"
"github.com/hack-pad/hackpad/internal/log"
"github.com/hack-pad/hackpad/internal/process"
"github.com/pkg/errors"
)

func spawn(args []js.Value) (interface{}, error) {
log.Warn("spawn call received")
if len(args) == 0 {
return nil, errors.Errorf("Invalid number of args, expected command name: %v", args)
}
Expand Down
7 changes: 6 additions & 1 deletion internal/jsworker/message_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ func wrapMessagePort(v js.Value, source, destination string) (*MessagePort, erro
func (p *MessagePort) debug(args ...interface{}) {
destination := fmt.Sprintf("(%s->%s) ", p.sourceName, p.destinationName)
args = append([]interface{}{destination}, args...)
log.Print(args...)
callers := log.Callers(1, 10)
var groupArgs [][]interface{}
for _, c := range callers {
groupArgs = append(groupArgs, []interface{}{c})
}
log.PrintGroup(fmt.Sprintln(args...), groupArgs...)
}

func (p *MessagePort) PostMessage(message js.Value, transfers []js.Value) (err error) {
Expand Down
4 changes: 4 additions & 0 deletions internal/jsworker/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func DoRequest(ctx context.Context, port *MessagePort, req js.Value, transfers [
id := newID()
var resp messageRequest
err := port.Listen(ctx, func(ev MessageEvent, err error) {
log.Print("Port Listen DoRequest")
message := parseMessageRequest(ev.Data)
if message.IsRequest { // only listen for responses, ignore requests
return
Expand All @@ -99,6 +100,7 @@ func DoRequest(ctx context.Context, port *MessagePort, req js.Value, transfers [
return js.Value{}, err
}

log.Print("Listening DoRequest")
err = port.PostMessage(messageRequest{
ID: id,
Data: req,
Expand All @@ -107,7 +109,9 @@ func DoRequest(ctx context.Context, port *MessagePort, req js.Value, transfers [
if err != nil {
return js.Value{}, err
}
log.Print("Awaiting response")
<-ctx.Done()
log.Print("DoReq response received")
if !receivedResponse {
resp.Err = ctx.Err()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/kernel/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kernel
type Op int

const (
OpStartProcess Op = iota + 1
OpStartProcess Op = iota + 64 // arbitrarily higher than worker op codes, to help find mistakes
OpStartCoprocess
OpWaitProcess
)
2 changes: 2 additions & 0 deletions kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func newKernelHandler(workers *jsworker.Manager, port *jsworker.MessagePort) jsw
}

func (k kernelHandler) Handle(req jsworker.RequestData) (response js.Value, transfers []js.Value, responseErr error) {
log.Warn("kernel received message")
panic("how is this not being hit?")
if req.Err != nil {
log.Error("Received error: ", req.Err)
return
Expand Down
30 changes: 21 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"syscall/js"
"time"

"github.com/hack-pad/hackpad/internal/common"
"github.com/hack-pad/hackpad/internal/global"
"github.com/hack-pad/hackpad/internal/interop"
jsfs "github.com/hack-pad/hackpad/internal/js/fs"
Expand All @@ -21,7 +22,7 @@ import (
func main() {
start := time.Now()

processPort, kernelPort, err := jsworker.NewChannel("kernel", "dom")
processPort, kernelPort, err := jsworker.NewChannel("dom", "kernel")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -79,15 +80,26 @@ func main() {
}
log.Printf("Startup took %.2f seconds", time.Since(start).Seconds())

go func() {
v, err := jsprocess.Spawn("editor", []string{"editor", "--editor=editor"}, &process.ProcAttr{
SameWorker: true,
})
if err != nil {
panic(err)
}
log.PrintJSValues("spawned editor:", v)
//go func() {
//v, err := jsprocess.Spawn("editor", []string{"editor", "--editor=editor"}, &process.ProcAttr{
//SameWorker: true,
//})
//if err != nil {
//panic(err)
//}
//log.PrintJSValues("spawned editor:", v)
//}()

err = func() (err error) {
defer common.CatchException(&err)
js.Global().Get("child_process").Call("spawn", "go")
return nil
}()
if err != nil {
log.Error("Failed go command:", err)
panic(err)
}
log.Print("done spawning")

select {}
}
2 changes: 1 addition & 1 deletion worker_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func startWorkerListener(kernelPort *jsworker.MessagePort) error {
_ = kernelPort.PostMessage(js.ValueOf("ready"), nil)
},
func(req jsworker.RequestData) (response js.Value, transfers []js.Value, responseErr error) {
log.Warn("DOM worker received message")
if req.Err != nil {
log.Error("Received error: ", req.Err)
return js.Value{}, nil, nil
Expand Down Expand Up @@ -72,7 +73,6 @@ func doRequest(data js.Value) (js.Value, []js.Value, error) {

cache := jsBoolProp(data, "cache")
for _, mountPath := range mountPaths {
log.Warn("DOM overlaying FSs: ", mountPath)
err := overlayIDB(context.Background(), mountPath, 0600, cache)
if err != nil {
return js.Value{}, nil, err
Expand Down

0 comments on commit 909d19d

Please sign in to comment.