NotebookSession

Struct NotebookSession 

Source
pub struct NotebookSession { /* private fields */ }
Expand description

A notebook session.

Implementations§

Source§

impl NotebookSession

Source

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.

Source

pub fn path(&self) -> &Path

Get the notebook path.

Source

pub fn subscribe(&self) -> Receiver<ServerMessage>

Subscribe to server messages.

Source

pub fn broadcast(&self, msg: ServerMessage)

Broadcast a server message, ignoring send failures.

Source

pub fn reload(&mut self) -> ServerResult<()>

Reload the notebook from disk.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn is_executing(&self) -> bool

Check if execution is in progress.

Source

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.

Source

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.

Source

pub fn execution_timeout(&self) -> Option<Duration>

Get the current execution timeout.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn get_dirty_cell_ids(&self) -> Vec<CellId>

Get IDs of all dirty cells in topological order.

Source

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.

Source

pub fn get_widget_values(&self, cell_id: CellId) -> HashMap<String, WidgetValue>

Get widget values for a cell.

Source

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.

Source

pub fn get_widget_defs(&self, cell_id: CellId) -> Vec<WidgetDef>

Get widget definitions for a cell.

Source

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.

Source

pub fn get_history_count(&self, cell_id: CellId) -> usize

Get history count for a cell.

Source

pub fn get_history_index(&self, cell_id: CellId) -> usize

Get current history index for a cell.

Source

pub fn cell_states(&self) -> &HashMap<CellId, CellState>

Get reference to cell states.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn delete_markdown_cell(&mut self, cell_id: CellId) -> ServerResult<()>

Delete a markdown cell.

Modifies the .rs source file and reloads the notebook.

Source

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.

Source

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.

Source

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.

Source

pub fn delete_definition_cell(&mut self, cell_id: CellId) -> ServerResult<()>

Delete a definition cell.

Modifies the .rs source file and reloads the notebook.

Source

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.

Source

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.

Source

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.

Source

pub fn get_undo_redo_state(&self) -> ServerMessage

Get the current undo/redo state.

Source

pub fn clear_undo_history(&mut self)

Clear undo/redo history.

Called when the file is externally modified.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,