From 0c5f5082dcaf19944abc17d8b2275a6dc35a0e9b Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 23 Apr 2015 17:04:07 +1200 Subject: [PATCH] terminating newline bug --- src/changes.rs | 9 +++++++++ src/functions.rs | 4 ++-- src/lists.rs | 1 + src/mod.rs | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/changes.rs b/src/changes.rs index 741c79a396b..8119dc540ac 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -60,6 +60,8 @@ impl<'a> ChangeSet<'a> { return Vec::new(); } + // idx is the index into file_spans which indicates the current file, we + // with the file start denotes. let mut idx = match self.file_spans.binary_search(&(start.0, ::std::u32::MAX)) { Ok(i) => i, Err(0) => 0, @@ -115,6 +117,13 @@ impl<'a> ChangeSet<'a> { } } + // Append a newline to the end of each file. + pub fn append_newlines(&mut self) { + for (_, s) in self.file_map.iter_mut() { + s.push_str("\n"); + } + } + pub fn write_all_files(&self, mode: WriteMode) -> Result<(HashMap), ::std::io::Error> { diff --git a/src/functions.rs b/src/functions.rs index e7f80922e8a..492754a39aa 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -372,8 +372,9 @@ impl<'a> FmtVisitor<'a> { result.push_str(&make_indent(indent + 4)); result.push_str("where "); + let comments = vec![String::new(); where_clause.predicates.len()]; // TODO uncomment when spans are fixed - //println!("{:?} {:?}", where_clause.predicates.iter().map(|p| self.snippet(span_for_where_pred(p))).collect::>(), next_span.lo); + // println!("{:?} {:?}", where_clause.predicates.iter().map(|p| self.snippet(span_for_where_pred(p))).collect::>(), next_span.lo); // let comments = self.make_comments_for_list(Vec::new(), // where_clause.predicates.iter(), // ",", @@ -381,7 +382,6 @@ impl<'a> FmtVisitor<'a> { // |pred| span_for_where_pred(pred).lo, // |pred| span_for_where_pred(pred).hi, // next_span.lo); - let comments = vec![String::new(); where_clause.predicates.len()]; let where_strs: Vec<_> = where_clause.predicates.iter() .map(|p| (self.rewrite_pred(p))) .zip(comments.into_iter()) diff --git a/src/lists.rs b/src/lists.rs index 01bad45b6af..4f443475afa 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -29,6 +29,7 @@ pub enum SeparatorTactic { Vertical, } +// TODO having some helpful ctors for ListFormatting would be nice. pub struct ListFormatting<'a> { pub tactic: ListTactic, pub separator: &'a str, diff --git a/src/mod.rs b/src/mod.rs index 44af8b08baf..3720eaad192 100644 --- a/src/mod.rs +++ b/src/mod.rs @@ -24,7 +24,6 @@ // dead spans (comments) - in where clause (wait for fixed spans, test) // // Smoke testing till we can use it -// ** no newline at the end of doc.rs // take config options from a file #[macro_use] @@ -214,6 +213,9 @@ impl<'a> CompilerCalls<'a> for RustFmtCalls { let krate = state.krate.unwrap(); let codemap = state.session.codemap(); let mut changes = fmt_ast(krate, codemap); + // For some reason, the codemap does not include terminating newlines + // so we must add one on for each file. This is sad. + changes.append_newlines(); fmt_lines(&mut changes); // FIXME(#5) Should be user specified whether to show or replace.