fn span_to_filename(&self, sp: Span) -> FileName;
fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>;
fn call_span_if_macro(&self, sp: Span) -> Span;
+ fn load_source_for_filemap(&mut self, file: FileName) -> bool;
}
impl CodeSuggestion {
crate_of_origin: crate_of_origin,
src: None,
src_hash: src_hash,
+ external_src: RefCell::new(ExternalSource::AbsentOk),
start_pos: start_pos,
end_pos: end_pos,
lines: RefCell::new(file_local_lines),
}
sp
}
+ fn load_source_for_filemap(&mut self, filename: FileName) -> bool {
+ let file_map = if let Some(fm) = self.get_filemap(&filename) {
+ fm
+ } else {
+ return false;
+ };
+
+ if *file_map.external_src.borrow() == ExternalSource::AbsentOk {
+ let mut external_src = file_map.external_src.borrow_mut();
+ if let Ok(src) = self.file_loader.read_file(Path::new(&filename)) {
+ *external_src = ExternalSource::Present(src);
+ return true;
+ } else {
+ *external_src = ExternalSource::AbsentErr;
+ }
+ }
+
+ false
+ }
}
#[derive(Clone)]
pub bytes: usize,
}
+#[derive(PartialEq, Eq, Clone)]
+pub enum ExternalSource {
+ Present(String),
+ AbsentOk,
+ AbsentErr,
+ Unneeded,
+}
+
/// A single source in the CodeMap.
#[derive(Clone)]
pub struct FileMap {
pub src: Option<Rc<String>>,
/// The source code's hash
pub src_hash: u128,
+ /// The external source code (used for external crates, which will have a `None`
+ /// value as `self.src`.
+ pub external_src: RefCell<ExternalSource>,
/// The start position of this source in the CodeMap
pub start_pos: BytePos,
/// The end position of this source in the CodeMap
end_pos: end_pos,
src: None,
src_hash: src_hash,
+ external_src: RefCell::new(ExternalSource::AbsentOk),
lines: RefCell::new(lines),
multibyte_chars: RefCell::new(multibyte_chars)
})
crate_of_origin: 0,
src: Some(Rc::new(src)),
src_hash: src_hash,
+ external_src: RefCell::new(ExternalSource::Unneeded),
start_pos: start_pos,
end_pos: Pos::from_usize(end_pos),
lines: RefCell::new(Vec::new()),