Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion sway-types/src/source_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,26 @@ impl SourceEngine {
.contains("<autogenerated>")
}

/// Fetch the cached source buffer for `source_id`, replacing it if the caller
/// provides newer text so future span lookups observe the latest file contents.
pub fn get_or_create_source_buffer(
&self,
source_id: &SourceId,
source: span::Source,
) -> span::Source {
let mut map = self.source_to_buffer_map.write();
map.entry(*source_id).or_insert(source).clone()

if let Some(existing) = map.get_mut(source_id) {
// Replace the cached source if the contents have changed so that
// subsequent spans reflect the latest file text.
if existing.text != source.text {
*existing = source;
}
existing.clone()
} else {
map.insert(*source_id, source.clone());
source
}
}

/// This function retrieves an integer-based source ID for a provided path buffer.
Expand Down
Loading