Skip to main content

Dictionary

Struct Dictionary 

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

Manages a set of ignored words for filtering grammar errors.

Loads the workspace-root .docolint-ignore file. Words are stored case-insensitively (lowercased). Supports adding new words to a target ignore file and filtering errors based on ignored words.

Implementations§

Source§

impl Dictionary

Source

pub fn new() -> Self

Creates an empty dictionary with no ignored words.

Source

pub fn load(workspace_root: &Path, document_path: &Path) -> Self

Loads the workspace-root .docolint-ignore file.

Lines starting with # are treated as comments and skipped. Empty lines are ignored. Words are lowercased before storage.

§Arguments
  • workspace_root - The workspace root directory containing .docolint-ignore.
  • document_path - Path to the source file being checked. Retained for API compatibility but ignored because the dictionary is always loaded from the workspace root.
§Panics

Does not panic. File read errors are silently ignored (missing files = no words).

Source

pub fn is_ignored(&self, word: &str) -> bool

Checks if a word is in the ignored set (case-insensitive).

§Arguments
  • word - The word to check. Compared in lowercase against stored words.
Source

pub fn add_word(&mut self, word: &str, target_file: &Path) -> Result<()>

Appends a word to a .docolint-ignore file and adds it to the in-memory set.

Creates the file if it does not exist. The word is lowercased before writing. No duplicate check is performed on the file; duplicates are harmless since the in-memory set deduplicates automatically.

§Arguments
  • word - The word to ignore. Empty strings are silently ignored.
  • target_file - Path to the .docolint-ignore file to append to.
§Errors

Returns std::io::Error if the file cannot be opened or written.

Source

pub fn filter_errors( &self, text: &str, errors: Vec<GrammarError>, ) -> Vec<GrammarError>

Filters out grammar errors whose matched word is in the ignored set.

Extracts the word from text using each error’s offset and length, then checks it against the ignored set. Errors with out-of-bounds offsets are kept (not filtered).

§Arguments
  • text - The plain text string that LanguageTool checked. Offsets in errors are relative to this string.
  • errors - Grammar errors to filter. Consumed by this function.
§Returns

A new Vec containing only errors whose matched word is not ignored.

Trait Implementations§

Source§

impl Default for Dictionary

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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