summaryrefslogtreecommitdiff
path: root/src/source.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/source.rs')
-rw-r--r--src/source.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/source.rs b/src/source.rs
index cd5a453a..77a020cb 100644
--- a/src/source.rs
+++ b/src/source.rs
@@ -175,9 +175,12 @@ impl SourceFile {
Self::new(SourceId::detached(), Path::new(""), src.into())
}
- /// Set a synthetic span for all nodes in this file.
- pub fn synthesize(&mut self, span: Span) {
- Arc::make_mut(&mut self.root).synthesize(Arc::new(span));
+ /// Create a source file with the same synthetic span for all nodes.
+ pub fn synthesized(src: impl Into<String>, span: Span) -> Self {
+ let mut file = Self::detached(src);
+ Arc::make_mut(&mut file.root).synthesize(Arc::new(span));
+ file.id = span.source;
+ file
}
/// The root node of the file's untyped green tree.