Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

Merge branch 'master' into local-stats

Elijah Potter7e4a7b85633b
diff --cc Cargo.lock
index f083bc164,e475126bf..df52edfc3
--- a/Cargo.lock
+++ b/Cargo.lock
@@@ -626,8 -605,8 +626,9 @@@ dependencies =
"harper-comments",
"harper-core",
"harper-literate-haskell",
+ "harper-stats",
"harper-typst",
+ "serde",
"serde_json",
]
@@@ -734,19 -712,9 +735,19 @@@ dependencies =
"tracing-subscriber",
]
+[[package]]
+name = "harper-stats"
+version = "0.16.0"
+dependencies = [
+ "csv",
+ "harper-core",
+ "serde",
+ "uuid",
+]
+
[[package]]
name = "harper-tree-sitter"
- version = "0.16.0"
+ version = "0.17.0"
dependencies = [
"harper-core",
"tree-sitter",
diff --cc harper-cli/Cargo.toml
index 880f6d245,b2a5c8a51..142360635
--- a/harper-cli/Cargo.toml
+++ b/harper-cli/Cargo.toml
@@@ -9,13 -9,13 +9,14 @@@ repository = "https://github.com/automa
[dependencies]
anyhow = "1.0.95"
ariadne = "0.4.1"
- clap = { version = "4.5.23", features = ["derive"] }
- harper-literate-haskell = { path = "../harper-literate-haskell", version = "0.16.0" }
- harper-core = { path = "../harper-core", version = "0.16.0" }
- harper-comments = { path = "../harper-comments", version = "0.16.0" }
- harper-typst = { path = "../harper-typst", version = "0.16.0" }
- harper-stats = { path = "../harper-stats", version = "0.16.0" }
- serde_json = "1.0.135"
+ clap = { version = "4.5.27", features = ["derive"] }
+ harper-literate-haskell = { path = "../harper-literate-haskell", version = "0.17.0" }
+ harper-core = { path = "../harper-core", version = "0.17.0" }
+ harper-comments = { path = "../harper-comments", version = "0.17.0" }
+ harper-typst = { path = "../harper-typst", version = "0.17.0" }
++harper-stats = { path = "../harper-stats", version = "0.17.0" }
+ serde = { version = "1.0.214", features = ["derive"] }
+ serde_json = "1.0.137"
[features]
default = []
diff --cc harper-cli/src/main.rs
index fa9e043b0,caea919c0..fbf1b9df1
--- a/harper-cli/src/main.rs
+++ b/harper-cli/src/main.rs
@@@ -1,7 -1,6 +1,8 @@@
#![doc = include_str!("../README.md")]
+ use std::collections::{BTreeMap, HashMap};
+use std::fs::File;
+use std::io::BufReader;
use std::path::{Path, PathBuf};
use anyhow::format_err;
@@@ -12,7 -11,7 +13,8 @@@ use harper_core::linting::{LintGroup, L
use harper_core::parsers::{Markdown, MarkdownOptions};
use harper_core::{remove_overlaps, Dictionary, Document, FstDictionary, TokenKind};
use harper_literate_haskell::LiterateHaskellParser;
+use harper_stats::Stats;
+ use serde::Serialize;
/// A debugging tool for the Harper grammar checker.
#[derive(Debug, Parser)]
@@@ -44,8 -43,8 +46,10 @@@ enum Args
Metadata { word: String },
/// Emit a decompressed, line-separated list of the words in Harper's dictionary.
Words,
+ /// Summarize a lint record
+ SummarizeLintRecord { file: PathBuf },
+ /// Print the default config with descriptions.
+ Config,
}
fn main() -> anyhow::Result<()> {
@@@ -172,14 -169,33 +174,43 @@@
Ok(())
}
+ Args::SummarizeLintRecord { file } => {
+ let file = File::open(file)?;
+ let mut reader = BufReader::new(file);
+ let stats = Stats::read_csv(&mut reader)?;
+
+ let summary = stats.summarize_lints_applied();
+ println!("{summary}");
+
++ Ok(())
++ }
+ Args::Config => {
+ #[derive(Serialize)]
+ struct Config {
+ default_value: bool,
+ description: String,
+ }
+
+ let mut linter = LintGroup::new(linting_options, dictionary);
+ linter.config.fill_default_values();
+
+ let default_config: HashMap<String, bool> =
+ serde_json::from_str(&serde_json::to_string(&linter.config).unwrap()).unwrap();
+
+ // Use `BTreeMap` so output is sorted by keys.
+ let mut configs = BTreeMap::new();
+ for (key, desc) in linter.all_descriptions().to_vec_pairs() {
+ configs.insert(
+ key.to_owned(),
+ Config {
+ default_value: default_config[key],
+ description: desc.to_owned(),
+ },
+ );
+ }
+
+ println!("{}", serde_json::to_string_pretty(&configs).unwrap());
+
Ok(())
}
}
diff --cc harper-ls/Cargo.toml
index 1a594448b,883b554e8..bac4ef196
--- a/harper-ls/Cargo.toml
+++ b/harper-ls/Cargo.toml
@@@ -8,15 -8,14 +8,15 @@@ readme = "README.md
repository = "https://github.com/automattic/harper"
[dependencies]
- harper-literate-haskell = { path = "../harper-literate-haskell", version = "0.16.0" }
- harper-core = { path = "../harper-core", version = "0.16.0", features = ["concurrent"] }
- harper-stats = { path = "../harper-stats", version = "0.16.0" }
- harper-comments = { path = "../harper-comments", version = "0.16.0" }
- harper-typst = { path = "../harper-typst", version = "0.16.0" }
- harper-html = { path = "../harper-html", version = "0.16.0" }
+ harper-literate-haskell = { path = "../harper-literate-haskell", version = "0.17.0" }
+ harper-core = { path = "../harper-core", version = "0.17.0", features = ["concurrent"] }
++harper-stats = { path = "../harper-stats", version = "0.17.0" }
+ harper-comments = { path = "../harper-comments", version = "0.17.0" }
+ harper-typst = { path = "../harper-typst", version = "0.17.0" }
+ harper-html = { path = "../harper-html", version = "0.17.0" }
tower-lsp = "0.20.0"
tokio = { version = "1.43.0", features = ["fs", "rt", "rt-multi-thread", "macros", "io-std", "io-util", "net"] }
- clap = { version = "4.5.23", features = ["derive"] }
+ clap = { version = "4.5.27", features = ["derive"] }
once_cell = "1.20.2"
dirs = "6.0.0"
anyhow = "1.0.95"
diff --cc harper-ls/src/config.rs
index fc296e11e,cc56963b5..1435e2754
--- a/harper-ls/src/config.rs
+++ b/harper-ls/src/config.rs
@@@ -94,21 -96,16 +97,24 @@@ impl Config
}
if let Some(v) = value.get("fileDictPath") {
- if let Value::String(path) = v {
- base.file_dict_path = path.try_resolve()?.to_path_buf();
- } else {
+ if !v.is_string() {
bail!("fileDict path must be a string.");
}
+
+ let path = v.as_str().unwrap();
+ if !path.is_empty() {
+ base.file_dict_path = path.try_resolve()?.to_path_buf();
+ }
}
+ if let Some(v) = value.get("statsPath") {
+ if let Value::String(path) = v {
+ base.file_dict_path = path.try_resolve()?.to_path_buf();
+ } else {
+ bail!("fileDict path must be a string.");
+ }
+ }
+
if let Some(v) = value.get("linters") {
base.lint_config = serde_json::from_value(v.clone())?;
}