summaryrefslogtreecommitdiff
path: root/src/source.rs
diff options
context:
space:
mode:
authorMartin Haug <mhaug@live.de>2022-01-03 23:18:21 +0100
committerMartin Haug <mhaug@live.de>2022-01-04 00:21:33 +0100
commitc994cfa7d814e3909682b19322867ed5c676c453 (patch)
tree03349230f74786c7128876889c07a31a4932f108 /src/source.rs
parent98c96ba1cb8a46e327de313118e4ce1a84795ae9 (diff)
Code Review: Your parsers were so preoccupied with whether they could
Diffstat (limited to 'src/source.rs')
-rw-r--r--src/source.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/source.rs b/src/source.rs
index 6cca9f75..7afeaa8a 100644
--- a/src/source.rs
+++ b/src/source.rs
@@ -154,9 +154,14 @@ impl SourceFile {
&self.root
}
+ /// The root red node of the file's untyped red tree.
+ pub fn red(&self) -> RedNode {
+ RedNode::from_root(self.root.clone(), self.id)
+ }
+
/// The root node of the file's typed abstract syntax tree.
pub fn ast(&self) -> TypResult<Markup> {
- let red = RedNode::from_root(self.root.clone(), self.id);
+ let red = self.red();
let errors = red.errors();
if errors.is_empty() {
Ok(red.cast().unwrap())
@@ -284,14 +289,8 @@ impl SourceFile {
self.line_starts
.extend(newlines(&self.src[start ..]).map(|idx| start + idx));
- // Update the root node.
- let reparser = Reparser::new(&self.src, replace, with.len());
- if let Some(range) = reparser.reparse(Rc::make_mut(&mut self.root)) {
- range
- } else {
- self.root = parse(&self.src);
- 0 .. self.src.len()
- }
+ // Incrementally reparse the replaced range.
+ Reparser::new(&self.src, replace, with.len()).reparse(&mut self.root)
}
/// Provide highlighting categories for the given range of the source file.