From e2cccc436ea3b1b34db068eb41f4fc6061feb410 Mon Sep 17 00:00:00 2001 From: Sven Thiele Date: Mon, 3 Oct 2022 14:33:51 +0200 Subject: [PATCH] Flush unformated text if fmt: off is active til the end of the file --- src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a9e0ec2..e5a6051 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,8 +2,7 @@ use anyhow::Result; use log::{debug, warn}; use std::io::Write; -const SOFT_FLUSH_LIMIT :usize = 60; - +const SOFT_FLUSH_LIMIT: usize = 60; #[cfg(test)] mod tests; @@ -221,6 +220,12 @@ pub fn format_program( match node.kind() { "source_file" => { formatter.finish_program()?; + if skip_fmt { + let unformated_text = + std::str::from_utf8(&source_code[start_unformatted..node.end_byte()]) + .unwrap(); + write!(formatter.out, "{}", unformated_text)?; + } } "statement" => short_cut = false, _ => {}