}
}
- fn preprocess_annotations(&self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
+ fn preprocess_annotations(&mut self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
file: Rc<FileMap>,
line_index: usize,
if span_label.span == DUMMY_SP {
continue;
}
+
+ cm.load_source_for_filemap(cm.span_to_filename(span_label.span));
+
let lo = cm.lookup_char_pos(span_label.span.lo);
let mut hi = cm.lookup_char_pos(span_label.span.hi);
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;
+ fn load_source_for_filemap(&self, file: FileName) -> bool;
}
impl CodeSuggestion {
}
sp
}
- fn load_source_for_filemap(&mut self, filename: FileName) -> bool {
+ fn load_source_for_filemap(&self, filename: FileName) -> bool {
let file_map = if let Some(fm) = self.get_filemap(&filename) {
fm
} else {
pub bytes: usize,
}
+/// The state of the lazy external source loading mechanism of a FileMap.
#[derive(PartialEq, Eq, Clone)]
pub enum ExternalSource {
+ /// The external source has been loaded already.
Present(String),
+ /// No attempt has been made to load the external source.
AbsentOk,
+ /// A failed attempt has been made to load the external source.
AbsentErr,
+ /// No external source has to be loaded, since the FileMap represents a local crate.
Unneeded,
}
+impl ExternalSource {
+ pub fn is_absent(&self) -> bool {
+ match *self {
+ ExternalSource::Present(_) => false,
+ _ => true,
+ }
+ }
+
+ pub fn get_source(&self) -> Option<&str> {
+ match *self {
+ ExternalSource::Present(ref src) => Some(src),
+ _ => None,
+ }
+ }
+}
+
/// A single source in the CodeMap.
#[derive(Clone)]
pub struct FileMap {
}
pub fn is_imported(&self) -> bool {
- self.src.is_none()
+ self.src.is_none() // TODO: change to something more sensible
}
pub fn byte_length(&self) -> u32 {