use std::io::{self, Write};
use std::path::Path;
-use syntax::source_map::SourceMap;
-
use crate::config::FileName;
use crate::emitter::{self, Emitter};
+use crate::parse::session::ParseSess;
use crate::NewlineStyle;
#[cfg(test)]
#[cfg(test)]
use crate::formatting::FileRecord;
+use rustc_data_structures::sync::Lrc;
+
// Append a newline to the end of each file.
pub(crate) fn append_newline(s: &mut String) {
- s.push_str("\n");
+ s.push('\n');
}
#[cfg(test)]
}
pub(crate) fn write_file<T>(
- source_map: Option<&SourceMap>,
+ parse_sess: Option<&ParseSess>,
filename: &FileName,
formatted_text: &str,
out: &mut T,
}
}
- impl From<&FileName> for syntax_pos::FileName {
- fn from(filename: &FileName) -> syntax_pos::FileName {
+ impl From<&FileName> for rustc_span::FileName {
+ fn from(filename: &FileName) -> rustc_span::FileName {
match filename {
- FileName::Real(path) => syntax_pos::FileName::Real(path.to_owned()),
- FileName::Stdin => syntax_pos::FileName::Custom("stdin".to_owned()),
+ FileName::Real(path) => {
+ rustc_span::FileName::Real(rustc_span::RealFileName::LocalPath(path.to_owned()))
+ }
+ FileName::Stdin => rustc_span::FileName::Custom("stdin".to_owned()),
}
}
}
// source map instead of hitting the file system. This also supports getting
// original text for `FileName::Stdin`.
let original_text = if newline_style != NewlineStyle::Auto && *filename != FileName::Stdin {
- fs::read_to_string(ensure_real_path(filename))?
+ Lrc::new(fs::read_to_string(ensure_real_path(filename))?)
} else {
- match source_map
- .and_then(|x| x.get_source_file(&filename.into()))
- .and_then(|x| x.src.as_ref().map(ToString::to_string))
- {
+ match parse_sess.and_then(|sess| sess.get_original_snippet(filename)) {
Some(ori) => ori,
- None => fs::read_to_string(ensure_real_path(filename))?,
+ None => Lrc::new(fs::read_to_string(ensure_real_path(filename))?),
}
};
let formatted_file = emitter::FormattedFile {
filename,
- original_text: &original_text,
+ original_text: original_text.as_str(),
formatted_text,
};