pub struct NotebookSession { /* private fields */ }Expand description
A notebook session.
Implementations§
Source§impl NotebookSession
impl NotebookSession
Sourcepub fn new(
path: impl AsRef<Path>,
interrupted: InterruptFlag,
) -> ServerResult<(Self, Receiver<ServerMessage>)>
pub fn new( path: impl AsRef<Path>, interrupted: InterruptFlag, ) -> ServerResult<(Self, Receiver<ServerMessage>)>
Create a new notebook session.
Uses process isolation for cell execution, allowing true interruption by killing worker processes.
The interrupted flag is shared with AppState so the interrupt handler
can set it without needing the session lock.
Sourcepub fn subscribe(&self) -> Receiver<ServerMessage>
pub fn subscribe(&self) -> Receiver<ServerMessage>
Subscribe to server messages.
Sourcepub fn broadcast(&self, msg: ServerMessage)
pub fn broadcast(&self, msg: ServerMessage)
Broadcast a server message, ignoring send failures.
Sourcepub fn reload(&mut self) -> ServerResult<()>
pub fn reload(&mut self) -> ServerResult<()>
Reload the notebook from disk.
Sourcepub fn get_state(&self) -> ServerMessage
pub fn get_state(&self) -> ServerMessage
Get the full notebook state. Returns a snapshot of the current notebook state for UI rendering. Note: The virtual notebook.rs file for LSP is written during reload(), not here.
Sourcepub fn store_pending_edit(&mut self, cell_id: CellId, source: String)
pub fn store_pending_edit(&mut self, cell_id: CellId, source: String)
Store a pending edit from the editor (not yet saved to disk).
The edit will be saved to disk when the cell is executed.
Sourcepub async fn execute_cell(&mut self, cell_id: CellId) -> ServerResult<()>
pub async fn execute_cell(&mut self, cell_id: CellId) -> ServerResult<()>
Execute a specific cell.
Uses process isolation - the cell runs in a worker process that can be killed immediately for interruption.
Sourcepub async fn execute_all(&mut self) -> ServerResult<()>
pub async fn execute_all(&mut self) -> ServerResult<()>
Execute all cells in order.
If execution_timeout is set, kills the worker process after that duration.
Unlike cooperative cancellation, this immediately terminates the cell.
Sourcepub fn mark_dirty(&mut self, cell_id: CellId)
pub fn mark_dirty(&mut self, cell_id: CellId)
Mark a cell as dirty (needs re-execution).
Only marks cells as dirty if they have existing output (data). Cells without output remain pristine (no border).
Sourcepub fn is_executing(&self) -> bool
pub fn is_executing(&self) -> bool
Check if execution is in progress.
Sourcepub fn abort(&mut self) -> bool
pub fn abort(&mut self) -> bool
Abort the current execution immediately.
Unlike cooperative cancellation, this kills the worker process,
providing true interruption even for long-running computations.
Returns true if there was an execution in progress to abort.
Sourcepub fn set_execution_timeout(&mut self, timeout: Option<Duration>)
pub fn set_execution_timeout(&mut self, timeout: Option<Duration>)
Set the execution timeout for execute_all.
When set, execute_all will kill the worker process after this duration, providing immediate interruption of even long-running cells.
Sourcepub fn execution_timeout(&self) -> Option<Duration>
pub fn execution_timeout(&self) -> Option<Duration>
Get the current execution timeout.
Sourcepub fn set_interrupted(&mut self, value: bool)
pub fn set_interrupted(&mut self, value: bool)
Set the interrupted flag.
When true, execution errors will be reported as “interrupted” rather than as failures, showing a friendly message to users.
Sourcepub fn get_kill_handle(&self) -> Option<ExecutorKillHandle>
pub fn get_kill_handle(&self) -> Option<ExecutorKillHandle>
Get a kill handle for the executor.
This handle can be used from another task to kill the current execution without needing to acquire the session lock.
Sourcepub fn restart_kernel(&mut self) -> ServerResult<()>
pub fn restart_kernel(&mut self) -> ServerResult<()>
Restart the kernel: kill WorkerPool, spin up new one, clear memory state, preserve source.
This clears all execution state including:
- Cell outputs and output history
- Widget values
- Cached serialized outputs
- Cell execution status (all cells reset to Idle)
Source code and cell definitions are preserved.
Sourcepub fn clear_outputs(&mut self)
pub fn clear_outputs(&mut self)
Clear all cell outputs without restarting the kernel.
This clears the display outputs but preserves:
- Worker pool and execution state
- Widget values
- Cell source code
All cells are reset to pristine state (no output, not dirty).
Sourcepub fn get_dirty_cell_ids(&self) -> Vec<CellId>
pub fn get_dirty_cell_ids(&self) -> Vec<CellId>
Get IDs of all dirty cells in topological order.
Sourcepub fn update_widget_value(
&mut self,
cell_id: CellId,
widget_id: String,
value: WidgetValue,
)
pub fn update_widget_value( &mut self, cell_id: CellId, widget_id: String, value: WidgetValue, )
Update a widget value for a cell.
This stores the new value but does NOT trigger re-execution. The user must explicitly run the cell to see the effect.
Sourcepub fn get_widget_values(&self, cell_id: CellId) -> HashMap<String, WidgetValue>
pub fn get_widget_values(&self, cell_id: CellId) -> HashMap<String, WidgetValue>
Get widget values for a cell.
Sourcepub fn get_all_widget_values(&self) -> HashMap<String, WidgetValue>
pub fn get_all_widget_values(&self) -> HashMap<String, WidgetValue>
Get ALL widget values from all cells, flattened into a single map. Widget IDs should be unique across the notebook.
Sourcepub fn get_widget_defs(&self, cell_id: CellId) -> Vec<WidgetDef>
pub fn get_widget_defs(&self, cell_id: CellId) -> Vec<WidgetDef>
Get widget definitions for a cell.
Sourcepub fn select_history_entry(
&mut self,
cell_id: CellId,
index: usize,
) -> Option<CellOutput>
pub fn select_history_entry( &mut self, cell_id: CellId, index: usize, ) -> Option<CellOutput>
Select a history entry for a cell, making it the current output. Returns the display output if successful.
Sourcepub fn get_history_count(&self, cell_id: CellId) -> usize
pub fn get_history_count(&self, cell_id: CellId) -> usize
Get history count for a cell.
Sourcepub fn get_history_index(&self, cell_id: CellId) -> usize
pub fn get_history_index(&self, cell_id: CellId) -> usize
Get current history index for a cell.
Sourcepub fn cell_states(&self) -> &HashMap<CellId, CellState>
pub fn cell_states(&self) -> &HashMap<CellId, CellState>
Get reference to cell states.
Sourcepub fn insert_cell(
&mut self,
after_cell_id: Option<CellId>,
) -> ServerResult<String>
pub fn insert_cell( &mut self, after_cell_id: Option<CellId>, ) -> ServerResult<String>
Insert a new cell after the specified cell.
Modifies the source file and triggers a reload. Returns the name of the newly created cell.
Sourcepub fn delete_cell(&mut self, cell_id: CellId) -> ServerResult<()>
pub fn delete_cell(&mut self, cell_id: CellId) -> ServerResult<()>
Delete a cell from the notebook.
Modifies the .rs source file and reloads the notebook.
Sourcepub fn duplicate_cell(&mut self, cell_id: CellId) -> ServerResult<String>
pub fn duplicate_cell(&mut self, cell_id: CellId) -> ServerResult<String>
Duplicate a cell in the notebook.
Creates a copy of the cell with a unique name. Returns the name of the new cell.
Sourcepub fn move_cell(
&mut self,
cell_id: CellId,
direction: MoveDirection,
) -> ServerResult<()>
pub fn move_cell( &mut self, cell_id: CellId, direction: MoveDirection, ) -> ServerResult<()>
Move a cell up or down in the notebook.
Modifies the .rs source file and reloads the notebook.
Sourcepub fn edit_cell(
&mut self,
cell_id: CellId,
new_source: String,
) -> ServerResult<()>
pub fn edit_cell( &mut self, cell_id: CellId, new_source: String, ) -> ServerResult<()>
Edit a code cell’s source.
Modifies the .rs source file and reloads the notebook.
Sourcepub fn rename_cell(
&mut self,
cell_id: CellId,
new_display_name: String,
) -> ServerResult<()>
pub fn rename_cell( &mut self, cell_id: CellId, new_display_name: String, ) -> ServerResult<()>
Rename a cell’s display name.
Updates the cell’s doc comment with the new display name and reloads the notebook.
Sourcepub fn insert_markdown_cell(
&mut self,
content: String,
after_cell_id: Option<CellId>,
) -> ServerResult<()>
pub fn insert_markdown_cell( &mut self, content: String, after_cell_id: Option<CellId>, ) -> ServerResult<()>
Insert a new markdown cell.
Modifies the .rs source file and reloads the notebook.
Sourcepub fn edit_markdown_cell(
&mut self,
cell_id: CellId,
new_content: String,
) -> ServerResult<()>
pub fn edit_markdown_cell( &mut self, cell_id: CellId, new_content: String, ) -> ServerResult<()>
Edit a markdown cell’s content.
Modifies the .rs source file and reloads the notebook.
Sourcepub fn delete_markdown_cell(&mut self, cell_id: CellId) -> ServerResult<()>
pub fn delete_markdown_cell(&mut self, cell_id: CellId) -> ServerResult<()>
Delete a markdown cell.
Modifies the .rs source file and reloads the notebook.
Sourcepub fn move_markdown_cell(
&mut self,
cell_id: CellId,
direction: MoveDirection,
) -> ServerResult<()>
pub fn move_markdown_cell( &mut self, cell_id: CellId, direction: MoveDirection, ) -> ServerResult<()>
Move a markdown cell up or down.
Modifies the .rs source file and reloads the notebook.
Sourcepub fn insert_definition_cell(
&mut self,
content: String,
definition_type: DefinitionType,
after_cell_id: Option<CellId>,
) -> ServerResult<CellId>
pub fn insert_definition_cell( &mut self, content: String, definition_type: DefinitionType, after_cell_id: Option<CellId>, ) -> ServerResult<CellId>
Insert a new definition cell.
Modifies the .rs source file and reloads the notebook. Returns the ID of the newly inserted definition cell.
Validates that the definition type matches the content before insertion.
Sourcepub fn edit_definition_cell(
&mut self,
cell_id: CellId,
new_content: String,
) -> ServerResult<Vec<CellId>>
pub fn edit_definition_cell( &mut self, cell_id: CellId, new_content: String, ) -> ServerResult<Vec<CellId>>
Edit a definition cell’s content.
Modifies the .rs source file and reloads the notebook. Returns a list of cells that are now dirty due to the definition change.
Sourcepub fn delete_definition_cell(&mut self, cell_id: CellId) -> ServerResult<()>
pub fn delete_definition_cell(&mut self, cell_id: CellId) -> ServerResult<()>
Delete a definition cell.
Modifies the .rs source file and reloads the notebook.
Sourcepub fn move_definition_cell(
&mut self,
cell_id: CellId,
direction: MoveDirection,
) -> ServerResult<()>
pub fn move_definition_cell( &mut self, cell_id: CellId, direction: MoveDirection, ) -> ServerResult<()>
Move a definition cell up or down.
Modifies the .rs source file and reloads the notebook.
Sourcepub fn undo(&mut self) -> ServerResult<String>
pub fn undo(&mut self) -> ServerResult<String>
Undo the last cell management operation.
Returns a description of what was undone, or an error if undo failed.
Sourcepub fn redo(&mut self) -> ServerResult<String>
pub fn redo(&mut self) -> ServerResult<String>
Redo the last undone operation.
Returns a description of what was redone, or an error if redo failed.
Sourcepub fn get_undo_redo_state(&self) -> ServerMessage
pub fn get_undo_redo_state(&self) -> ServerMessage
Get the current undo/redo state.
Sourcepub fn clear_undo_history(&mut self)
pub fn clear_undo_history(&mut self)
Clear undo/redo history.
Called when the file is externally modified.
Auto Trait Implementations§
impl Freeze for NotebookSession
impl !RefUnwindSafe for NotebookSession
impl Send for NotebookSession
impl Sync for NotebookSession
impl Unpin for NotebookSession
impl !UnwindSafe for NotebookSession
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.