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:
parent
271133b03e
commit
d11973ae2a
1 changed files with 23 additions and 22 deletions
|
@ -415,8 +415,8 @@ impl CodeMap {
|
|||
local_end.fm.start_pos)
|
||||
}));
|
||||
} else {
|
||||
match local_begin.fm.src {
|
||||
Some(ref src) => {
|
||||
self.ensure_filemap_source_present(local_begin.fm.clone());
|
||||
|
||||
let start_index = local_begin.pos.to_usize();
|
||||
let end_index = local_end.pos.to_usize();
|
||||
let source_len = (local_begin.fm.end_pos -
|
||||
|
@ -432,16 +432,17 @@ impl CodeMap {
|
|||
}));
|
||||
}
|
||||
|
||||
return Ok((&src[start_index..end_index]).to_string())
|
||||
}
|
||||
None => {
|
||||
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()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Given a `Span`, try to get a shorter span ending before the first occurrence of `c` `char`
|
||||
pub fn span_until_char(&self, sp: Span, c: char) -> Span {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue