From eb7ed4f97aa86330cd29e29b23cdcf82cc507b30 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 17 Mar 2026 15:09:38 +0300 Subject: [PATCH] fix(client): add ListWorkspaces method to retrieve all workspaces from the server --- internal/client/proto.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/client/proto.go b/internal/client/proto.go index 7d6b7d95e0b88e6b8ced10046d19b0d3045e66e8..7a3b3a3c6b4b375c776ac6740f4d055858205941 100644 --- a/internal/client/proto.go +++ b/internal/client/proto.go @@ -22,6 +22,23 @@ import ( "github.com/charmbracelet/x/powernap/pkg/lsp/protocol" ) +// ListWorkspaces retrieves all workspaces from the server. +func (c *Client) ListWorkspaces(ctx context.Context) ([]proto.Workspace, error) { + rsp, err := c.get(ctx, "/workspaces", nil, nil) + if err != nil { + return nil, fmt.Errorf("failed to list workspaces: %w", err) + } + defer rsp.Body.Close() + if rsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("failed to list workspaces: status code %d", rsp.StatusCode) + } + var workspaces []proto.Workspace + if err := json.NewDecoder(rsp.Body).Decode(&workspaces); err != nil { + return nil, fmt.Errorf("failed to decode workspaces: %w", err) + } + return workspaces, nil +} + // CreateWorkspace creates a new workspace on the server. func (c *Client) CreateWorkspace(ctx context.Context, ws proto.Workspace) (*proto.Workspace, error) { rsp, err := c.post(ctx, "/workspaces", nil, jsonBody(ws), http.Header{"Content-Type": []string{"application/json"}})