MingaEditor.State.Tab.Context (Minga v0.1.0)

Copy Markdown View Source

Typed per-tab workspace snapshot stored on MingaEditor.State.Tab.

Contexts replace the old free-form map while still accepting legacy maps at API boundaries. present_fields records which workspace fields were actually present in a legacy map so partial migration inputs do not overwrite live workspace state with nil defaults.

Summary

Types

A document highlight range from the LSP server.

Workspace fields carried by a tab context.

Legacy map persisted or built before tab contexts became typed structs.

t()

Functions

Returns the active buffer pid represented by this context, when present.

Returns live buffer pids represented by this context.

Returns an empty context for a brand-new tab with no saved workspace yet.

Returns true when the context has no workspace fields to restore.

Returns the workspace field names represented by this context.

Normalizes a legacy context map into a typed context struct.

Creates a tab context directly from a workspace struct, without intermediate map conversion.

Builds the initial context for a semantic agent tab.

Builds an agent context around an already-constructed semantic window set.

Builds the initial context for a new file tab from the current workspace and viewport.

Returns a context with valid workspace field overrides applied.

Returns a context with every exact reference to the dead buffer retired when present.

Captures a complete tab snapshot, including a non-default shared agent projection.

Returns a workspace map containing only fields present in this context.

Returns workspace fields intentionally excluded from per-tab snapshotting.

Types

document_highlight()

@type document_highlight() :: Minga.LSP.DocumentHighlight.t()

A document highlight range from the LSP server.

field_name()

@type field_name() ::
  :keymap_scope
  | :buffers
  | :windows
  | :file_tree
  | :viewport
  | :mouse
  | :lsp_pending
  | :search
  | :editing
  | :feature_state
  | :document_highlights
  | :agent_ui

Workspace fields carried by a tab context.

legacy()

@type legacy() :: map()

Legacy map persisted or built before tab contexts became typed structs.

t()

@type t() :: %MingaEditor.State.Tab.Context{
  agent_ui: MingaEditor.Agent.UIState.t() | nil,
  buffers: MingaEditor.State.Buffers.t() | nil,
  document_highlights: [document_highlight()] | nil,
  editing: MingaEditor.VimState.t() | nil,
  feature_state: MingaEditor.FeatureState.t() | nil,
  file_tree: MingaEditor.State.FileTree.t() | nil,
  keymap_scope: Minga.Keymap.Scope.scope_name() | nil,
  lsp_pending: %{required(reference()) => atom() | tuple()} | nil,
  mouse: MingaEditor.State.Mouse.t() | nil,
  present_fields: [field_name()],
  search: MingaEditor.State.Search.t() | nil,
  version: pos_integer(),
  viewport: MingaEditor.Viewport.t() | nil,
  windows: MingaEditor.State.Windows.t() | nil
}

Functions

active_buffer_pid(context)

@spec active_buffer_pid(t() | legacy()) :: pid() | nil

Returns the active buffer pid represented by this context, when present.

buffer_pids(context)

@spec buffer_pids(t() | legacy()) :: [pid()]

Returns live buffer pids represented by this context.

empty()

@spec empty() :: t()

Returns an empty context for a brand-new tab with no saved workspace yet.

empty?(context)

@spec empty?(t() | legacy()) :: boolean()

Returns true when the context has no workspace fields to restore.

field_names()

@spec field_names() :: [field_name()]

Returns the workspace field names represented by this context.

from_map(context)

@spec from_map(t() | legacy()) :: t()

Normalizes a legacy context map into a typed context struct.

from_workspace(ws)

@spec from_workspace(MingaEditor.Session.State.t()) :: t()

Creates a tab context directly from a workspace struct, without intermediate map conversion.

from_workspace_map(map)

This function is deprecated. Use from_workspace/1 for struct inputs. This remains for legacy map inputs only..
@spec from_workspace_map(map()) :: t()

new_agent(viewport, project_root)

@spec new_agent(MingaEditor.Viewport.t(), String.t() | nil) :: t()

Builds the initial context for a semantic agent tab.

new_agent(viewport, project_root, windows)

@spec new_agent(
  MingaEditor.Viewport.t(),
  String.t() | nil,
  MingaEditor.State.Windows.t()
) :: t()

Builds an agent context around an already-constructed semantic window set.

new_file(workspace, viewport)

Builds the initial context for a new file tab from the current workspace and viewport.

put_fields(context, attrs)

@spec put_fields(t(), map() | keyword()) :: t()

Returns a context with valid workspace field overrides applied.

scrub_buffer(context, pid)

@spec scrub_buffer(t() | legacy(), pid()) :: t()

Returns a context with every exact reference to the dead buffer retired when present.

snapshot(workspace)

@spec snapshot(MingaEditor.Session.State.t()) :: t()

Captures a complete tab snapshot, including a non-default shared agent projection.

to_workspace_map(context)

@spec to_workspace_map(t() | legacy()) :: map()

Returns a workspace map containing only fields present in this context.

transient_fields()

@spec transient_fields() :: [atom()]

Returns workspace fields intentionally excluded from per-tab snapshotting.

These are transient pointer/frame state (#2630), never persisted or restored. Together with field_names/0 they must account for every Session.State field; the feature_state_test guard enforces that.