Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion crates/codebook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod queries;
pub mod regexes;
mod splitter;

use crate::regexes::get_default_skip_patterns;
use crate::{queries::LanguageType, regexes::get_default_skip_patterns};
use std::path::Path;
use std::sync::Arc;

Expand Down Expand Up @@ -42,6 +42,9 @@ impl Codebook {
{
return Vec::new();
}
if has_ignore_comment(text, language.unwrap_or(LanguageType::Javascript)) {
return Vec::new();
}
// get needed dictionary names
// get needed dictionaries
// call spell check on each dictionary
Expand Down Expand Up @@ -140,6 +143,37 @@ impl Codebook {
}
}

fn has_ignore_comment(text: &str, language: LanguageType) -> bool {
let ignore_comment = match language {
LanguageType::Css => "/* spellchecker: disable",
LanguageType::HTML => "<!-- spellchecker: disable",
LanguageType::Latex => "% spellchecker: disable",
LanguageType::Haskell | LanguageType::Lua => "-- spellchecker: disable",
LanguageType::Bash
| LanguageType::Elixir
| LanguageType::Python
| LanguageType::R
| LanguageType::Ruby
| LanguageType::TOML => "# spellchecker: disable",
LanguageType::Text => "spellchecker: disable",
LanguageType::C
| LanguageType::Php
| LanguageType::CSharp
| LanguageType::Rust
| LanguageType::Cpp
| LanguageType::Typescript
| LanguageType::Go
| LanguageType::Typst
| LanguageType::Java
| LanguageType::Zig
| LanguageType::Javascript => "// spellchecker: disable",
};
text.lines()
.next()
.unwrap_or("")
.starts_with(ignore_comment)
}

fn collect_round_robin<T: Clone + PartialEq + Ord>(sources: &[Vec<T>], max_count: usize) -> Vec<T> {
let mut result = Vec::with_capacity(max_count);
for i in 0..max_count {
Expand Down