mirror of
https://github.com/Automattic/harper.git
synced 2025-08-04 18:48:02 +00:00
Merge branch 'master' into add-clojure-support
This commit is contained in:
commit
4e1c767cfe
8 changed files with 43 additions and 28 deletions
25
Cargo.lock
generated
25
Cargo.lock
generated
|
@ -1323,6 +1323,17 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-uring"
|
||||
version = "0.7.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
|
||||
dependencies = [
|
||||
"bitflags 2.9.1",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.11.0"
|
||||
|
@ -1474,9 +1485,9 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
|||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0281c2e25e62316a5c9d98f2d2e9e95a37841afdaf4383c177dbb5c1dfab0568"
|
||||
checksum = "86ea4e65087ff52f3862caff188d489f1fab49a0cb09e01b2e3f1a617b10aaed"
|
||||
dependencies = [
|
||||
"hashbrown 0.15.4",
|
||||
]
|
||||
|
@ -2044,9 +2055,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
|||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.12.20"
|
||||
version = "0.12.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eabf4c97d9130e2bf606614eb937e86edac8292eaa6f422f995d7e8de1eb1813"
|
||||
checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bytes",
|
||||
|
@ -2513,15 +2524,17 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.45.1"
|
||||
version = "1.46.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779"
|
||||
checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
"io-uring",
|
||||
"libc",
|
||||
"mio",
|
||||
"pin-project-lite",
|
||||
"slab",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"windows-sys 0.52.0",
|
||||
|
|
|
@ -352,7 +352,7 @@ fn main() -> anyhow::Result<()> {
|
|||
let rune_words = format!("1\n{line}");
|
||||
let dict = MutableDictionary::from_rune_files(
|
||||
&rune_words,
|
||||
include_str!("../../harper-core/affixes.json"),
|
||||
include_str!("../../harper-core/annotations.json"),
|
||||
)?;
|
||||
|
||||
println!("New, from you:");
|
||||
|
@ -445,7 +445,7 @@ fn main() -> anyhow::Result<()> {
|
|||
use serde_json::Value;
|
||||
|
||||
let dict_path = dir.join("dictionary.dict");
|
||||
let affixes_path = dir.join("affixes.json");
|
||||
let affixes_path = dir.join("annotations.json");
|
||||
|
||||
// Validate old and new flags are exactly one Unicode code point (Rust char)
|
||||
// And not characters used for the dictionary format
|
||||
|
@ -467,27 +467,27 @@ fn main() -> anyhow::Result<()> {
|
|||
|
||||
// Load and parse affixes
|
||||
let affixes_string = fs::read_to_string(&affixes_path)
|
||||
.map_err(|e| anyhow!("Failed to read affixes.json: {e}"))?;
|
||||
.map_err(|e| anyhow!("Failed to read annotations.json: {e}"))?;
|
||||
|
||||
let affixes_json: Value = serde_json::from_str(&affixes_string)
|
||||
.map_err(|e| anyhow!("Failed to parse affixes.json: {e}"))?;
|
||||
.map_err(|e| anyhow!("Failed to parse annotations.json: {e}"))?;
|
||||
|
||||
// Get the nested "affixes" object
|
||||
let affixes_obj = &affixes_json
|
||||
.get("affixes")
|
||||
.and_then(Value::as_object)
|
||||
.ok_or_else(|| anyhow!("affixes.json does not contain 'affixes' object"))?;
|
||||
.ok_or_else(|| anyhow!("annotations.json does not contain 'affixes' object"))?;
|
||||
|
||||
let properties_obj = &affixes_json
|
||||
.get("properties")
|
||||
.and_then(Value::as_object)
|
||||
.ok_or_else(|| anyhow!("affixes.json does not contain 'properties' object"))?;
|
||||
.ok_or_else(|| anyhow!("annotations.json does not contain 'properties' object"))?;
|
||||
|
||||
// Validate old flag exists and get its description
|
||||
let old_entry = affixes_obj
|
||||
.get(&old)
|
||||
.or_else(|| properties_obj.get(&old))
|
||||
.ok_or_else(|| anyhow!("Flag '{old}' not found in affixes.json"))?;
|
||||
.ok_or_else(|| anyhow!("Flag '{old}' not found in annotations.json"))?;
|
||||
|
||||
let description = old_entry
|
||||
.get("#")
|
||||
|
@ -548,7 +548,7 @@ fn main() -> anyhow::Result<()> {
|
|||
|
||||
// Verify that the updated affixes string is valid JSON
|
||||
serde_json::from_str::<Value>(&updated_affixes_string)
|
||||
.map_err(|e| anyhow!("Failed to parse updated affixes.json: {e}"))?;
|
||||
.map_err(|e| anyhow!("Failed to parse updated annotations.json: {e}"))?;
|
||||
|
||||
// Write changes
|
||||
fs::write(&dict_path, updated_dict)
|
||||
|
|
|
@ -26,7 +26,7 @@ unicode-script = "0.5.7"
|
|||
unicode-width = "0.2.1"
|
||||
levenshtein_automata = { version = "0.2.1", features = ["fst_automaton"] }
|
||||
cached = "0.55.1"
|
||||
lru = "0.15.0"
|
||||
lru = "0.16.0"
|
||||
foldhash = "0.1.5"
|
||||
strum_macros = "0.27.1"
|
||||
strum = "0.27.1"
|
||||
|
|
|
@ -33,7 +33,7 @@ fn uncached_inner_new() -> Arc<MutableDictionary> {
|
|||
Arc::new(
|
||||
MutableDictionary::from_rune_files(
|
||||
include_str!("../../dictionary.dict"),
|
||||
include_str!("../../affixes.json"),
|
||||
include_str!("../../annotations.json"),
|
||||
)
|
||||
.expect("Curated dictionary should be valid."),
|
||||
)
|
||||
|
@ -377,7 +377,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn are_merged_attrs_same_as_spread_attrs() {
|
||||
let curated_attr_list = include_str!("../../affixes.json");
|
||||
let curated_attr_list = include_str!("../../annotations.json");
|
||||
|
||||
let merged = MutableDictionary::from_rune_files("1\nblork/DGS", curated_attr_list).unwrap();
|
||||
let spread =
|
||||
|
|
|
@ -15,7 +15,7 @@ harper-comments = { path = "../harper-comments", version = "0.48.0" }
|
|||
harper-typst = { path = "../harper-typst", version = "0.48.0" }
|
||||
harper-html = { path = "../harper-html", version = "0.48.0" }
|
||||
tower-lsp-server = "0.22.0"
|
||||
tokio = { version = "1.45.1", features = ["fs", "rt", "rt-multi-thread", "macros", "io-std", "io-util", "net"] }
|
||||
tokio = { version = "1.46.1", features = ["fs", "rt", "rt-multi-thread", "macros", "io-std", "io-util", "net"] }
|
||||
clap = { version = "4.5.40", features = ["derive"] }
|
||||
once_cell = "1.21.3"
|
||||
dirs = "6.0.0"
|
||||
|
@ -29,7 +29,7 @@ open = "5.3.0"
|
|||
futures = "0.3.31"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
indexmap = { version = "2.10.0", features = ["serde"] }
|
||||
reqwest = { version = "0.12.20", features = ["rustls-tls"], default-features = false }
|
||||
reqwest = { version = "0.12.22", features = ["rustls-tls"], default-features = false }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
8
justfile
8
justfile
|
@ -438,10 +438,10 @@ registerlinter module name:
|
|||
sed -i "/insert_expr_rule!(ChockFull, true);/a \ \ \ \ insert_struct_rule!({{name}}, true);" "$D/lint_group.rs"
|
||||
just format
|
||||
|
||||
# Print affixes and their descriptions from affixes.json
|
||||
# Print affixes and their descriptions from annotations.json
|
||||
printaffixes:
|
||||
#! /usr/bin/env node
|
||||
const affixesData = require('{{justfile_directory()}}/harper-core/affixes.json');
|
||||
const affixesData = require('{{justfile_directory()}}/harper-core/annotations.json');
|
||||
const allAffixes = {
|
||||
...affixesData.affixes || {},
|
||||
...affixesData.properties || {}
|
||||
|
@ -508,8 +508,8 @@ newest-dict-changes *numCommits:
|
|||
if (showDiff) console.log(`DIFFSTART\n${diffString}\nDIFFEND`);
|
||||
|
||||
// uncomment first line to use in justfile, comment out second line to use standalone
|
||||
const affixes = require('{{justfile_directory()}}/harper-core/affixes.json').affixes;
|
||||
// const affixes = require('./harper-core/affixes.json').affixes;
|
||||
const affixes = require('{{justfile_directory()}}/harper-core/annotations.json').affixes;
|
||||
// const affixes = require('./harper-core/annotations.json').affixes;
|
||||
|
||||
diffString.split("\n").forEach(line => {
|
||||
const match = line.match(/^(?:\[-(.*?)-\])?(?:\{\+(.*?)\+\})?$/);
|
||||
|
|
|
@ -9,15 +9,17 @@ If this happens to you, please open a PR to get them in.
|
|||
PR [#343](https://github.com/Automattic/harper/pull/343) is a practical example of the ideas described here.
|
||||
|
||||
There are two files you need to worry about.
|
||||
[`harper-core/dictionary.dict`](https://github.com/Automattic/harper/blob/master/harper-core/dictionary.dict) and [`harper-core/affixes.json`](https://github.com/Automattic/harper/blob/master/harper-core/affixes.json).
|
||||
[`harper-core/dictionary.dict`](https://github.com/Automattic/harper/blob/master/harper-core/dictionary.dict) and [`harper-core/annotations.json`](https://github.com/Automattic/harper/blob/master/harper-core/annotations.json) (formerly `affixes.json`).
|
||||
The first is a list of words, tagged with modifiers defined in the second.
|
||||
|
||||
For example, all words, such as "move", tagged with `L`, will be expanded to two dictionary entries, "move" and "movement".
|
||||
In `affixes.json`, this expansion rule looks like this:
|
||||
In `annotations.json`, this expansion rule looks like this:
|
||||
|
||||
```js title=affixes.json
|
||||
```js title=annotations.json
|
||||
{
|
||||
"L": {
|
||||
// A description of the rule.
|
||||
"#": "'-ment' suffix",
|
||||
// Denotes that the area of interest is at the _end_ of the base word.
|
||||
"kind": "suffix",
|
||||
// Declare that it is OK to use the result of the expansion with other expansions.
|
||||
|
@ -33,9 +35,9 @@ In `affixes.json`, this expansion rule looks like this:
|
|||
}
|
||||
],
|
||||
// The word metadata that should be applied to the expanded word.
|
||||
"adds_metadata": {},
|
||||
"target": {},
|
||||
// The word metadata that should be applied to the base word.
|
||||
"gifts_metadata": {}
|
||||
"base_metadata": {}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue