Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/wsh/cmd/wshcmd-getmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
Expand All @@ -24,9 +25,11 @@ var getMetaCmd = &cobra.Command{

var getMetaRawOutput bool
var getMetaClearPrefix bool
var getMetaVerbose bool

func init() {
rootCmd.AddCommand(getMetaCmd)
getMetaCmd.Flags().BoolVarP(&getMetaVerbose, "verbose", "v", false, "output full metadata")
getMetaCmd.Flags().BoolVar(&getMetaRawOutput, "raw", false, "output singleton string values without quotes")
getMetaCmd.Flags().BoolVar(&getMetaClearPrefix, "clear-prefix", false, "output the special clearing key for prefix queries")
}
Expand Down Expand Up @@ -82,6 +85,9 @@ func getMetaRun(cmd *cobra.Command, args []string) (rtnErr error) {
if err != nil {
return err
}
if getMetaVerbose {
fmt.Fprintf(os.Stderr, "resolved-id: %s\n", fullORef.String())
}
resp, err := wshclient.GetMetaCommand(RpcClient, wshrpc.CommandGetMetaData{ORef: *fullORef}, &wshrpc.RpcOpts{Timeout: 2000})
if err != nil {
return fmt.Errorf("getting metadata: %w", err)
Expand Down
22 changes: 21 additions & 1 deletion pkg/wshrpc/wshserver/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (

const SimpleId_This = "this"
const SimpleId_Tab = "tab"
const SimpleId_Ws = "ws"
const SimpleId_Client = "client"

var (
simpleTabNumRe = regexp.MustCompile(`^tab:(\d{1,3})$`)
Expand All @@ -33,7 +35,7 @@ func parseSimpleId(simpleId string) (discriminator string, value string, err err
}

// Handle special keywords
if simpleId == SimpleId_This || simpleId == SimpleId_Tab {
if simpleId == SimpleId_This || simpleId == SimpleId_Tab || simpleId == SimpleId_Ws || simpleId == SimpleId_Client {
return "this", simpleId, nil
}

Expand Down Expand Up @@ -84,6 +86,24 @@ func resolveThis(ctx context.Context, data wshrpc.CommandResolveIdsData, value s
}
return &waveobj.ORef{OType: waveobj.OType_Tab, OID: tabId}, nil
}
if value == SimpleId_Ws {
tabId, err := wstore.DBFindTabForBlockId(ctx, data.BlockId)
if err != nil {
return nil, fmt.Errorf("error finding tab: %v", err)
}
wsId, err := wstore.DBFindWorkspaceForTabId(ctx, tabId)
if err != nil {
return nil, fmt.Errorf("error finding workspace: %v", err)
}
return &waveobj.ORef{OType: waveobj.OType_Workspace, OID: wsId}, nil
}
if value == SimpleId_Client {
client, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
if err != nil {
return nil, fmt.Errorf("error getting client: %v", err)
}
return &waveobj.ORef{OType: waveobj.OType_Client, OID: client.OID}, nil
}
return nil, fmt.Errorf("invalid value for 'this' resolver: %s", value)
}

Expand Down