MingaEditor.Session.State (Minga v0.1.0)

Copy Markdown View Source

Core editing context that exists regardless of presentation.

A workspace is the editing state that gets saved/restored when switching tabs. It works identically whether rendered as a tab in the traditional editor, an extension shell surface, or running headless without any UI.

This struct formalizes the @per_tab_fields boundary from MingaEditor.State: every field here is snapshotted per tab and restored on tab switch.

Summary

Types

A leaf-owned buffer selection to activate in this session.

The pointer cell used to deduplicate Cmd/Ctrl-hover resolution.

Transient Cmd/Ctrl-hover go-to-definition link range.

A document highlight range from the LSP server.

A buffer position as {line, byte_col}.

t()

Functions

Activates a buffer selection and synchronizes every session-owned observation.

Returns the active window struct, or nil.

Clears the complete transient Cmd/Ctrl-hover observation.

Returns the focused window viewport or the supplied terminal fallback.

Removes one pending LSP request from the workspace correlation table.

Drops every extension-owned feature state entry.

Drops one source-owned feature state entry. Missing state is treated as inactive.

Drops all feature state owned by a source.

Resets FileTree UI state.

True when the workspace is showing the zero-buffers launchpad.

Enters the zero-buffers launchpad (#2689).

Returns the list of field names (for snapshot/restore compatibility).

Returns FileTree UI state.

Finds the semantic agent chat window, when one exists.

Commits focus to a surviving window after the active split was removed.

Commits a pure window-focus transition after its required buffer calls succeed.

Returns source-owned feature state, or nil when inactive.

Returns source-owned feature state, or a caller-provided default when inactive.

Invalidates render caches for all windows.

Marks the active window for authoritative scroll receipt handling.

Marks all window retained-GUI render caches reset-pending after frontend state loss.

Records a renderer observation for one session-owned window.

Stores source-owned feature state.

Adds one pending LSP request to the workspace correlation table.

Records a concrete source-owned feature value.

Stores the active buffer cursor in its matching active window.

Replaces every window showing a buffer with concrete values.

Replaces one session-owned window with a concrete value.

Restores a tab context into a workspace. Empty contexts are ignored by this pure helper; EditorState handles brand-new tab defaults because those need editor dimensions. Dead buffer pids in the restored context are scrubbed to prevent activating a dead process.

Forgets a retired process when it owns the agent prompt buffer.

Returns the appropriate keymap scope for the active window's content type.

Derives the keymap scope from a window's content type.

Scrolls the agent chat window viewport when one exists.

Updates the agent UI state.

Replaces the buffers sub-struct.

Records the pointer cell that produced the hover observation.

Records the transient Cmd/Ctrl-hover link range.

Updates the document highlights from LSP.

Replaces the editing (VimState) sub-struct.

Replaces the feature-state registry.

Replaces the FileTree UI state.

Sets the keymap scope.

Sets or clears the launchpad (zero-buffers empty state).

Updates the LSP pending requests map.

Updates the mouse sub-struct.

Updates the search sub-struct.

Sets the viewport dimensions.

Replaces the windows sub-struct.

Returns true if the workspace has more than one window.

Converts a workspace into a typed tab context suitable for storing on a MingaEditor.State.Tab and later restoring via restore_tab_context/2.

Transitions the editing model to a new mode.

Updates the active window viewport, when a window is active.

Types

buffer_activation()

@type buffer_activation() :: integer() | MingaEditor.State.Buffers.t()

A leaf-owned buffer selection to activate in this session.

cmd_hover_cell()

@type cmd_hover_cell() :: position() | nil

The pointer cell used to deduplicate Cmd/Ctrl-hover resolution.

cmd_hover_link()

@type cmd_hover_link() :: MingaEditor.Session.HoverObservation.link()

Transient Cmd/Ctrl-hover go-to-definition link range.

document_highlight()

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

A document highlight range from the LSP server.

position()

@type position() :: {non_neg_integer(), non_neg_integer()}

A buffer position as {line, byte_col}.

t()

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

Functions

activate_buffer(workspace, activation, opts \\ [])

@spec activate_buffer(t(), buffer_activation(), keyword()) :: t()

Activates a buffer selection and synchronizes every session-owned observation.

Integer selections delegate wrapping and index semantics to Buffers. A prepared Buffers value supports close, restore, and add workflows that already performed their leaf transition. By default non-buffer surfaces remain visible; replace_window_content?: true lets a shell intentionally replace one with the activated buffer.

active_window_struct(state)

@spec active_window_struct(t()) :: MingaEditor.Window.t() | nil

Returns the active window struct, or nil.

clear_cmd_hover_link(workspace)

@spec clear_cmd_hover_link(t()) :: t()

Clears the complete transient Cmd/Ctrl-hover observation.

current_viewport(workspace, fallback)

@spec current_viewport(t(), MingaEditor.Viewport.t()) :: MingaEditor.Viewport.t()

Returns the focused window viewport or the supplied terminal fallback.

delete_lsp_pending(workspace, ref)

@spec delete_lsp_pending(t(), reference()) :: t()

Removes one pending LSP request from the workspace correlation table.

drop_extension_feature_state_sources(wspace)

@spec drop_extension_feature_state_sources(t()) :: t()

Drops every extension-owned feature state entry.

drop_feature_state(wspace, source, feature_id)

@spec drop_feature_state(
  t(),
  MingaEditor.FeatureState.source(),
  MingaEditor.FeatureState.feature_id()
) ::
  t()

Drops one source-owned feature state entry. Missing state is treated as inactive.

drop_feature_state_source(wspace, source)

@spec drop_feature_state_source(t(), MingaEditor.FeatureState.source()) :: t()

Drops all feature state owned by a source.

drop_file_tree(wspace)

@spec drop_file_tree(t()) :: t()

Resets FileTree UI state.

empty_state?(state)

@spec empty_state?(t()) :: boolean()

True when the workspace is showing the zero-buffers launchpad.

enter_empty_state(wspace, launchpad_opts \\ [])

@spec enter_empty_state(
  t(),
  keyword()
) :: t()

Enters the zero-buffers launchpad (#2689).

Clears the active buffer, switches the active window's content to the empty-state surface, and snapshots launchpad data (session, recents). The window tree is untouched: the last window stays open.

field_names()

@spec field_names() :: [MingaEditor.State.Tab.Context.field_name()]

Returns the list of field names (for snapshot/restore compatibility).

file_tree_state(state)

@spec file_tree_state(t()) :: MingaEditor.State.FileTree.t()

Returns FileTree UI state.

find_agent_chat_window(state)

@spec find_agent_chat_window(t()) ::
  {MingaEditor.Window.id(), MingaEditor.Window.t()} | nil

Finds the semantic agent chat window, when one exists.

focus_surviving_window(workspace, windows, target_id)

@spec focus_surviving_window(
  t(),
  MingaEditor.State.Windows.t(),
  MingaEditor.Window.id()
) :: t()

Commits focus to a surviving window after the active split was removed.

focus_window(workspace, target_id, outgoing_cursor)

@spec focus_window(t(), MingaEditor.Window.id(), position() | nil) :: t()

Commits a pure window-focus transition after its required buffer calls succeed.

get_feature_state(state, source, feature_id)

@spec get_feature_state(
  t(),
  MingaEditor.FeatureState.source(),
  MingaEditor.FeatureState.feature_id()
) ::
  term() | nil

Returns source-owned feature state, or nil when inactive.

get_feature_state(state, source, feature_id, default)

@spec get_feature_state(
  t(),
  MingaEditor.FeatureState.source(),
  MingaEditor.FeatureState.feature_id(),
  default
) :: term() | default
when default: var

Returns source-owned feature state, or a caller-provided default when inactive.

invalidate_all_windows(wspace)

@spec invalidate_all_windows(t()) :: t()

Invalidates render caches for all windows.

Call when the screen layout changes (file tree toggle, agent panel toggle) because cached draws contain baked-in absolute coordinates that become wrong when column offsets shift.

mark_authoritative_scroll(workspace)

@spec mark_authoritative_scroll(t()) :: t()

Marks the active window for authoritative scroll receipt handling.

mark_frontend_reset_pending(wspace)

@spec mark_frontend_reset_pending(t()) :: t()

Marks all window retained-GUI render caches reset-pending after frontend state loss.

observe_window(workspace, id, buffer, viewport, version)

@spec observe_window(
  t(),
  MingaEditor.Window.id(),
  pid(),
  MingaEditor.Viewport.t(),
  non_neg_integer()
) ::
  t()

Records a renderer observation for one session-owned window.

put_feature_state(wspace, source, feature_id, value)

@spec put_feature_state(
  t(),
  MingaEditor.FeatureState.source(),
  MingaEditor.FeatureState.feature_id(),
  term()
) :: t()

Stores source-owned feature state.

put_lsp_pending(workspace, ref, kind)

@spec put_lsp_pending(t(), reference(), atom() | tuple()) :: t()

Adds one pending LSP request to the workspace correlation table.

record_feature_value(wspace, source, feature_id, value)

@spec record_feature_value(
  t(),
  MingaEditor.FeatureState.source(),
  MingaEditor.FeatureState.feature_id(),
  term()
) :: t()

Records a concrete source-owned feature value.

remember_active_window_cursor(workspace, cursor)

@spec remember_active_window_cursor(t(), position()) :: t()

Stores the active buffer cursor in its matching active window.

replace_buffer_windows(workspace, buffer, replacements)

@spec replace_buffer_windows(t(), pid(), %{
  required(MingaEditor.Window.id()) => MingaEditor.Window.t()
}) ::
  t()

Replaces every window showing a buffer with concrete values.

replace_window(workspace, id, window)

@spec replace_window(t(), MingaEditor.Window.id(), MingaEditor.Window.t()) :: t()

Replaces one session-owned window with a concrete value.

restore_tab_context(ws, context)

@spec restore_tab_context(
  t(),
  MingaEditor.State.Tab.Context.t() | MingaEditor.State.Tab.Context.legacy()
) :: t()

Restores a tab context into a workspace. Empty contexts are ignored by this pure helper; EditorState handles brand-new tab defaults because those need editor dimensions. Dead buffer pids in the restored context are scrubbed to prevent activating a dead process.

retire_agent_prompt_buffer(workspace, pid)

@spec retire_agent_prompt_buffer(t(), pid()) :: t()

Forgets a retired process when it owns the agent prompt buffer.

scope_for_active_window(state)

@spec scope_for_active_window(t()) :: atom()

Returns the appropriate keymap scope for the active window's content type.

scope_for_content(arg, current_scope)

Derives the keymap scope from a window's content type.

Agent chat windows use :agent, launchpad windows use :editor, and buffer windows return from :agent to :editor while preserving other scopes.

scroll_agent_chat_window(workspace, delta)

@spec scroll_agent_chat_window(t(), integer()) :: t()

Scrolls the agent chat window viewport when one exists.

set_agent_ui(wspace, agent_ui)

@spec set_agent_ui(t(), MingaEditor.Agent.UIState.t()) :: t()

Updates the agent UI state.

set_buffers(wspace, buffers)

@spec set_buffers(t(), MingaEditor.State.Buffers.t()) :: t()

Replaces the buffers sub-struct.

set_cmd_hover_cell(workspace, cell)

@spec set_cmd_hover_cell(t(), cmd_hover_cell()) :: t()

Records the pointer cell that produced the hover observation.

set_cmd_hover_link(workspace, link)

@spec set_cmd_hover_link(t(), cmd_hover_link()) :: t()

Records the transient Cmd/Ctrl-hover link range.

set_document_highlights(wspace, highlights)

@spec set_document_highlights(t(), [document_highlight()] | nil) :: t()

Updates the document highlights from LSP.

set_editing(wspace, vim)

@spec set_editing(t(), MingaEditor.VimState.t()) :: t()

Replaces the editing (VimState) sub-struct.

set_feature_state(wspace, feature_state)

@spec set_feature_state(t(), MingaEditor.FeatureState.t()) :: t()

Replaces the feature-state registry.

set_file_tree(wspace, file_tree)

@spec set_file_tree(t(), MingaEditor.State.FileTree.t()) :: t()

Replaces the FileTree UI state.

set_keymap_scope(wspace, scope)

@spec set_keymap_scope(t(), Minga.Keymap.Scope.scope_name()) :: t()

Sets the keymap scope.

set_launchpad(wspace, launchpad)

@spec set_launchpad(t(), MingaEditor.State.Launchpad.t() | nil) :: t()

Sets or clears the launchpad (zero-buffers empty state).

set_lsp_pending(wspace, pending)

@spec set_lsp_pending(t(), %{required(reference()) => atom() | tuple()}) :: t()

Updates the LSP pending requests map.

set_mouse(wspace, mouse)

@spec set_mouse(t(), MingaEditor.State.Mouse.t()) :: t()

Updates the mouse sub-struct.

set_search(wspace, search)

@spec set_search(t(), MingaEditor.State.Search.t()) :: t()

Updates the search sub-struct.

set_viewport(wspace, viewport)

@spec set_viewport(t(), MingaEditor.Viewport.t()) :: t()

Sets the viewport dimensions.

set_windows(wspace, windows)

@spec set_windows(t(), MingaEditor.State.Windows.t()) :: t()

Replaces the windows sub-struct.

split?(state)

@spec split?(t()) :: boolean()

Returns true if the workspace has more than one window.

to_tab_context(ws)

@spec to_tab_context(t()) :: MingaEditor.State.Tab.Context.t()

Converts a workspace into a typed tab context suitable for storing on a MingaEditor.State.Tab and later restoring via restore_tab_context/2.

The single chokepoint for snapshots. Delegates to TabContext.from_workspace/1 which constructs the context struct directly from the session struct (no intermediate map). The vim state is normalised so the snapshotted editing state is a valid resting state, not a transient mid-transition pair where mode_state belongs to the leaving mode (see VimState.normalize/1). Use this everywhere the editor captures state.workspace into a tab context.

transition_mode(wspace, mode, mode_state \\ nil)

@spec transition_mode(t(), atom(), term()) :: t()

Transitions the editing model to a new mode.

update_current_viewport(workspace, viewport)

@spec update_current_viewport(t(), MingaEditor.Viewport.t()) :: t()

Updates the active window viewport, when a window is active.