Skip to content

feat(plugin): add session restore lifecycle support#70

Merged
fcoury merged 1 commit into
masterfrom
plugin-session-restore
May 29, 2026
Merged

feat(plugin): add session restore lifecycle support#70
fcoury merged 1 commit into
masterfrom
plugin-session-restore

Conversation

@fcoury
Copy link
Copy Markdown
Contributor

@fcoury fcoury commented May 28, 2026

Why

Plugins can react to editor events today, but they do not have a deterministic way to persist workspace state at shutdown or restore it during startup. That makes session-style plugins impossible without baking the behavior directly into the editor. This change adds the missing lifecycle and state APIs, then uses them to ship a built-in session_restore plugin.

What Changed

  • Added editor session snapshots for file-backed buffers, active buffer, cursor and viewport positions, cwd, and window split layout.
  • Added plugin APIs for red.getEditorState(), red.restoreEditorState(snapshot), and namespaced JSON red.storage.
  • Added startup/shutdown plugin extension points: async-safe activate(red), editor:ready, awaited beforeExit(red, state), and context-aware deactivate(red).
  • Added plugins/session_restore.js, enabled it in default_config.toml, and documented the new APIs in docs/PLUGIN_SYSTEM.md and types/red.d.ts.

How to Test

  1. Enable session_restore = "session_restore.js" under [plugins] in a Red config.
  2. Start Red without explicit file arguments, open a couple of real files, move the cursors, and create a split.
  3. Quit cleanly, then start Red again from the same cwd without explicit file arguments.
  4. Confirm that the same file-backed buffers, active window, cursor positions, viewport positions, and split layout are restored.
  5. Start Red with an explicit file argument and confirm session restore is skipped for that launch, so the requested file opens normally.
  6. Delete or rename one file from a saved session, restart from the same cwd, and confirm the remaining files restore while the missing file is skipped and logged.

Targeted tests:

  • cargo test snapshot_round_trips_split_layout
  • cargo test
  • timeout 3 target/debug/red CLAUDE.md after cargo build to verify startup reaches the editor instead of failing during plugin activation

@fcoury fcoury force-pushed the plugin-session-restore branch from 7f7e0aa to 0443b11 Compare May 29, 2026 02:39
Add editor session snapshot APIs, plugin storage, and lifecycle hooks so plugins can persist and restore workspace state across editor runs.

Include a built-in `session_restore` plugin that saves file-backed buffers, cursor positions, viewport state, and window splits on exit.
@fcoury fcoury force-pushed the plugin-session-restore branch from 0443b11 to a1d0b53 Compare May 29, 2026 02:48
@fcoury fcoury merged commit e0d7bd2 into master May 29, 2026
27 checks passed
@fcoury fcoury deleted the plugin-session-restore branch May 29, 2026 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant