aboutsummaryrefslogtreecommitdiff
path: root/bin/src/fix/single.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/src/fix/single.rs')
-rw-r--r--bin/src/fix/single.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/bin/src/fix/single.rs b/bin/src/fix/single.rs
index d95cfda..67b6b8f 100644
--- a/bin/src/fix/single.rs
+++ b/bin/src/fix/single.rs
@@ -1,6 +1,6 @@
1use std::{borrow::Cow, convert::TryFrom}; 1use std::{borrow::Cow, convert::TryFrom};
2 2
3use lib::Report; 3use lib::{session::SessionInfo, Report};
4use rnix::{TextSize, WalkEvent}; 4use rnix::{TextSize, WalkEvent};
5 5
6use crate::{err::SingleFixErr, fix::Source, utils}; 6use crate::{err::SingleFixErr, fix::Source, utils};
@@ -27,7 +27,7 @@ fn pos_to_byte(line: usize, col: usize, src: &str) -> Result<TextSize, SingleFix
27 } 27 }
28} 28}
29 29
30fn find(offset: TextSize, src: &str) -> Result<Report, SingleFixErr> { 30fn find(offset: TextSize, src: &str, sess: &SessionInfo) -> Result<Report, SingleFixErr> {
31 // we don't really need the source to form a completely parsed tree 31 // we don't really need the source to form a completely parsed tree
32 let parsed = rnix::parse(src); 32 let parsed = rnix::parse(src);
33 let lints = utils::lint_map(); 33 let lints = utils::lint_map();
@@ -39,7 +39,7 @@ fn find(offset: TextSize, src: &str) -> Result<Report, SingleFixErr> {
39 WalkEvent::Enter(child) => lints.get(&child.kind()).map(|rules| { 39 WalkEvent::Enter(child) => lints.get(&child.kind()).map(|rules| {
40 rules 40 rules
41 .iter() 41 .iter()
42 .filter_map(|rule| rule.validate(&child)) 42 .filter_map(|rule| rule.validate(&child, sess))
43 .find(|report| report.total_suggestion_range().is_some()) 43 .find(|report| report.total_suggestion_range().is_some())
44 }), 44 }),
45 _ => None, 45 _ => None,
@@ -49,10 +49,15 @@ fn find(offset: TextSize, src: &str) -> Result<Report, SingleFixErr> {
49 .ok_or(SingleFixErr::NoOp) 49 .ok_or(SingleFixErr::NoOp)
50} 50}
51 51
52pub fn single(line: usize, col: usize, src: &str) -> Result<SingleFixResult, SingleFixErr> { 52pub fn single<'a, 'b>(
53 line: usize,
54 col: usize,
55 src: &'a str,
56 sess: &'b SessionInfo,
57) -> Result<SingleFixResult<'a>, SingleFixErr> {
53 let mut src = Cow::from(src); 58 let mut src = Cow::from(src);
54 let offset = pos_to_byte(line, col, &*src)?; 59 let offset = pos_to_byte(line, col, &*src)?;
55 let report = find(offset, &*src)?; 60 let report = find(offset, &*src, &sess)?;
56 61
57 report.apply(src.to_mut()); 62 report.apply(src.to_mut());
58 63