Skip to content

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

fix(panic): `harper-ls` crash with `.lua` files

Elijah Potter3d0dde4e505b
diff --git a/harper-core/dictionary.dict b/harper-core/dictionary.dict
index 63190e367..e81061144 100644
--- a/harper-core/dictionary.dict
+++ b/harper-core/dictionary.dict
@@ -40303,7 +40303,7 @@ safe/MYTPRS
safeguard/SMDG
safekeeping/M
safeness/M
-safety/SM
+safety/SMY
safflower/MS
saffron/MS
sag/SM
diff --git a/harper-core/src/linting/matcher.rs b/harper-core/src/linting/matcher.rs
index a6b4b252e..c98b3a4eb 100644
--- a/harper-core/src/linting/matcher.rs
+++ b/harper-core/src/linting/matcher.rs
@@ -101,6 +101,7 @@ impl Matcher {
// This match list needs to be automatically expanded instead of explicitly defined
// like it is now.
let mut triggers = pt! {
+ "my","self" => "myself",
"human","live" => "human life",
"eight","grade" => "eighth grade",
"and","also" => "and",
diff --git a/harper-ls/src/tree_sitter_parser.rs b/harper-ls/src/tree_sitter_parser.rs
index 154590182..f896872e8 100644
--- a/harper-ls/src/tree_sitter_parser.rs
+++ b/harper-ls/src/tree_sitter_parser.rs
@@ -172,10 +172,22 @@ fn is_comment_character(c: char) -> bool {
/// Converts a set of byte-indexed [`Span`]s to char-index Spans, in-place.
/// NOTE: Will sort the given slice by their [`Span::start`].
///
-/// Assumes that none of the Spans are overlapping.
-fn byte_spans_to_char_spans(byte_spans: &mut [Span], source: &str) {
+/// If any spans overlap, it will remove the second one.
+fn byte_spans_to_char_spans(byte_spans: &mut Vec<Span>, source: &str) {
byte_spans.sort_by_key(|s| s.start);
+ let cloned = byte_spans.clone();
+
+ let mut i = 0;
+ byte_spans.retain(|cur| {
+ i += 1;
+ if let Some(prev) = cloned.get(i - 2) {
+ !cur.overlaps_with(*prev)
+ } else {
+ true
+ }
+ });
+
let mut last_byte_pos = 0;
let mut last_char_pos = 0;