External spans: added lazy source loading elsewhere

* In other places where the `src` member of a file map is accessed, we
  now load and possibly work with external source as well.
This commit is contained in:
Inokentiy Babushkin 2017-06-12 21:47:39 +02:00
parent 271133b03e
commit d11973ae2a
No known key found for this signature in database
GPG Key ID: 7EFC8EC5224DE8EC

View File

@ -415,30 +415,31 @@ pub fn span_to_snippet(&self, sp: Span) -> Result<String, SpanSnippetError> {
local_end.fm.start_pos) local_end.fm.start_pos)
})); }));
} else { } else {
match local_begin.fm.src { self.ensure_filemap_source_present(local_begin.fm.clone());
Some(ref src) => {
let start_index = local_begin.pos.to_usize();
let end_index = local_end.pos.to_usize();
let source_len = (local_begin.fm.end_pos -
local_begin.fm.start_pos).to_usize();
if start_index > end_index || end_index > source_len { let start_index = local_begin.pos.to_usize();
return Err(SpanSnippetError::MalformedForCodemap( let end_index = local_end.pos.to_usize();
MalformedCodemapPositions { let source_len = (local_begin.fm.end_pos -
name: local_begin.fm.name.clone(), local_begin.fm.start_pos).to_usize();
source_len: source_len,
begin_pos: local_begin.pos,
end_pos: local_end.pos,
}));
}
return Ok((&src[start_index..end_index]).to_string()) if start_index > end_index || end_index > source_len {
} return Err(SpanSnippetError::MalformedForCodemap(
None => { MalformedCodemapPositions {
return Err(SpanSnippetError::SourceNotAvailable { name: local_begin.fm.name.clone(),
filename: local_begin.fm.name.clone() source_len: source_len,
}); begin_pos: local_begin.pos,
} end_pos: local_end.pos,
}));
}
if let Some(ref src) = local_begin.fm.src {
return Ok((&src[start_index..end_index]).to_string());
} else if let Some(src) = local_begin.fm.external_src.borrow().get_source() {
return Ok((&src[start_index..end_index]).to_string());
} else {
return Err(SpanSnippetError::SourceNotAvailable {
filename: local_begin.fm.name.clone()
});
} }
} }
} }