Skip to content

Commit

Permalink
fix(core): overlap removal algorithm missed some
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Jan 3, 2025
1 parent 28448ad commit c956a02
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions harper-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod token_kind;
mod vec_ext;
mod word_metadata;

use std::collections::VecDeque;
use std::{collections::VecDeque, iter::once};

pub use char_string::{CharString, CharStringExt};
pub use document::Document;
Expand All @@ -47,22 +47,17 @@ pub fn remove_overlaps(lints: &mut Vec<Lint>) {
return;
}

lints.sort_by_key(|l| l.span.start);

let mut remove_indices = VecDeque::new();
lints.sort_by_key(|l| (l.span.start, !0 - l.span.end));

for i in 0..lints.len() - 1 {
let cur = &lints[i];
let next = &lints[i + 1];
let mut cur = 0;

if cur.span.overlaps_with(next.span) {
// Remember, lower priority means higher importance.
if next.priority < cur.priority {
remove_indices.push_back(i);
} else {
remove_indices.push_back(i + 1);
}
for (i, lint) in lints.iter().enumerate() {
if lint.span.start < cur {
remove_indices.push_back(i);
continue;
}
cur = lint.span.end;
}

lints.remove_indices(remove_indices);
Expand Down

0 comments on commit c956a02

Please sign in to comment.