Skip to content

Commit

Permalink
terminating newline bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Apr 23, 2015
1 parent 2819738 commit 0c5f508
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<String, String>), ::std::io::Error> {
Expand Down
4 changes: 2 additions & 2 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,16 @@ 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::<Vec<_>>(), next_span.lo);
// println!("{:?} {:?}", where_clause.predicates.iter().map(|p| self.snippet(span_for_where_pred(p))).collect::<Vec<_>>(), next_span.lo);
// let comments = self.make_comments_for_list(Vec::new(),
// where_clause.predicates.iter(),
// ",",
// "{",
// |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())
Expand Down
1 change: 1 addition & 0 deletions src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0c5f508

Please sign in to comment.