Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat(harper-lib): move some things into harper_lib and adjust everything accordingly
Grant Lemons4c44123c60a7
diff --git a/Cargo.lock b/Cargo.lockindex b43018a8a..7181cd2ce 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -570,6 +570,7 @@ version = "0.12.0"dependencies = ["harper-core","harper-html",+ "harper-lib","harper-tree-sitter","itertools 0.13.0","paste",@@ -599,6 +600,7 @@ dependencies = ["criterion","fst","harper-dictionary-parsing",+ "harper-lib","hashbrown 0.15.0","is-macro","itertools 0.13.0",@@ -619,8 +621,8 @@ dependencies = [name = "harper-dictionary-parsing"version = "0.12.0"dependencies = [+ "harper-lib","hashbrown 0.15.0",- "is-macro","serde","serde_json","smallvec",@@ -638,6 +640,15 @@ dependencies = ["tree-sitter-html",]+[[package]]+name = "harper-lib"+version = "0.12.0"+dependencies = [+ "is-macro",+ "serde",+ "smallvec",+]+[[package]]name = "harper-ls"version = "0.12.0"@@ -649,6 +660,7 @@ dependencies = ["harper-comments","harper-core","harper-html",+ "harper-lib","itertools 0.13.0","once_cell","open",@@ -666,6 +678,7 @@ name = "harper-tree-sitter"version = "0.12.0"dependencies = ["harper-core",+ "harper-lib","tree-sitter",]@@ -675,6 +688,7 @@ version = "0.1.0"dependencies = ["console_error_panic_hook","harper-core",+ "harper-lib","once_cell","serde-wasm-bindgen","tracing",diff --git a/harper-comments/Cargo.toml b/harper-comments/Cargo.tomlindex 108ca51fa..34bbf5d6f 100644--- a/harper-comments/Cargo.toml+++ b/harper-comments/Cargo.toml@@ -8,6 +8,7 @@ readme = "README.md"repository = "https://github.com/elijah-potter/harper"[dependencies]+harper-lib = { path = "../harper-lib", version = "0.12.0" }harper-core = { path = "../harper-core", version = "0.12.0" }harper-html = { path = "../harper-html", version = "0.12.0" }harper-tree-sitter = { path = "../harper-tree-sitter", version = "0.12.0" }diff --git a/harper-comments/src/comment_parsers/jsdoc.rs b/harper-comments/src/comment_parsers/jsdoc.rsindex 33e4858ae..b53d3b9a2 100644--- a/harper-comments/src/comment_parsers/jsdoc.rs+++ b/harper-comments/src/comment_parsers/jsdoc.rs@@ -1,5 +1,6 @@use harper_core::parsers::{Markdown, Parser};-use harper_core::{Punctuation, Span, Token, TokenKind};+use harper_core::{Punctuation, Token, TokenKind};+use harper_lib::Span;use itertools::Itertools;use super::without_initiators;diff --git a/harper-comments/src/comment_parsers/mod.rs b/harper-comments/src/comment_parsers/mod.rsindex f39c5bd24..af7adca38 100644--- a/harper-comments/src/comment_parsers/mod.rs+++ b/harper-comments/src/comment_parsers/mod.rs@@ -4,7 +4,7 @@ mod jsdoc;mod unit;pub use go::Go;-use harper_core::Span;+use harper_lib::Span;pub use javadoc::JavaDoc;pub use jsdoc::JsDoc;pub use unit::Unit;diff --git a/harper-comments/src/comment_parsers/unit.rs b/harper-comments/src/comment_parsers/unit.rsindex 324225ca5..9735e8705 100644--- a/harper-comments/src/comment_parsers/unit.rs+++ b/harper-comments/src/comment_parsers/unit.rs@@ -1,5 +1,6 @@use harper_core::parsers::{Markdown, Parser};-use harper_core::{Span, Token};+use harper_core::Token;+use harper_lib::Span;use super::without_initiators;diff --git a/harper-core/Cargo.toml b/harper-core/Cargo.tomlindex 2ffa4a2f3..99a93dc89 100644--- a/harper-core/Cargo.toml+++ b/harper-core/Cargo.toml@@ -12,6 +12,7 @@ name = "force-build"path = "build.rs"[dependencies]+harper-lib = { path = "../harper-lib", version = "0.12.0" }harper-dictionary-parsing = { path = "../harper-dictionary-parsing", version = "0.12.0" }blanket = "0.4.0"fst = "0.4.7"@@ -35,6 +36,7 @@ rand = "0.8.5"[build-dependencies]fst = "0.4.7"+harper-lib = { path = "../harper-lib", version = "0.12.0" }harper-dictionary-parsing = { path = "../harper-dictionary-parsing", version = "0.12.0" }hashbrown = { version = "0.15.0" }itertools = "0.13.0"diff --git a/harper-core/build.rs b/harper-core/build.rsindex 996df9bd9..fddb69a0a 100644--- a/harper-core/build.rs+++ b/harper-core/build.rs@@ -2,9 +2,8 @@ use std::fs::File;use std::io;use fst::MapBuilder;-use harper_dictionary_parsing::{- parse_default_attribute_list, parse_default_word_list, CharString,-};+use harper_dictionary_parsing::{parse_default_attribute_list, parse_default_word_list};+use harper_lib::CharString;use hashbrown::HashMap;use itertools::Itertools;diff --git a/harper-core/src/lib.rs b/harper-core/src/lib.rsindex ac55825b7..493cae690 100644--- a/harper-core/src/lib.rs+++ b/harper-core/src/lib.rs@@ -18,9 +18,6 @@ mod vec_ext;use std::collections::VecDeque;pub use document::Document;-pub use harper_dictionary_parsing::char_string::{CharString, CharStringExt};-pub use harper_dictionary_parsing::span::Span;-pub use harper_dictionary_parsing::{word_metadata::Tense, WordMetadata};use linting::Lint;pub use mask::{Mask, Masker};pub use punctuation::{Punctuation, Quote};@@ -29,6 +26,10 @@ pub use sync::Lrc;pub use token::{FatToken, Token, TokenKind, TokenStringExt};pub use vec_ext::VecExt;+use harper_lib::Span;+use harper_lib::WordMetadata;+use harper_lib::{CharString, CharStringExt};+/// A utility function that removes overlapping lints in a vector,/// keeping the more important ones.///diff --git a/harper-core/src/spell/fst_dictionary.rs b/harper-core/src/spell/fst_dictionary.rsindex 9ae2dcc03..59cea11aa 100644--- a/harper-core/src/spell/fst_dictionary.rs+++ b/harper-core/src/spell/fst_dictionary.rs@@ -1,11 +1,12 @@use super::{seq_to_normalized, FullDictionary};use fst::{map::StreamWithState, IntoStreamer, Map as FstMap, Streamer};+use harper_lib::CharStringExt;use hashbrown::HashMap;use itertools::Itertools;use levenshtein_automata::{LevenshteinAutomatonBuilder, DFA};use std::{cell::RefCell, sync::Arc};-use crate::{CharString, CharStringExt, WordMetadata};+use crate::{CharString, WordMetadata};use super::Dictionary;@@ -185,9 +186,10 @@ impl Dictionary for FstDictionary {#[cfg(test)]mod tests {+ use harper_lib::CharStringExt;use itertools::Itertools;- use crate::{spell::seq_to_normalized, CharStringExt, Dictionary};+ use crate::{spell::seq_to_normalized, Dictionary};use super::FstDictionary;diff --git a/harper-core/src/spell/full_dictionary.rs b/harper-core/src/spell/full_dictionary.rsindex 8d3a5f038..f0779a615 100644--- a/harper-core/src/spell/full_dictionary.rs+++ b/harper-core/src/spell/full_dictionary.rs@@ -1,11 +1,12 @@use super::{edit_distance_min_alloc, seq_to_normalized};+use harper_lib::CharStringExt;use hashbrown::HashMap;use itertools::Itertools;use smallvec::{SmallVec, ToSmallVec};use std::sync::Arc;use super::dictionary::Dictionary;-use crate::{CharString, CharStringExt, WordMetadata};+use crate::{CharString, WordMetadata};use harper_dictionary_parsing::{parse_default_attribute_list, parse_default_word_list};/// A full, fat dictionary.@@ -248,7 +249,7 @@ impl Dictionary for FullDictionary {#[cfg(test)]mod tests {- use harper_dictionary_parsing::CharString;+ use harper_lib::CharString;use itertools::Itertools;use crate::{Dictionary, FullDictionary};diff --git a/harper-core/src/spell/merged_dictionary.rs b/harper-core/src/spell/merged_dictionary.rsindex 6569b3ab3..717e064f3 100644--- a/harper-core/src/spell/merged_dictionary.rs+++ b/harper-core/src/spell/merged_dictionary.rs@@ -1,6 +1,7 @@-use itertools::Itertools;use std::sync::Arc;+use itertools::Itertools;+use super::dictionary::Dictionary;use crate::{CharString, WordMetadata};diff --git a/harper-core/src/token.rs b/harper-core/src/token.rsindex 74efdcc5e..dd0ca2fc6 100644--- a/harper-core/src/token.rs+++ b/harper-core/src/token.rs@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};use crate::punctuation::Punctuation;use crate::Span;use crate::{Quote, WordMetadata};-use harper_dictionary_parsing::word_metadata::{ConjunctionData, NounData};+use harper_lib::word_metadata::{ConjunctionData, NounData};#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Default)]pub struct Token {diff --git a/harper-dictionary-parsing/Cargo.toml b/harper-dictionary-parsing/Cargo.tomlindex 1b6de9a07..06254e3dc 100644--- a/harper-dictionary-parsing/Cargo.toml+++ b/harper-dictionary-parsing/Cargo.toml@@ -7,8 +7,8 @@ license = "Apache-2.0"repository = "https://github.com/elijah-potter/harper"[dependencies]+harper-lib = { path = "../harper-lib", version = "0.12.0" }hashbrown = { version = "0.15.0", features = ["serde"] }-is-macro = "0.3.6"serde = { version = "1.0.209", features = ["derive"] }serde_json = "1.0.132"smallvec = { version = "1.13.2", features = ["serde"] }diff --git a/harper-dictionary-parsing/src/attribute_list.rs b/harper-dictionary-parsing/src/attribute_list.rsindex 182d29fbb..eabe0ce68 100644--- a/harper-dictionary-parsing/src/attribute_list.rs+++ b/harper-dictionary-parsing/src/attribute_list.rs@@ -6,7 +6,7 @@ use super::affix_replacement::AffixReplacement;use super::expansion::{Expansion, HumanReadableExpansion};use super::word_list::MarkedWord;use super::Error;-use crate::{CharString, Span, WordMetadata};+use harper_lib::{CharString, Span, WordMetadata};#[derive(Debug, Clone)]pub struct AttributeList {diff --git a/harper-dictionary-parsing/src/expansion.rs b/harper-dictionary-parsing/src/expansion.rsindex 3711681b9..c0f22dc28 100644--- a/harper-dictionary-parsing/src/expansion.rs+++ b/harper-dictionary-parsing/src/expansion.rs@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};use super::affix_replacement::{AffixReplacement, HumanReadableAffixReplacement};use super::Error;-use crate::WordMetadata;+use harper_lib::WordMetadata;#[derive(Debug, Clone)]pub struct Expansion {diff --git a/harper-dictionary-parsing/src/lib.rs b/harper-dictionary-parsing/src/lib.rsindex f3f132f4a..1d0b0efd9 100644--- a/harper-dictionary-parsing/src/lib.rs+++ b/harper-dictionary-parsing/src/lib.rs@@ -1,22 +1,14 @@mod affix_replacement;mod attribute_list;-pub mod char_string;mod error;mod expansion;mod matcher;-pub mod span;-pub mod word_list;-pub mod word_metadata;+mod word_list;pub use attribute_list::AttributeList;use attribute_list::HumanReadableAttributeList;-pub use char_string::{CharString, CharStringExt};pub use error::Error;-pub use span::Span;-pub use word_metadata::WordMetadata;--use self::word_list::parse_word_list;-pub use self::word_list::MarkedWord;+pub use word_list::{parse_word_list, MarkedWord};pub fn parse_default_word_list() -> Result<Vec<MarkedWord>, Error> {parse_word_list(include_str!("../dictionary.dict"))@@ -40,7 +32,7 @@ mod tests {use super::word_list::parse_word_list;use super::{parse_default_attribute_list, parse_default_word_list};use crate::attribute_list::HumanReadableAttributeList;- use crate::{CharString, WordMetadata};+ use harper_lib::{CharString, WordMetadata};pub const TEST_WORD_LIST: &str = "3\nhello\ntry/B\nwork/AB";diff --git a/harper-dictionary-parsing/src/word_list.rs b/harper-dictionary-parsing/src/word_list.rsindex 7d7240f95..03155b408 100644--- a/harper-dictionary-parsing/src/word_list.rs+++ b/harper-dictionary-parsing/src/word_list.rs@@ -1,5 +1,5 @@use super::Error;-use crate::CharString;+use harper_lib::CharString;#[derive(Debug, Clone)]pub struct MarkedWord {diff --git a/harper-lib/Cargo.toml b/harper-lib/Cargo.tomlindex 18de14d36..b5f028c1d 100644--- a/harper-lib/Cargo.toml+++ b/harper-lib/Cargo.toml@@ -1,6 +1,9 @@[package]name = "harper-lib"-version = "0.1.0"+version = "0.12.0"edition = "2021"[dependencies]+is-macro = "0.3.6"+serde = { version = "1.0.209", features = ["derive"] }+smallvec = { version = "1.13.2", features = ["serde"] }diff --git a/harper-dictionary-parsing/src/char_string.rs b/harper-lib/src/char_string.rssimilarity index 100%rename from harper-dictionary-parsing/src/char_string.rsrename to harper-lib/src/char_string.rsdiff --git a/harper-lib/src/lib.rs b/harper-lib/src/lib.rsindex b93cf3ffd..3fddb6303 100644--- a/harper-lib/src/lib.rs+++ b/harper-lib/src/lib.rs@@ -1,14 +1,7 @@-pub fn add(left: u64, right: u64) -> u64 {- left + right-}+mod char_string;+mod span;+pub mod word_metadata;-#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn it_works() {- let result = add(2, 2);- assert_eq!(result, 4);- }-}+pub use char_string::{CharString, CharStringExt};+pub use span::Span;+pub use word_metadata::WordMetadata;diff --git a/harper-dictionary-parsing/src/span.rs b/harper-lib/src/span.rssimilarity index 100%rename from harper-dictionary-parsing/src/span.rsrename to harper-lib/src/span.rsdiff --git a/harper-dictionary-parsing/src/word_metadata.rs b/harper-lib/src/word_metadata.rssimilarity index 100%rename from harper-dictionary-parsing/src/word_metadata.rsrename to harper-lib/src/word_metadata.rsdiff --git a/harper-ls/Cargo.toml b/harper-ls/Cargo.tomlindex 5003c6068..dd671b9af 100644--- a/harper-ls/Cargo.toml+++ b/harper-ls/Cargo.toml@@ -8,6 +8,7 @@ readme = "README.md"repository = "https://github.com/elijah-potter/harper"[dependencies]+harper-lib = { path = "../harper-lib", version = "0.12.0" }harper-core = { path = "../harper-core", version = "0.12.0", features = ["concurrent"] }harper-comments = { path = "../harper-comments", version = "0.12.0" }harper-html = { path = "../harper-html", version = "0.12.0" }diff --git a/harper-ls/src/backend.rs b/harper-ls/src/backend.rsindex 7c914479f..170a54dbc 100644--- a/harper-ls/src/backend.rs+++ b/harper-ls/src/backend.rs@@ -8,9 +8,9 @@ use harper_core::linting::{LintGroup, Linter};use harper_core::parsers::{CollapseIdentifiers, IsolateEnglish, Markdown, Parser, PlainEnglish};use harper_core::{Dictionary, Document, FstDictionary, FullDictionary, MergedDictionary, Token, TokenKind,- WordMetadata,};use harper_html::HtmlParser;+use harper_lib::WordMetadata;use serde_json::Value;use tokio::sync::{Mutex, RwLock};use tower_lsp::jsonrpc::Result;diff --git a/harper-ls/src/dictionary_io.rs b/harper-ls/src/dictionary_io.rsindex 0884a911e..2c001274a 100644--- a/harper-ls/src/dictionary_io.rs+++ b/harper-ls/src/dictionary_io.rs@@ -1,6 +1,7 @@use std::path::Path;-use harper_core::{Dictionary, FullDictionary, WordMetadata};+use harper_core::{Dictionary, FullDictionary};+use harper_lib::WordMetadata;use tokio::fs::{self, File};use tokio::io::{self, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader, BufWriter};diff --git a/harper-ls/src/pos_conv.rs b/harper-ls/src/pos_conv.rsindex 93b9e11c0..062b5c644 100644--- a/harper-ls/src/pos_conv.rs+++ b/harper-ls/src/pos_conv.rs@@ -1,4 +1,4 @@-use harper_core::Span;+use harper_lib::Span;use tower_lsp::lsp_types::{Position, Range};/// This module includes various conversions from the index-based [`Span`]s thatdiff --git a/harper-tree-sitter/Cargo.toml b/harper-tree-sitter/Cargo.tomlindex bec99fc23..5ef613b58 100644--- a/harper-tree-sitter/Cargo.toml+++ b/harper-tree-sitter/Cargo.toml@@ -7,5 +7,6 @@ license = "Apache-2.0"repository = "https://github.com/elijah-potter/harper"[dependencies]+harper-lib = { path = "../harper-lib", version = "0.12.0" }harper-core = { path = "../harper-core", version = "0.12.0" }tree-sitter = "0.20.10"diff --git a/harper-tree-sitter/src/lib.rs b/harper-tree-sitter/src/lib.rsindex abb09aa88..037974b5e 100644--- a/harper-tree-sitter/src/lib.rs+++ b/harper-tree-sitter/src/lib.rs@@ -1,6 +1,7 @@use std::collections::HashSet;-use harper_core::{FullDictionary, Mask, Masker, Span, WordMetadata};+use harper_core::{FullDictionary, Mask, Masker};+use harper_lib::{Span, WordMetadata};use tree_sitter::{Language, Node, Tree, TreeCursor};/// A Harper [`Masker`] that wraps a given tree-sitter language and a condition,diff --git a/harper-wasm/Cargo.toml b/harper-wasm/Cargo.tomlindex 6a79bc160..dc88ecc96 100644--- a/harper-wasm/Cargo.toml+++ b/harper-wasm/Cargo.toml@@ -14,6 +14,7 @@ console_error_panic_hook = "0.1.7"tracing = "0.1.40"tracing-wasm = "0.2.1"wasm-bindgen = "0.2.95"+harper-lib = { path = "../harper-lib", version = "0.12.0" }harper-core = { path = "../harper-core", version = "0.12.0", features = ["concurrent"] }once_cell = "1.20.2"serde-wasm-bindgen = "0.6.5"diff --git a/harper-wasm/src/lib.rs b/harper-wasm/src/lib.rsindex 7a404504c..895dd5b7e 100644--- a/harper-wasm/src/lib.rs+++ b/harper-wasm/src/lib.rs@@ -6,6 +6,7 @@ use harper_core::language_detection::is_doc_likely_english;use harper_core::linting::{LintGroup, LintGroupConfig, Linter};use harper_core::parsers::{IsolateEnglish, Markdown, PlainEnglish};use harper_core::{remove_overlaps, Document, FstDictionary, Lrc};+use harper_lib::Span as HarperSpan;use once_cell::sync::Lazy;use wasm_bindgen::prelude::wasm_bindgen;use wasm_bindgen::JsValue;@@ -86,7 +87,7 @@ pub fn apply_suggestion(suggestion: &Suggestion,) -> Result<String, String> {let mut source: Vec<_> = text.chars().collect();- let span: harper_core::Span = span.into();+ let span: HarperSpan = span.into();suggestion.inner.apply(span, &mut source);@@ -184,14 +185,14 @@ impl Span {}}-impl From<Span> for harper_core::Span {- fn from(value: Span) -> Self {- harper_core::Span::new(value.start, value.end)+impl From<HarperSpan> for Span {+ fn from(value: HarperSpan) -> Self {+ Span::new(value.start, value.end)}}-impl From<harper_core::Span> for Span {- fn from(value: harper_core::Span) -> Self {- Span::new(value.start, value.end)+impl From<Span> for HarperSpan {+ fn from(value: Span) -> Self {+ HarperSpan::new(value.start, value.end)}}