MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / BlocksListCommand

Method BlocksListCommand

pkg/wshrpc/wshserver/wshserver.go:882–945  ·  view source on GitHub ↗

BlocksListCommand returns every block visible in the requested scope (current workspace by default).

(
	ctx context.Context,
	req wshrpc.BlocksListRequest)

Source from the content-addressed store, hash-verified

880// BlocksListCommand returns every block visible in the requested
881// scope (current workspace by default).
882func (ws *WshServer) BlocksListCommand(
883 ctx context.Context,
884 req wshrpc.BlocksListRequest) ([]wshrpc.BlocksListEntry, error) {
885 var results []wshrpc.BlocksListEntry
886
887 // Resolve the set of workspaces to inspect
888 var workspaceIDs []string
889 if req.WorkspaceId != "" {
890 workspaceIDs = []string{req.WorkspaceId}
891 } else if req.WindowId != "" {
892 win, err := wcore.GetWindow(ctx, req.WindowId)
893 if err != nil {
894 return nil, err
895 }
896 workspaceIDs = []string{win.WorkspaceId}
897 } else {
898 // "current" == first workspace in client focus list
899 client, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
900 if err != nil {
901 return nil, err
902 }
903 if len(client.WindowIds) == 0 {
904 return nil, fmt.Errorf("no active window")
905 }
906 win, err := wcore.GetWindow(ctx, client.WindowIds[0])
907 if err != nil {
908 return nil, err
909 }
910 workspaceIDs = []string{win.WorkspaceId}
911 }
912
913 for _, wsID := range workspaceIDs {
914 wsData, err := wcore.GetWorkspace(ctx, wsID)
915 if err != nil {
916 return nil, err
917 }
918
919 windowId, err := wstore.DBFindWindowForWorkspaceId(ctx, wsID)
920 if err != nil {
921 log.Printf("error finding window for workspace %s: %v", wsID, err)
922 }
923
924 for _, tabID := range wsData.TabIds {
925 tab, err := wstore.DBMustGet[*waveobj.Tab](ctx, tabID)
926 if err != nil {
927 return nil, err
928 }
929 for _, blkID := range tab.BlockIds {
930 blk, err := wstore.DBMustGet[*waveobj.Block](ctx, blkID)
931 if err != nil {
932 return nil, err
933 }
934 results = append(results, wshrpc.BlocksListEntry{
935 WindowId: windowId,
936 WorkspaceId: wsID,
937 TabId: tabID,
938 BlockId: blkID,
939 Meta: blk.Meta,

Callers

nothing calls this directly

Calls 4

GetWindowFunction · 0.92
GetWorkspaceFunction · 0.92
DBMustGetFunction · 0.92

Tested by

no test coverage detected