aboutsummaryrefslogtreecommitdiff
path: root/bin/src/fix
diff options
context:
space:
mode:
Diffstat (limited to 'bin/src/fix')
-rw-r--r--bin/src/fix/single.rs23
1 files changed, 9 insertions, 14 deletions
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<TextSize, SingleFix
15 for (l, _) in src 15 for (l, _) in src
16 .split_inclusive('\n') 16 .split_inclusive('\n')
17 .zip(1..) 17 .zip(1..)
18 .take_while(|(_, i)| i < &line) 18 .take_while(|(_, i)| *i < line)
19 { 19 {
20 byte += TextSize::of(l); 20 byte += TextSize::of(l);
21 } 21 }
@@ -29,7 +29,6 @@ fn pos_to_byte(line: usize, col: usize, src: &str) -> Result<TextSize, SingleFix
29} 29}
30 30
31fn find(offset: TextSize, src: &str) -> Result<Report, SingleFixErr> { 31fn find(offset: TextSize, src: &str) -> Result<Report, SingleFixErr> {
32 let offset = offset - TextSize::from(1u32);
33 // we don't really need the source to form a completely parsed tree 32 // we don't really need the source to form a completely parsed tree
34 let parsed = rnix::parse(src); 33 let parsed = rnix::parse(src);
35 34
@@ -38,22 +37,18 @@ fn find(offset: TextSize, src: &str) -> Result<Report, SingleFixErr> {
38 .preorder_with_tokens() 37 .preorder_with_tokens()
39 .filter_map(|event| match event { 38 .filter_map(|event| match event {
40 WalkEvent::Enter(child) => { 39 WalkEvent::Enter(child) => {
41 if child.text_range().start() == offset { 40 LINTS.get(&child.kind()).map(|rules| {
42 LINTS.get(&child.kind()).map(|rules| { 41 rules
43 rules 42 .iter()
44 .iter() 43 .filter_map(|rule| rule.validate(&child))
45 .filter_map(|rule| rule.validate(&child)) 44 .filter(|report| report.total_suggestion_range().is_some())
46 .filter(|report| report.total_suggestion_range().is_some()) 45 .next()
47 .next() 46 })
48 })
49 } else {
50 None
51 }
52 } 47 }
53 _ => None, 48 _ => None,
54 }) 49 })
55 .flatten() 50 .flatten()
56 .next() 51 .find(|report| report.total_diagnostic_range().unwrap().contains(offset))
57 .ok_or(SingleFixErr::NoOp) 52 .ok_or(SingleFixErr::NoOp)
58} 53}
59 54