WorkspaceIndex

Struct WorkspaceIndex 

Source
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

Source

pub fn new() -> Self

Create a new empty workspace index

Source

pub fn version(&self) -> u64

Get the current version (for cache invalidation)

Source

pub fn file_count(&self) -> usize

Get the number of indexed files

Source

pub fn contains_file(&self, path: &Path) -> bool

Check if a file is in the index

Source

pub fn get_file(&self, path: &Path) -> Option<&FileIndex>

Get the index data for a specific file

Source

pub fn insert_file(&mut self, path: PathBuf, index: FileIndex)

Insert or update a file’s index data

Source

pub fn remove_file(&mut self, path: &Path) -> Option<FileIndex>

Remove a file from the index

Source

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.

Source

pub fn all_headings(&self) -> impl Iterator<Item = (&Path, &HeadingIndex)>

Get all headings across the workspace (for debugging/testing)

Source

pub fn files(&self) -> impl Iterator<Item = (&Path, &FileIndex)>

Iterate over all files in the index

Source

pub fn clear(&mut self)

Clear the entire index

Source

pub fn update_file(&mut self, path: &Path, index: FileIndex)

Update a file’s index and maintain reverse dependencies

This method:

  1. Removes this file as a source (dependent) from all reverse deps
  2. Inserts the new file index
  3. Builds new reverse deps from cross_file_links
Source

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.

Source

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.

Source

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.

Source

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
Source

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

Source§

fn clone(&self) -> WorkspaceIndex

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WorkspaceIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WorkspaceIndex

Source§

fn default() -> WorkspaceIndex

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for WorkspaceIndex

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for WorkspaceIndex

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,