From bfc720bf4d8adbb3b1eaff4f3556bc6d1e00849a Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 26 Oct 2021 21:22:41 +0530 Subject: allow stdin input to statix-single --- bin/src/fix/single.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'bin/src/fix') diff --git a/bin/src/fix/single.rs b/bin/src/fix/single.rs index c09c710..4d492f8 100644 --- a/bin/src/fix/single.rs +++ b/bin/src/fix/single.rs @@ -15,7 +15,7 @@ fn pos_to_byte(line: usize, col: usize, src: &str) -> Result Result Result { - let offset = offset - TextSize::from(1u32); // we don't really need the source to form a completely parsed tree let parsed = rnix::parse(src); @@ -38,22 +37,18 @@ fn find(offset: TextSize, src: &str) -> Result { .preorder_with_tokens() .filter_map(|event| match event { WalkEvent::Enter(child) => { - if child.text_range().start() == offset { - LINTS.get(&child.kind()).map(|rules| { - rules - .iter() - .filter_map(|rule| rule.validate(&child)) - .filter(|report| report.total_suggestion_range().is_some()) - .next() - }) - } else { - None - } + LINTS.get(&child.kind()).map(|rules| { + rules + .iter() + .filter_map(|rule| rule.validate(&child)) + .filter(|report| report.total_suggestion_range().is_some()) + .next() + }) } _ => None, }) .flatten() - .next() + .find(|report| report.total_diagnostic_range().unwrap().contains(offset)) .ok_or(SingleFixErr::NoOp) } -- cgit v1.2.3