Minga.Session (Minga v0.1.0)

Copy Markdown View Source

Session state persistence for crash recovery.

Periodically saves the list of open files, cursor positions, scroll positions, and active buffer to a JSON file. On next launch, the session is restored: files are reopened and cursors are repositioned.

The session file includes a version field for forward compatibility. Old session files that lack newer fields get defaults when loaded.

Clean shutdown detection

A clean_shutdown flag is set in the session file on orderly exit. On next launch, if the flag is missing or false, Minga knows the previous session crashed and shows "Restored from previous session" in *Messages*.

Summary

Types

A single buffer's session state.

A snapshot of the current editor session.

A recoverable swap file entry.

Functions

Returns whether the last session was a clean shutdown.

Deletes the swap file for the given buffer path.

Loads the session from disk.

Marks the session as cleanly shut down.

Recovers content from a swap file. Returns {:ok, original_path, content}.

Saves a session snapshot to disk as JSON.

Scans the swap directory for recoverable swap files.

Returns the session file path.

Builds a session snapshot from the Editor's state.

Returns the default swap directory path.

Writes a swap file for the given buffer path.

Types

buffer_entry()

@type buffer_entry() :: Minga.Session.BufferEntry.t()

A single buffer's session state.

snapshot()

@type snapshot() :: Minga.Session.Snapshot.t()

A snapshot of the current editor session.

swap_entry()

@type swap_entry() :: Minga.Session.Swap.Recovery.entry()

A recoverable swap file entry.

Functions

clean_shutdown?(opts \\ [])

@spec clean_shutdown?(keyword()) :: boolean()

Returns whether the last session was a clean shutdown.

delete_swap(path, opts \\ [])

@spec delete_swap(
  String.t(),
  keyword()
) :: :ok

Deletes the swap file for the given buffer path.

load(opts \\ [])

@spec load(keyword()) :: {:ok, snapshot()} | {:error, term()}

Loads the session from disk.

mark_clean_shutdown(opts \\ [])

@spec mark_clean_shutdown(keyword()) :: :ok

Marks the session as cleanly shut down.

recover_swap_file(swap_path)

@spec recover_swap_file(String.t()) ::
  {:ok, String.t(), String.t()} | {:error, term()}

Recovers content from a swap file. Returns {:ok, original_path, content}.

save(snapshot, opts \\ [])

@spec save(
  snapshot(),
  keyword()
) :: :ok | {:error, term()}

Saves a session snapshot to disk as JSON.

scan_recoverable_swaps(opts \\ [])

@spec scan_recoverable_swaps(keyword()) :: [swap_entry()]

Scans the swap directory for recoverable swap files.

session_file(opts \\ [])

@spec session_file(keyword()) :: String.t()

Returns the session file path.

snapshot(editor_state)

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

Builds a session snapshot from the Editor's state.

Queries each open buffer for its file path and cursor position. Only includes file-backed buffers (not scratch, nofile, or log buffers).

swap_dir()

@spec swap_dir() :: String.t()

Returns the default swap directory path.

write_swap(path, content, opts \\ [])

@spec write_swap(String.t(), String.t(), keyword()) :: :ok | {:error, term()}

Writes a swap file for the given buffer path.