Skip to content

Commit

Permalink
feat: have simple_lookup plugins suggest alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Dec 25, 2022
1 parent b14872c commit 62ec998
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/tailwind-parse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version = "0.11.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
eddie = "0.4.2"
itertools = "0.10.5"
nom = "7.1.1"
nom_locate = "4.0.0"
Expand Down
10 changes: 9 additions & 1 deletion crates/tailwind-parse/src/eval/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,15 @@ fn simple_lookup<'a>(
hashmap
.get(search)
.map(|val| to_lit(&[(output, val)]))
.ok_or_else(|| vec![])
.ok_or_else(|| {
let sort = eddie::Levenshtein::new();
hashmap
.keys()
.sorted_by_key(|val| sort.distance(search, val))
.copied()
.take(5)
.collect()
})
}

fn simple_lookup_map<'a, V>(
Expand Down

0 comments on commit 62ec998

Please sign in to comment.