pub struct WorkspaceIndex { /* private fields */ }Expand description
Workspace-wide index for cross-file analysis
Contains pre-extracted information from all markdown files in the workspace, enabling rules to validate cross-file references efficiently.
Implementations§
Source§impl WorkspaceIndex
impl WorkspaceIndex
Sourcepub fn file_count(&self) -> usize
pub fn file_count(&self) -> usize
Get the number of indexed files
Sourcepub fn contains_file(&self, path: &Path) -> bool
pub fn contains_file(&self, path: &Path) -> bool
Check if a file is in the index
Sourcepub fn get_file(&self, path: &Path) -> Option<&FileIndex>
pub fn get_file(&self, path: &Path) -> Option<&FileIndex>
Get the index data for a specific file
Sourcepub fn insert_file(&mut self, path: PathBuf, index: FileIndex)
pub fn insert_file(&mut self, path: PathBuf, index: FileIndex)
Insert or update a file’s index data
Sourcepub fn remove_file(&mut self, path: &Path) -> Option<FileIndex>
pub fn remove_file(&mut self, path: &Path) -> Option<FileIndex>
Remove a file from the index
Sourcepub fn get_vulnerable_anchors(&self) -> HashMap<String, Vec<VulnerableAnchor>>
pub fn get_vulnerable_anchors(&self) -> HashMap<String, Vec<VulnerableAnchor>>
Build a map of all “vulnerable” anchors across the workspace
A vulnerable anchor is an auto-generated anchor for a heading that does NOT have a custom anchor defined. These are problematic for translated content because the anchor changes when the heading is translated.
Returns: Map from lowercase anchor → Vec of VulnerableAnchor info Multiple files can have headings with the same auto-generated anchor, so we collect all occurrences.
Sourcepub fn all_headings(&self) -> impl Iterator<Item = (&Path, &HeadingIndex)>
pub fn all_headings(&self) -> impl Iterator<Item = (&Path, &HeadingIndex)>
Get all headings across the workspace (for debugging/testing)
Sourcepub fn files(&self) -> impl Iterator<Item = (&Path, &FileIndex)>
pub fn files(&self) -> impl Iterator<Item = (&Path, &FileIndex)>
Iterate over all files in the index
Sourcepub fn update_file(&mut self, path: &Path, index: FileIndex)
pub fn update_file(&mut self, path: &Path, index: FileIndex)
Update a file’s index and maintain reverse dependencies
This method:
- Removes this file as a source (dependent) from all reverse deps
- Inserts the new file index
- Builds new reverse deps from cross_file_links
Sourcepub fn get_dependents(&self, path: &Path) -> Vec<PathBuf>
pub fn get_dependents(&self, path: &Path) -> Vec<PathBuf>
Get files that depend on (link to) the given file
Returns a list of file paths that contain links targeting this file. Used to re-lint dependent files when a target file changes.
Sourcepub fn is_file_stale(&self, path: &Path, current_hash: &str) -> bool
pub fn is_file_stale(&self, path: &Path, current_hash: &str) -> bool
Check if a file needs re-indexing based on its content hash
Returns true if the file is not in the index or has a different hash.
Sourcepub fn retain_only(&mut self, current_files: &HashSet<PathBuf>) -> usize
pub fn retain_only(&mut self, current_files: &HashSet<PathBuf>) -> usize
Retain only files that exist in the given set, removing deleted files
This prunes stale entries from the cache for files that no longer exist. Returns the number of files removed.
Sourcepub fn save_to_cache(&self, cache_dir: &Path) -> Result<()>
pub fn save_to_cache(&self, cache_dir: &Path) -> Result<()>
Save the workspace index to a cache file
Uses postcard for efficient binary serialization with:
- Magic header for file type validation
- Format version for compatibility detection
- Atomic writes (temp file + rename) to prevent corruption
Sourcepub fn load_from_cache(cache_dir: &Path) -> Option<Self>
pub fn load_from_cache(cache_dir: &Path) -> Option<Self>
Load the workspace index from a cache file
Returns None if:
- Cache file doesn’t exist
- Magic header doesn’t match
- Format version is incompatible
- Data is corrupted
Trait Implementations§
Source§impl Clone for WorkspaceIndex
impl Clone for WorkspaceIndex
Source§fn clone(&self) -> WorkspaceIndex
fn clone(&self) -> WorkspaceIndex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WorkspaceIndex
impl Debug for WorkspaceIndex
Source§impl Default for WorkspaceIndex
impl Default for WorkspaceIndex
Source§fn default() -> WorkspaceIndex
fn default() -> WorkspaceIndex
Source§impl<'de> Deserialize<'de> for WorkspaceIndex
impl<'de> Deserialize<'de> for WorkspaceIndex
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for WorkspaceIndex
impl RefUnwindSafe for WorkspaceIndex
impl Send for WorkspaceIndex
impl Sync for WorkspaceIndex
impl Unpin for WorkspaceIndex
impl UnwindSafe for WorkspaceIndex
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more