Skip to content

Commit

Permalink
Fixing incorrect line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed Sep 25, 2024
1 parent 19e0bbd commit 662c6d0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::verbatim::*;
use crate::wrap::*;
use crate::LINE_END;
use log::Level::{Info, Warn};
use std::iter::zip;

/// Central function to format a file
pub fn format_file(
Expand All @@ -25,7 +26,8 @@ pub fn format_file(

let mut state = State::new();

let mut old_lines = old_text.lines().enumerate();
let old_lines = old_text.lines();
let mut old_lines = zip(1.., old_lines);

let mut queue: Vec<(usize, String)> = vec![];
let mut new_text = String::with_capacity(text.len());
Expand All @@ -50,6 +52,7 @@ pub fn format_file(
state = temp_state;
new_text.push_str(&line);
new_text.push_str(LINE_END);
state.linum_new += 1;
}
} else if let Some((linum_old, line)) = old_lines.next() {
queue.push((linum_old, line.to_string()));
Expand Down Expand Up @@ -86,8 +89,8 @@ impl State {
/// Construct a new default state
pub const fn new() -> Self {
Self {
linum_old: 0,
linum_new: 0,
linum_old: 1,
linum_new: 1,
ignore: Ignore::new(),
indent: Indent::new(),
verbatim: Verbatim::new(),
Expand Down
1 change: 0 additions & 1 deletion src/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ pub fn apply_indent(
) -> (String, State) {
let mut new_line = line.to_string();
let mut new_state = state.clone();
new_state.linum_new += 1;
new_state.linum_old = linum_old;

new_state.ignore = get_ignore(line, &new_state, logs, file, true);
Expand Down
4 changes: 2 additions & 2 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ pub fn print_logs(logs: &mut Vec<Log>) {
)
});
logs.dedup_by(|a, b| {
(a.level, a.linum_new, a.linum_old, &a.message)
== (b.level, b.linum_new, b.linum_old, &b.message)
(a.level, &a.file, a.linum_new, a.linum_old, &a.line, &a.message)
== (b.level, &b.file, b.linum_new, b.linum_old, &b.line, &b.message)
});
logs.sort_by_key(|l| l.time);

Expand Down

0 comments on commit 662c6d0

Please sign in to comment.