Skip to content

Commit 7b90650

Browse files
committed
chore: enable debug logging on web server
1 parent cf7a1d4 commit 7b90650

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

cli/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (r *RootCmd) WebsocketServer() *serpent.Command {
4242
Hidden: true,
4343
Handler: func(i *serpent.Invocation) error {
4444
ctx := i.Context()
45-
logger := slog.Make(sloghuman.Sink(i.Stderr))
45+
logger := slog.Make(sloghuman.Sink(i.Stderr)).Leveled(slog.LevelDebug)
4646

4747
mux := chi.NewMux()
4848
mux.HandleFunc("/ws/{dir}", websocketHandler(logger))

types/parameter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type RichParameter struct {
4545
Name string `json:"name"`
4646
DisplayName string `json:"display_name"`
4747
Description string `json:"description"`
48+
FormControl string `json:"form_control"`
4849
Type ParameterType `json:"type"`
4950
Mutable bool `json:"mutable"`
5051
DefaultValue string `json:"default_value"`

web/session.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import (
1212
type Request struct {
1313
// ID identifies the request. The response contains the same
1414
// ID so that the client can match it to the request.
15-
ID int
16-
Inputs map[string]string
15+
ID int `json:"id"`
16+
Inputs map[string]string `json:"inputs"`
1717
}
1818

1919
type Response struct {
20+
ID int `json:"id"`
2021
Diagnostics Diagnostics `json:"diagnostics"`
2122
Parameters []types.Parameter `json:"parameters"`
2223
// TODO: Workspace tags
@@ -71,6 +72,7 @@ func (s *Session) preview(ctx context.Context, req *Request) Response {
7172
}, s.dir)
7273

7374
r := Response{
75+
ID: req.ID,
7476
Diagnostics: FromHCLDiagnostics(diags),
7577
}
7678
if output == nil {

web/typescripttypes/preview.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface RichParameter {
5959
readonly name: string;
6060
readonly display_name: string;
6161
readonly description: string;
62+
readonly form_control: string;
6263
readonly type: ParameterType;
6364
readonly mutable: boolean;
6465
readonly default_value: string;

web/websocket.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package web
22

33
import (
44
"context"
5-
"fmt"
6-
"time"
75

86
"cdr.dev/slog"
97
"github.com/coder/websocket"
@@ -24,9 +22,6 @@ func (s *Session) Listen(ctx context.Context, conn *websocket.Conn) {
2422
// write responses back
2523
go s.writeLoop(ctx, cancel, conn)
2624

27-
time.Sleep(time.Second)
28-
fmt.Println("CLOSE")
29-
3025
// Always close the connection at the end of the Listen.
3126
defer conn.Close(websocket.StatusNormalClosure, "closing connection")
3227
<-ctx.Done()
@@ -44,6 +39,10 @@ func (s *Session) readLoop(ctx context.Context, cancel func(), conn *websocket.C
4439
return
4540
}
4641

42+
s.logger.Debug(ctx, "received request",
43+
slog.F("id", req.ID),
44+
slog.F("inputs", req.Inputs),
45+
)
4746
s.sendRequest(ctx, req)
4847
}
4948
}

0 commit comments

Comments
 (0)