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
impl SourceEditor
Sourcepub fn load(path: &Path) -> Result<Self>
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.
Sourcepub fn insert_cell(&mut self, after_cell_id: Option<&str>) -> Result<String>
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.
Sourcepub fn delete_cell(&mut self, cell_name: &str) -> Result<String>
pub fn delete_cell(&mut self, cell_name: &str) -> Result<String>
Delete a cell by name.
Returns the name of the deleted cell.
Sourcepub fn duplicate_cell(&mut self, cell_name: &str) -> Result<String>
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.
Sourcepub fn move_cell(
&mut self,
cell_name: &str,
direction: MoveDirection,
) -> Result<()>
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.
Sourcepub fn rename_cell(
&mut self,
cell_name: &str,
new_display_name: &str,
) -> Result<()>
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.
Sourcepub fn insert_markdown_cell(
&mut self,
content: &str,
after_line: Option<usize>,
) -> Result<()>
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).
Sourcepub fn insert_raw_code(
&mut self,
content: &str,
after_line: Option<usize>,
) -> Result<()>
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.
Sourcepub fn edit_markdown_cell(
&mut self,
start_line: usize,
end_line: usize,
new_content: &str,
is_module_doc: bool,
) -> Result<()>
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 ///.
Sourcepub fn edit_raw_code(
&mut self,
start_line: usize,
end_line: usize,
new_content: &str,
) -> Result<()>
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.
Sourcepub fn delete_markdown_cell(
&mut self,
start_line: usize,
end_line: usize,
) -> Result<()>
pub fn delete_markdown_cell( &mut self, start_line: usize, end_line: usize, ) -> Result<()>
Delete a markdown cell by line range.
Sourcepub fn move_markdown_cell(
&mut self,
start_line: usize,
end_line: usize,
direction: MoveDirection,
) -> Result<()>
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.
Sourcepub fn save(&self) -> Result<()>
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.
Sourcepub fn get_cell_source(&self, cell_name: &str) -> Result<String>
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.
Sourcepub fn get_previous_cell_name(&self, cell_name: &str) -> Result<Option<String>>
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.
Sourcepub fn restore_cell(
&mut self,
source: &str,
after_cell_name: Option<&str>,
) -> Result<()>
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.
Sourcepub fn find_cell_span(
&self,
file: &SynFile,
cell_name: &str,
) -> Result<(usize, usize)>
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.
Sourcepub fn find_function_span(
&self,
file: &SynFile,
cell_name: &str,
) -> Result<(usize, usize)>
pub fn find_function_span( &self, file: &SynFile, cell_name: &str, ) -> Result<(usize, usize)>
Find just the function span (NOT doc comments) for editing.
Sourcepub fn extract_doc_comments(&self, cell_name: &str) -> Result<Vec<String>>
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.
Auto Trait Implementations§
impl Freeze for SourceEditor
impl RefUnwindSafe for SourceEditor
impl Send for SourceEditor
impl Sync for SourceEditor
impl Unpin for SourceEditor
impl UnwindSafe for SourceEditor
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.