Skip to content

Commit 6e7cbe1

Browse files
committed
feat: created CharString and added config for diagnosticSeverity
1 parent e0f84ab commit 6e7cbe1

File tree

18 files changed

+118
-35
lines changed

18 files changed

+118
-35
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ Harper is even small enough to load via [WebAssembly.](https://writewithharper.c
3131

3232
If you want to use Harper on your machine, you will want to look at the [documentation for
3333
`harper-ls`](./harper-ls/README.md), the Language Server Protocol implementation.
34-

harper-core/dictionary.dict

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49622,3 +49622,4 @@ URI/s
4962249622
suprachiasmatic
4962349623
cannabinoids
4962449624
eudaimonia
49625+
whitespace

harper-core/src/char_string.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use smallvec::SmallVec;
2+
3+
pub type CharString = SmallVec<[char; 6]>;
4+
5+
pub trait CharStringExt {
6+
fn to_lower(&self) -> CharString;
7+
}
8+
9+
impl CharStringExt for [char] {
10+
fn to_lower(&self) -> CharString {
11+
let mut out = CharString::with_capacity(self.len());
12+
13+
out.extend(self.iter().flat_map(|v| v.to_lowercase()));
14+
15+
out
16+
}
17+
}

harper-core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(dead_code)]
22

3+
mod char_string;
34
mod document;
45
mod lexing;
56
mod linting;
@@ -8,6 +9,7 @@ mod span;
89
mod spell;
910
mod token;
1011

12+
pub use char_string::{CharString, CharStringExt};
1113
pub use document::Document;
1214
pub use linting::{Lint, LintGroup, LintGroupConfig, LintKind, Linter, Suggestion};
1315
pub use span::Span;

harper-core/src/linting/an_a.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use itertools::Itertools;
22

3-
use crate::{Document, Lint, LintKind, Linter, Suggestion, TokenStringExt};
3+
use crate::{CharStringExt, Document, Lint, LintKind, Linter, Suggestion, TokenStringExt};
44

55
#[derive(Debug, Default)]
66
pub struct AnA;
@@ -23,7 +23,7 @@ impl Linter for AnA {
2323
continue;
2424
};
2525

26-
let should_be_a_an = !starts_with_vowel(chars_second);
26+
let should_be_a_an = !starts_with_vowel(&chars_second.to_lower());
2727

2828
if a_an != should_be_a_an {
2929
let replacement = match a_an {

harper-core/src/linting/matcher.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
use crate::spell::DictWord;
2-
use crate::{Document, Lint, LintKind, Linter, Punctuation, Span, Suggestion, Token, TokenKind};
1+
use crate::{
2+
CharString,
3+
Document,
4+
Lint,
5+
LintKind,
6+
Linter,
7+
Punctuation,
8+
Span,
9+
Suggestion,
10+
Token,
11+
TokenKind
12+
};
313

414
#[derive(Debug, PartialEq, PartialOrd, Clone)]
515
struct PatternToken {
616
kind: TokenKind,
7-
content: Option<DictWord>
17+
content: Option<CharString>
818
}
919

1020
impl PatternToken {

harper-core/src/linting/repeated_words.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use hashbrown::HashSet;
22

33
use super::{Lint, LintKind, Linter};
4-
use crate::spell::DictWord;
54
use crate::token::{Token, TokenKind, TokenStringExt};
6-
use crate::{Document, Span, Suggestion};
5+
use crate::{CharString, Document, Span, Suggestion};
76

87
#[derive(Debug, Clone)]
98
pub struct RepeatedWords {
109
/// The set of words that can be considered for repetition checking.
11-
set: HashSet<DictWord>
10+
set: HashSet<CharString>
1211
}
1312

1413
impl RepeatedWords {

harper-core/src/spell/full_dictionary.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use smallvec::{SmallVec, ToSmallVec};
44

55
use super::dictionary::Dictionary;
66
use super::hunspell::{parse_default_attribute_list, parse_default_word_list};
7-
use super::{seq_to_normalized, DictWord};
7+
use super::seq_to_normalized;
8+
use crate::CharString;
89

910
/// A full, fat dictionary.
1011
/// All of the elements are stored in-memory.
@@ -16,13 +17,13 @@ pub struct FullDictionary {
1617
/// This is likely due to increased locality :shrug:.
1718
///
1819
/// This list is sorted by word length (i.e. the shortest words are first).
19-
words: Vec<DictWord>,
20+
words: Vec<CharString>,
2021
/// A lookup list for each word length.
2122
/// Each index of this list will return the first index of [`Self::words`]
2223
/// that has a word whose index is that length.
2324
word_len_starts: Vec<usize>,
2425
/// All English words
25-
word_set: HashSet<DictWord>
26+
word_set: HashSet<CharString>
2627
}
2728

2829
fn uncached_inner_new() -> FullDictionary {
@@ -81,7 +82,7 @@ impl FullDictionary {
8182
/// list. NOTE: This function will sort the original word list by its
8283
/// length. If the word list's order is changed after creating the
8384
/// lookup, it will no longer be valid.
84-
fn create_len_starts(words: &mut [DictWord]) -> Vec<usize> {
85+
fn create_len_starts(words: &mut [CharString]) -> Vec<usize> {
8586
words.sort_by_key(|a| a.len());
8687
let mut word_len_starts = vec![0, 0];
8788

harper-core/src/spell/hunspell/attributes.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use smallvec::ToSmallVec;
66
use super::matcher::Matcher;
77
use super::word_list::MarkedWord;
88
use super::Error;
9-
use crate::spell::DictWord;
10-
use crate::Span;
9+
use crate::{CharString, Span};
1110

1211
#[derive(Debug, Clone)]
1312
struct AffixReplacement {
@@ -111,7 +110,7 @@ impl AttributeList {
111110
/// Will append to the given `dest`;
112111
///
113112
/// In the future, I want to make this function cleaner and faster.
114-
pub fn expand_marked_word(&self, word: MarkedWord, dest: &mut Vec<DictWord>) {
113+
pub fn expand_marked_word(&self, word: MarkedWord, dest: &mut Vec<CharString>) {
115114
dest.reserve(word.attributes.len() + 1);
116115

117116
let start_len = dest.len();
@@ -173,7 +172,7 @@ impl AttributeList {
173172
pub fn expand_marked_words(
174173
&self,
175174
words: impl IntoIterator<Item = MarkedWord>,
176-
dest: &mut Vec<DictWord>
175+
dest: &mut Vec<CharString>
177176
) {
178177
for word in words {
179178
self.expand_marked_word(word, dest);
@@ -184,7 +183,7 @@ impl AttributeList {
184183
replacement: &AffixReplacement,
185184
letters: &[char],
186185
suffix: bool
187-
) -> Option<DictWord> {
186+
) -> Option<CharString> {
188187
if replacement.condition.len() > letters.len() {
189188
return None;
190189
}
@@ -199,7 +198,7 @@ impl AttributeList {
199198

200199
if replacement.condition.matches(target_segment) {
201200
let mut replaced_segment = letters.to_smallvec();
202-
let mut remove: DictWord = replacement.remove.to_smallvec();
201+
let mut remove: CharString = replacement.remove.to_smallvec();
203202

204203
if !suffix {
205204
replaced_segment.reverse();

0 commit comments

Comments
 (0)