Skip to content

Commit

Permalink
fix: formatter websocket ctx
Browse files Browse the repository at this point in the history
Signed-off-by: Hemanth Krishna <[email protected]>
  • Loading branch information
DarthBenro008 committed Jul 5, 2023
1 parent 03c96a8 commit 26dca24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 8 additions & 0 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ type FormatResponse struct {
func fileFormatterController() func(c *websocket.Conn) {
return func(c *websocket.Conn) {
log.Println(c.RemoteAddr(), "Connection opened for format request!")
c.SetCloseHandler(func(code int, text string) error {
log.Printf("WebSocket connection for format closed with code %d and text: %s", code, text)
return nil
})
for {
mt, msg, err := c.ReadMessage()
if mt == websocket.CloseMessage|websocket.CloseGoingAway|websocket.CloseAbnormalClosure {
log.Println(c.RemoteAddr(), "Closing formatter websocket")
return
}
log.Println(c.RemoteAddr(), "Received format request!")

if err != nil {
Expand Down
8 changes: 2 additions & 6 deletions rust_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ package main

import (
"bytes"
"context"
"fmt"
"os/exec"
"strings"
"sync"
)

func runFormatter(inputCode string) ([]byte, error) {
var mutex sync.Mutex
mutex.Lock()
defer mutex.Unlock()

cmd := exec.Command("rustfmt")
cmd := exec.CommandContext(context.Background(), "rustfmt")
cmd.Stdin = strings.NewReader(inputCode)
var stdOut bytes.Buffer
cmd.Stdout = &stdOut
Expand Down

0 comments on commit 26dca24

Please sign in to comment.