Skip to content

ctx.workspaces

Read and drive workspace state through WorkspaceService — create/rename/close workspaces, manage their folders, and subscribe to a frozen snapshot. (Opening editor tabs lives on ctx.editors, not here.)

ts
ctx.workspaces: WorkspaceService

Example

tsx
import { useServiceState } from "@silo-code/sdk";

// read workspace state reactively in a component
function OpenCount() {
  const state = useServiceState(ctx.workspaces);
  return <span>{state.open.length} open</span>;
}

// or observe changes imperatively
const sub = ctx.workspaces.subscribe((state) => {
  console.log(state.open.length, "open workspaces");
});

Methods

On ctx.workspaces. Method names link to the full signature.

MethodWhat it does
getState()Current frozen WorkspaceState.
subscribe(listener)Observe changes; returns a Disposable.
get(id)One-shot lookup of a workspace by id (for reactive reads, prefer the state).
create(input)Create a workspace from a folder + name.
createFromFolderPicker()Show a folder picker, then create.
rename(id, name)Rename a workspace.
reorder(from, to, position)Reorder workspaces.
activate(id)Activate (and reopen if closed).
close(id)Soft close — hidden but still saved.
reopen(id)Reverse of close.
delete(id)Hard delete — permanent removal.
addFolder(id, folder)Add an extra folder to a workspace.
removeFolder(id, folder)Remove an extra folder.

State

The readable state — a frozen WorkspaceState from getState(), subscribe, or useServiceState:

PropertyTypeWhat it is
allreadonly Workspace[]every workspace, in user order
openreadonly Workspace[]open workspaces (not closed)
closedreadonly Workspace[]closed workspaces, most-recent first
activeIdstring | nullid of the active workspace
hydratedbooleantrue once persisted state has loaded

Types

Pass WorkspaceService.

Related: WorkspaceState · CreateWorkspaceInput · OpenFileOptions.

See also

Other State members on ctx.