pub struct SourceContext { /* private fields */ }Expand description
Context for managing source files
Implementations§
Source§impl SourceContext
impl SourceContext
Sourcepub fn add_file(&mut self, path: String, content: Option<String>) -> FileId
pub fn add_file(&mut self, path: String, content: Option<String>) -> FileId
Add a file to the context and return its ID
- If content is Some: Creates an ephemeral (in-memory) file. Content is stored and used for ariadne rendering.
- If content is None: Creates a disk-backed file. Content will be read from disk when needed (path must exist).
For ephemeral files, FileInformation is created immediately from the provided content. For disk-backed files, FileInformation is created by reading from disk if the path exists.
Sourcepub fn add_file_with_info(
&mut self,
path: String,
file_info: FileInformation,
) -> FileId
pub fn add_file_with_info( &mut self, path: String, file_info: FileInformation, ) -> FileId
Add a file with pre-computed FileInformation
This is useful when deserializing from formats (like JSON) that include serialized FileInformation, avoiding the need to recompute line breaks or read from disk.
The file is created without content (content=None), so ariadne rendering won’t work, but map_offset() will work using the provided FileInformation.
Sourcepub fn add_file_with_id(
&mut self,
id: FileId,
path: String,
content: Option<String>,
) -> FileId
pub fn add_file_with_id( &mut self, id: FileId, path: String, content: Option<String>, ) -> FileId
Add a file with a specific FileId
This is useful when interfacing with systems that use hash-based or non-sequential FileIds (like quarto-yaml). The FileId must not already exist in the context.
§Panics
Panics if the FileId already exists in the context.
Sourcepub fn get_file(&self, id: FileId) -> Option<&SourceFile>
pub fn get_file(&self, id: FileId) -> Option<&SourceFile>
Get a file by ID
Sourcepub fn get_file_mut(&mut self, id: FileId) -> Option<&mut SourceFile>
pub fn get_file_mut(&mut self, id: FileId) -> Option<&mut SourceFile>
Get a file by ID for mutation — typically to attach
FileMetadata::origin after registering a virtual file.
Sourcepub fn without_content(&self) -> Self
pub fn without_content(&self) -> Self
Create a copy without FileInformation (for serialization)
Note: This preserves the content field for ephemeral files, as they need content to be serialized for proper deserialization. Only FileInformation is removed since it can be reconstructed from content.