SourceEditor

Struct SourceEditor 

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

Editor for modifying .rs notebook source files.

Holds an exclusive file lock for the duration of the edit session to prevent concurrent modifications.

Implementations§

Source§

impl SourceEditor

Source

pub fn load(path: &Path) -> Result<Self>

Load a source file for editing.

Acquires an exclusive advisory lock on the file to prevent concurrent modifications from other processes.

Source

pub fn insert_cell(&mut self, after_cell_id: Option<&str>) -> Result<String>

Insert a new cell after the specified cell.

If after_cell_id is None, inserts at the end of the file. Returns the name of the newly created cell.

Source

pub fn delete_cell(&mut self, cell_name: &str) -> Result<String>

Delete a cell by name.

Returns the name of the deleted cell.

Source

pub fn duplicate_cell(&mut self, cell_name: &str) -> Result<String>

Duplicate a cell by name.

Creates a copy of the cell with a unique name (e.g., cell_name_copy). The new cell is inserted immediately after the original. Returns the name of the new cell.

Source

pub fn move_cell( &mut self, cell_name: &str, direction: MoveDirection, ) -> Result<()>

Move a cell up or down by swapping with its neighbor.

Returns Ok(()) on success.

Source

pub fn rename_cell( &mut self, cell_name: &str, new_display_name: &str, ) -> Result<()>

Rename a cell’s display name by updating its doc comment.

Updates or adds a # Display Name heading to the cell’s doc comment.

Source

pub fn insert_markdown_cell( &mut self, content: &str, after_line: Option<usize>, ) -> Result<()>

Insert a markdown cell at a specific line position.

If after_line is None, inserts at the beginning of the file. Content should be plain markdown text (without /// prefix).

Source

pub fn insert_raw_code( &mut self, content: &str, after_line: Option<usize>, ) -> Result<()>

Insert raw Rust code (for definition cells, imports, etc.) without any formatting. This is a generic method for inserting plain Rust code without comment prefix or attributes.

Source

pub fn edit_markdown_cell( &mut self, start_line: usize, end_line: usize, new_content: &str, is_module_doc: bool, ) -> Result<()>

Edit an existing markdown cell by line range.

Replaces the comment block at the given line range with new content. If is_module_doc is true, uses //! syntax; otherwise uses ///.

Source

pub fn edit_raw_code( &mut self, start_line: usize, end_line: usize, new_content: &str, ) -> Result<()>

Edit raw Rust code by line range (for definition cells, etc.) without any formatting. Replaces the code block at the given line range with new content as-is.

Source

pub fn delete_markdown_cell( &mut self, start_line: usize, end_line: usize, ) -> Result<()>

Delete a markdown cell by line range.

Source

pub fn move_markdown_cell( &mut self, start_line: usize, end_line: usize, direction: MoveDirection, ) -> Result<()>

Move a markdown cell up or down.

Swaps the markdown block with the adjacent one.

Source

pub fn save(&self) -> Result<()>

Save changes to the file.

The exclusive lock is maintained until SourceEditor is dropped, ensuring no other process can modify the file between save and drop.

Source

pub fn get_cell_source(&self, cell_name: &str) -> Result<String>

Get the source code of a cell (including doc comments and attributes).

Used for undo operations to capture cell content before deletion.

Source

pub fn get_previous_cell_name(&self, cell_name: &str) -> Result<Option<String>>

Get the name of the cell that appears before the specified cell.

Returns None if the cell is the first one. Used for undo operations to track position for restoration.

Source

pub fn restore_cell( &mut self, source: &str, after_cell_name: Option<&str>, ) -> Result<()>

Restore a cell with specific source code after a specific cell.

If after_cell_name is None, inserts at the beginning (before all cells). Used for undo delete operations.

Source

pub fn find_cell_span( &self, file: &SynFile, cell_name: &str, ) -> Result<(usize, usize)>

Find the span of a cell (start line to end line, 1-indexed). Includes doc comments and attributes above the function.

Source

pub fn find_function_span( &self, file: &SynFile, cell_name: &str, ) -> Result<(usize, usize)>

Find just the function span (NOT doc comments) for editing.

Source

pub fn extract_doc_comments(&self, cell_name: &str) -> Result<Vec<String>>

Extract existing doc comments for a cell. Returns them in “/// comment” format, preserving original formatting.

Source

pub fn reconstruct_cell( &self, cell_name: &str, new_function: &str, ) -> Result<String>

Reconstruct a complete cell including doc comments and attributes. Returns the full cell text: doc comments + #[venus::cell] + function.

Source

pub fn reconstruct_and_get_span( &self, cell_name: &str, new_function: &str, ) -> Result<(String, usize, usize)>

Reconstruct a cell and get its line span in one call. Returns (reconstructed_text, start_line, end_line).

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, 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<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