contentpanes

package
v1.15.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contentpanes owns the host-independent lifecycle of Sidecar's passive Document, Issue, Note, Diff, and Resource panes.

A Deck deliberately does not render or persist itself. Hosts provide the available box when opening a leaf, render the returned viewer models, and choose where the reference-only State is stored. All potentially expensive work is returned as tea.Cmd; New, Decode, PlanOpen, and Encode are pure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveDocument added in v1.12.0

func ResolveDocument(src Source, source SourceContext, pending contentlink.Pending) (contentlink.Ref, error)

ResolveDocument uses src, or LocalSource when src is nil.

Types

type AsyncID

type AsyncID struct {
	TabID      uint64
	Generation uint64
	Epoch      uint64
	Surface    string
}

AsyncID pins a result to the exact deck tab request that produced it. Tab IDs are never reused; Generation changes whenever that tab starts work.

type Config

type Config struct {
	Renderer         *markdown.Renderer
	ResourceResolver resourceview.Resolver
	// PluginCalls is how a collection or row tab reaches its protocol plugin.
	// It is injected for the same reason ResourceResolver is: the host's
	// describe pass finishes long after a restored tab is armed.
	PluginCalls resourceview.CallsFor
	// Source loads Document identity and bytes. Nil uses today's local
	// filepreview path so tests constructing Config{} keep working.
	Source Source
	// ConfigureViewer attaches host presentation behavior (for example issue
	// navigation handlers or Diff paint state). It must remain free of I/O.
	ConfigureViewer func(kind panelayout.Kind, model any)
}

Config supplies only replaceable viewer dependencies. Constructing a Deck remains free of filesystem, database, git, and provider work.

type Deck

type Deck struct {
	// contains filtered or unexported fields
}

Deck is one primary surface plus at most one homogeneous leaf for each passive content kind.

func Decode

func Decode(ctx SurfaceContext, cfg Config, state State) *Deck

Decode restores references in an armed state without starting any load. Unknown kinds and invalid tabs collapse out of the tree. If the surviving state has no primary leaf, Decode returns a safe primary-only deck. Hosts must return Deck.LoadVisible after Decode, or every restored pane stays on its loading placeholder until a later select happens to start work.

func New

func New(ctx SurfaceContext, cfg Config) *Deck

New constructs a primary-only deck without doing I/O.

func (*Deck) AdoptLayout added in v1.11.0

func (d *Deck) AdoptLayout(candidate *panelayout.Node) bool

func (*Deck) Apply

func (d *Deck) Apply(result Result) (tea.Cmd, bool)

Apply routes one load result to the exact live or hidden tab that requested it. It returns an optional, identity-wrapped follow-up command.

func (*Deck) ApplyBroadcast

func (d *Deck) ApplyBroadcast(payload any) tea.Cmd

ApplyBroadcast routes an existing viewer-owned broadcast message through every tab. Viewer identities decide whether it applies.

func (*Deck) CanAdoptLayout added in v1.11.0

func (d *Deck) CanAdoptLayout(candidate *panelayout.Node) bool

CanAdoptLayout validates a host-composed candidate without changing the deck. Modal hosts use it before touching their live tree, so adopting the passive projection cannot become a late partial-commit failure.

func (*Deck) CloseActive

func (d *Deck) CloseActive() bool

CloseActive closes the active tab. Closing the last tab forgets the pane and collapses its leaf; unlike HideFocused, no hidden snapshot survives.

func (*Deck) CloseTab

func (d *Deck) CloseTab(leafID, index int) bool

CloseTab closes a specific tab through the same last-tab collapse rule.

func (*Deck) ConfigureViewers

func (d *Deck) ConfigureViewers(configure func(panelayout.Kind, any))

func (*Deck) ContentSource added in v1.12.0

func (d *Deck) ContentSource() Source

ContentSource is the deck's Document source, defaulting to LocalSource.

func (*Deck) Context

func (d *Deck) Context() SurfaceContext

Context returns the current resolution identity.

func (*Deck) CycleFocus

func (d *Deck) CycleFocus(delta int) int

CycleFocus walks visible leaves in layout order and wraps.

func (*Deck) CycleTab

func (d *Deck) CycleTab(delta int) tea.Cmd

CycleTab moves the focused homogeneous tab strip and wraps.

func (*Deck) Encode

func (d *Deck) Encode() State

Encode projects the deck to references and view state only.

func (*Deck) FocusLeaf

func (d *Deck) FocusLeaf(id int) bool

FocusLeaf moves focus to a visible leaf.

func (*Deck) FocusedLeaf

func (d *Deck) FocusedLeaf() int

FocusedLeaf returns the leaf that owns outer keyboard focus.

func (*Deck) ForgetLeaf added in v1.3.0

func (d *Deck) ForgetLeaf(leafID int) bool

ForgetLeaf forgets a pane outright, dropping all its tabs and collapsing its leaf. Neither the live leaf nor any hidden snapshot survives.

func (*Deck) Hidden

func (d *Deck) Hidden(kind panelayout.Kind) bool

Hidden reports whether kind has a remembered, currently collapsed pane.

func (*Deck) HideFocused

func (d *Deck) HideFocused() bool

HideFocused collapses the focused passive leaf but remembers its tabs. A later Open of the same kind reuses that pane.

func (*Deck) Leaf

func (d *Deck) Leaf(kind panelayout.Kind) int

func (*Deck) LoadVisible added in v1.3.0

func (d *Deck) LoadVisible() []tea.Cmd

LoadVisible starts a load for the active tab of every visible pane that still needs one. Decode and SetContext arm viewers without I/O; hosts must return these commands or a visible pane sits on its placeholder until something else happens to select it.

func (*Deck) LoadVisibleKind added in v1.6.0

func (d *Deck) LoadVisibleKind(kind panelayout.Kind) []tea.Cmd

LoadVisibleKind is LoadVisible narrowed to one kind, for the moments when only one viewer's dependency has changed — a resource resolver arriving after startup — and re-focusing every other visible pane would be work the change did not ask for.

func (*Deck) Open

func (d *Deck) Open(ctx SurfaceContext, ref contentlink.Ref, placement Placement) Outcome

Open opens or focuses one homogeneous passive tab. A split is first applied to a clone and laid out against placement; refusal leaves tree, focus, hidden state, and tabs unchanged.

func (*Deck) OpenDocumentFile

func (d *Deck) OpenDocumentFile(ctx SurfaceContext, ref contentlink.Ref, placement Placement, file *os.File) Outcome

OpenDocumentFile opens a validated, already-open file through the ordinary Deck lifecycle. The returned command owns file when accepted.

func (*Deck) PlanOpen

func (d *Deck) PlanOpen(ref contentlink.Ref, boxes map[int]panelayout.Box) (panelayout.OpenPlan, bool)

PlanOpen exposes the shared placement answer without mutating the deck.

func (*Deck) ReloadFocused added in v1.3.0

func (d *Deck) ReloadFocused() tea.Cmd

ReloadFocused force-reloads the focused pane's active tab, including a tab already showing a document. It is the user-facing recovery for a pane stuck on its loading placeholder.

func (*Deck) ReplaceActive

func (d *Deck) ReplaceActive(ctx SurfaceContext, ref contentlink.Ref) Outcome

ReplaceActive retargets the active tab without changing the leaf geometry. Hosts use this for picker-style navigation where Enter replaces the current document while Shift+Enter remains the ordinary append operation.

func (*Deck) SelectTab

func (d *Deck) SelectTab(leafID, index int) tea.Cmd

SelectTab selects a tab and starts a deferred restore load when needed.

func (*Deck) SetContext

func (d *Deck) SetContext(ctx SurfaceContext) []tea.Cmd

SetContext changes the deck's async scope. Tabs are rebound to the new identity so in-flight results from the old context cannot land, and the active tab of every visible pane is asked to load. Hidden panes stay armed until they are shown. Loading visible tabs here is what keeps a sibling document from sitting on "Loading document…" after a split.

func (*Deck) SetPluginCalls added in v1.14.0

func (d *Deck) SetPluginCalls(calls resourceview.CallsFor)

SetPluginCalls rebinds how every Resource tab reaches its protocol plugin, for existing tabs and for the ones a later open creates. It is the collection shape's counterpart to SetResourceResolver, and it starts nothing for the same reason: a load whose command is dropped leaves the tab loading forever.

func (*Deck) SetRatio

func (d *Deck) SetRatio(splitID, ratio int) bool

func (*Deck) SetResourceResolver

func (d *Deck) SetResourceResolver(resolve resourceview.Resolver)

SetResourceResolver updates existing viewers and the factory used by future Resource tabs created after provider discovery completes.

Rebinding starts nothing. A deck that is on screen follows this with LoadVisibleKind(panelayout.Resource) and returns the commands, which is what finally resolves tabs armed before any provider was ready; a deck the host is only holding does not, because a load whose command is dropped would leave the tab loading forever.

func (*Deck) Tabs

func (d *Deck) Tabs(leafID int) ([]TabInfo, int)

Tabs returns the strip in display order and its active index. The returned slice is detached; viewer models remain the shared host-independent models.

func (*Deck) Tree

func (d *Deck) Tree() *panelayout.Node

Tree returns a detached layout tree so hosts cannot mutate deck ownership.

func (*Deck) Viewer

func (d *Deck) Viewer(leafID int) any

Viewer returns the active host-independent viewer model for a passive leaf. Its dynamic type is *docview.Model, *issueview.Model, *noteview.Model, *workspacediff.View, or *resourceview.Model.

type DiffPayload added in v1.12.0

type DiffPayload struct {
	Snapshot *workspacediff.Snapshot
	Commit   *workspacediff.CommitDetail
	RangeRaw string
	FileRaw  string
	FilePath string
}

DiffPayload is the typed diff body a shared viewer consumes.

type DiffReadRequest added in v1.12.0

type DiffReadRequest struct {
	Ref        contentlink.Ref
	Operation  string
	IfRevision string
	BaseRef    string
	Path       string
	ParentHash string
	Offset     int
	Limit      int
}

DiffReadRequest is one Diff resolve/load. Operation is a contentservice diff op; Path/ParentHash/Offset/Limit are operation-specific locators.

type DiffReadResult added in v1.12.0

type DiffReadResult struct {
	Value       DiffPayload
	Revision    string
	NotModified bool
}

DiffReadResult is a typed Diff payload. NotModified completes an in-flight refresh without replacing content.

type DocumentReadRequest added in v1.12.0

type DocumentReadRequest struct {
	Ref        contentlink.Ref
	IfRevision string
}

DocumentReadRequest is one Document resolve/load. IfRevision is the last adopted source revision and is empty on the first load.

type DocumentReadResult added in v1.12.0

type DocumentReadResult struct {
	Value       filepreview.PreviewResult
	Revision    string
	NotModified bool
}

DocumentReadResult is a typed Document payload the shared viewer consumes. NotModified completes an in-flight refresh without replacing content.

type IssuePayload added in v1.12.0

type IssuePayload struct {
	Data  *issueview.Data
	Owner *issueview.Owner
}

IssuePayload is the typed issue card a shared viewer consumes.

type IssueReadRequest added in v1.12.0

type IssueReadRequest struct {
	Ref        contentlink.Ref
	IfRevision string
	Fallbacks  []issueview.ProjectRef
}

IssueReadRequest is one Issue resolve/load. Fallbacks are local-only; a remote source ignores them and uses the host's config.

type IssueReadResult added in v1.12.0

type IssueReadResult struct {
	Value       IssuePayload
	Revision    string
	NotModified bool
}

IssueReadResult is a typed Issue payload. NotModified completes an in-flight refresh without replacing content.

type LocalSource added in v1.12.0

type LocalSource struct{}

LocalSource is the in-process Document adapter. It uses the same contentservice file contract as `sidecar content`, then highlights with this process's theme. A nil Config.Source also delegates here so tests constructing Config{} stay valid.

func (LocalSource) Describe added in v1.12.0

Describe is a no-op on the local adapter: Overview never asks a local row to spawn content describe. The empty fingerprint is stable.

func (LocalSource) GetCollectionItem added in v1.14.0

func (LocalSource) GetCollectionItem(ctx context.Context, src SourceContext, instance, collection, id string, refresh bool) (resource.Document, error)

GetCollectionItem expands one row through this process's own plugin manager.

func (LocalSource) ListCollection added in v1.14.0

func (LocalSource) ListCollection(ctx context.Context, src SourceContext, instance string, params contentservice.CollectionParams) (pluginhost.Page, error)

ListCollection lists through this process's own plugin manager. A local pane takes the app-injected calls instead of this path, for the reason ResolveResource gives below; this exists so the Source contract is complete and a caller that has only a Source never has to ask whether it is remote.

func (LocalSource) LoadDiff added in v1.12.0

LoadDiff reads through contentservice so local/direct and remote/JSON share git execution, revision, and notModified.

func (LocalSource) LoadDocument added in v1.12.0

LoadDocument reads through contentservice.ReadFile so local/direct and remote/JSON share containment, revision, and notModified.

func (LocalSource) LoadIssue added in v1.12.0

LoadIssue reads through contentservice.ReadIssue so local/direct and remote/JSON share fallback search, revision, and notModified.

func (LocalSource) LoadNote added in v1.12.0

LoadNote reads through contentservice.ReadNote so local/direct and remote/JSON share revision and notModified.

func (LocalSource) Resolve added in v1.12.0

Resolve maps a token onto identity on this machine. Issue and note ids are normalized without consulting td.

func (LocalSource) ResolveResource added in v1.12.0

func (LocalSource) ResolveResource(ctx context.Context, src SourceContext, ref resource.Reference, refresh bool) (resource.Document, error)

ResolveResource uses the host-side manager bound to this process's config. Overview local rows keep the app-injected resolver instead of this path.

type NodeState

type NodeState struct {
	Kind  string     `json:"kind,omitempty"`
	Axis  string     `json:"axis,omitempty"`
	Ratio int        `json:"ratio,omitempty"`
	A     *NodeState `json:"a,omitempty"`
	B     *NodeState `json:"b,omitempty"`
	Pane  *PaneState `json:"pane,omitempty"`
}

NodeState is a pane tree. Leaf Pane is omitted for the primary surface.

type NoteReadRequest added in v1.12.0

type NoteReadRequest struct {
	Ref        contentlink.Ref
	IfRevision string
}

NoteReadRequest is one Note resolve/load.

type NoteReadResult added in v1.12.0

type NoteReadResult struct {
	Value       *noteview.Data
	Revision    string
	NotModified bool
}

NoteReadResult is a typed Note payload. NotModified completes an in-flight refresh without replacing content.

type Outcome

type Outcome struct {
	Status      Status
	Refusal     Refusal
	Ref         contentlink.Ref
	Kind        panelayout.Kind
	LeafID      int
	TabID       uint64
	CreatedLeaf bool
	CreatedTab  bool
	Command     tea.Cmd
}

Outcome describes exactly what Open did. Command, when non-nil, performs the viewer load and returns a Result for Apply.

func (Outcome) Accepted

func (o Outcome) Accepted() bool

Accepted reports whether the deck accepted the target or delegated a valid action to the host.

type PaneState

type PaneState struct {
	Kind   string     `json:"kind"`
	Active int        `json:"active,omitempty"`
	Tabs   []TabState `json:"tabs"`
}

PaneState is one homogeneous passive tab strip.

type Placement

type Placement struct {
	Box    panelayout.Box
	Boxes  map[int]panelayout.Box
	Floors panelayout.Floors
	Split  string
	Plan   *panelayout.OpenPlan
}

Placement is the geometry against which a new split is trialled. Boxes are the last boxes by leaf ID and let panelayout choose the largest content leaf. Plan, when set, IS that choice: the open applies the caller's plan verbatim instead of re-running PlanOpen, so a host that validated a composed layout commits exactly the tree it fit-tested. A planned retarget must still name an existing pane of the kind, or the open refuses.

type Refusal

type Refusal string

Refusal is why Open made no change.

const (
	RefusalNone        Refusal = ""
	RefusalInvalid     Refusal = "invalid-reference"
	RefusalUnsupported Refusal = "unsupported-kind"
	RefusalPlacement   Refusal = "no-placement"
	RefusalFit         Refusal = "does-not-fit"
)

type RemoteRunner added in v1.12.0

type RemoteRunner func(ctx context.Context, hostID string, args []string, out any) error

RemoteRunner is the hosts.RunSidecar seam. Production binds hosts.Registry.RunSidecar; tests bind a recorder.

type RemoteSource added in v1.12.0

type RemoteSource struct {
	HostID string
	Verbs  hostproto.VerbCapabilities
	Run    RemoteRunner
}

RemoteSource is a Document source that reads through `sidecar content` verbs on a registered host.

func NewRemoteSource added in v1.12.0

func NewRemoteSource(hostID string, verbs hostproto.VerbCapabilities, run RemoteRunner) RemoteSource

NewRemoteSource builds a remote Document adapter. Capability is checked on each call so a host that advertised ContentReadV1 at hello and then rolled back is still refused.

func (RemoteSource) Describe added in v1.12.0

func (s RemoteSource) Describe(ctx context.Context, ifRevision string) (contentservice.DescribeResult, error)

func (RemoteSource) GetCollectionItem added in v1.14.0

func (s RemoteSource) GetCollectionItem(ctx context.Context, src SourceContext, instance, collection, id string, refresh bool) (resource.Document, error)

GetCollectionItem expands one row on the host that owns the pane.

func (RemoteSource) ListCollection added in v1.14.0

func (s RemoteSource) ListCollection(ctx context.Context, src SourceContext, instance string, params contentservice.CollectionParams) (pluginhost.Page, error)

ListCollection asks the host that owns the pane, over the connection Sidecar already holds open. It is the same journey ResolveResource takes, with the same refusal shape: the host runs its own plugin, and the answer that comes back is the page IT kept, already sanitized and already bounded.

func (RemoteSource) LoadDiff added in v1.12.0

func (RemoteSource) LoadDocument added in v1.12.0

func (RemoteSource) LoadIssue added in v1.12.0

func (RemoteSource) LoadNote added in v1.12.0

func (RemoteSource) Resolve added in v1.12.0

func (RemoteSource) ResolveResource added in v1.12.0

func (s RemoteSource) ResolveResource(ctx context.Context, src SourceContext, ref resource.Reference, refresh bool) (resource.Document, error)

type Result

type Result struct {
	ID      AsyncID
	Payload any
}

Result is the only asynchronous message a Deck consumes. Payload remains a viewer-owned type such as docview.LoadedMsg or resourceview.ResolvedMsg.

type Source added in v1.12.0

type Source interface {
	Resolve(context.Context, SourceContext, contentlink.Pending) (contentlink.Ref, error)
	LoadDocument(context.Context, SourceContext, DocumentReadRequest) (DocumentReadResult, error)
	LoadIssue(context.Context, SourceContext, IssueReadRequest) (IssueReadResult, error)
	LoadNote(context.Context, SourceContext, NoteReadRequest) (NoteReadResult, error)
	LoadDiff(context.Context, SourceContext, DiffReadRequest) (DiffReadResult, error)
	Describe(ctx context.Context, ifRevision string) (contentservice.DescribeResult, error)
	ResolveResource(ctx context.Context, src SourceContext, ref resource.Reference, refresh bool) (resource.Document, error)
	// ListCollection and GetCollectionItem are the plugin-protocol twins of
	// ResolveResource. A Resource leaf bound to a remote workspace must ask
	// THAT host's plugins, exactly as a resolve already does, or a collection
	// pane would quietly list this machine while its header named another.
	ListCollection(ctx context.Context, src SourceContext, instance string, params contentservice.CollectionParams) (pluginhost.Page, error)
	GetCollectionItem(ctx context.Context, src SourceContext, instance, collection, id string, refresh bool) (resource.Document, error)
}

Source is the Document/Issue/Note/Diff/Resource seam. Resolve returns identity only; it does not ship a body. Describe is host-level provider metadata. Local rows do not call Describe: the app manager is the matcher snapshot.

type SourceContext added in v1.12.0

type SourceContext struct {
	HostID          string
	HostIncarnation uint64
	ProjectKey      string
	ProjectRoot     string
	WorkspaceID     string
	WorkspaceKind   workspaceinventory.Kind
	WorkspaceKey    string
	Root            string
}

SourceContext is the host-qualified identity of the workspace a content pane was opened from. Empty HostID means this machine. HostIncarnation is the viewer registry client identity and is never serialized or sent as authority.

func (SourceContext) Remote added in v1.12.0

func (s SourceContext) Remote() bool

Remote reports whether this source lives on another machine.

type SourceState added in v1.12.0

type SourceState struct {
	HostID        string `json:"hostId,omitempty"`
	ProjectKey    string `json:"projectKey,omitempty"`
	ProjectRoot   string `json:"projectRoot,omitempty"`
	WorkspaceID   string `json:"workspaceId,omitempty"`
	WorkspaceKind string `json:"workspaceKind,omitempty"`
	WorkspaceKey  string `json:"workspaceKey,omitempty"`
	Root          string `json:"root,omitempty"`
}

SourceState is the durable half of SourceContext. HostIncarnation, loaded bodies, and rendered rows are never serialized.

type State

type State struct {
	Version   int          `json:"version"`
	Source    *SourceState `json:"source,omitempty"`
	Root      *NodeState   `json:"root,omitempty"`
	FocusKind string       `json:"focusKind,omitempty"`
	Hidden    []PaneState  `json:"hidden,omitempty"`
}

State is the reference-only persistence boundary for a Deck. It contains no loaded document, issue, diff, provider response, error, or rendered bytes.

type Status

type Status uint8

Status is the typed result of Open.

const (
	StatusRefused Status = iota
	StatusOpened
	StatusFocused
	// StatusAction means the reference is valid but is not a passive leaf.
	// URL and Internal refs are returned to the host for activation.
	StatusAction
)

type SurfaceContext

type SurfaceContext struct {
	Root        string
	DiffRoot    string
	Surface     string
	DiffSurface string
	BaseRef     string
	Epoch       uint64
	Source      SourceContext
}

SurfaceContext is the stable identity and resolution context for one deck. BaseRef is used only by working-tree Diff viewers. Source is the host-qualified workspace that later slices load from; empty HostID is local.

type TabInfo

type TabInfo struct {
	ID     uint64
	Ref    contentlink.Ref
	Viewer any
}

TabInfo is one tab as a host needs to render it. Viewer is intentionally the existing shared model rather than a second rendering interface.

type TabState

type TabState struct {
	Ref      contentlink.Ref `json:"ref"`
	Scroll   int             `json:"scroll,omitempty"`
	Wrap     bool            `json:"wrap,omitempty"`
	Rendered bool            `json:"rendered,omitempty"`
	Scope    string          `json:"scope,omitempty"`
	Mode     string          `json:"mode,omitempty"`
	Path     string          `json:"path,omitempty"`
	// OwnerName and OwnerRoot identify a cross-project issue tab's owning
	// store. Empty on a local issue. Restore reinstates the adoption before
	// the first load so the card does not re-run the search.
	OwnerName string `json:"ownerName,omitempty"`
	OwnerRoot string `json:"ownerRoot,omitempty"`
	// View, Sort, CursorID and Filters are a plugin collection tab's view position, the
	// rest of which (its query) is identity-adjacent enough to live on the Ref.
	// They are here for the reason Scope and Mode are: they are what the user
	// chose, not what the tab points at.
	View     string `json:"view,omitempty"`
	Sort     string `json:"sort,omitempty"`
	CursorID string `json:"cursorId,omitempty"`
	// Filters is the applied filter set the user chose, {id: value}. It sits
	// beside View and Sort for the same reason they do: it is a choice, not
	// part of what the tab points at.
	Filters map[string]string `json:"filters,omitempty"`
}

TabState contains target identity and user-owned view position only.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL