File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -64,13 +64,26 @@ impl SourceEngine {
64
64
. contains ( "<autogenerated>" )
65
65
}
66
66
67
+ /// Fetch the cached source buffer for `source_id`, replacing it if the caller
68
+ /// provides newer text so future span lookups observe the latest file contents.
67
69
pub fn get_or_create_source_buffer (
68
70
& self ,
69
71
source_id : & SourceId ,
70
72
source : span:: Source ,
71
73
) -> span:: Source {
72
74
let mut map = self . source_to_buffer_map . write ( ) ;
73
- map. entry ( * source_id) . or_insert ( source) . clone ( )
75
+
76
+ if let Some ( existing) = map. get_mut ( source_id) {
77
+ // Replace the cached source if the contents have changed so that
78
+ // subsequent spans reflect the latest file text.
79
+ if existing. text != source. text {
80
+ * existing = source;
81
+ }
82
+ existing. clone ( )
83
+ } else {
84
+ map. insert ( * source_id, source. clone ( ) ) ;
85
+ source
86
+ }
74
87
}
75
88
76
89
/// This function retrieves an integer-based source ID for a provided path buffer.
You can’t perform that action at this time.
0 commit comments