feat: retain REPL and event results while incremental refresh is pending
This commit is contained in:
+77
-18
@@ -355,7 +355,26 @@ impl ReplSession {
|
||||
refresh: None,
|
||||
})
|
||||
}
|
||||
#[cfg(test)]
|
||||
pub fn execute(&mut self, source: &str, namespace: &str) -> Result<ReplResult> {
|
||||
self.execute_mode(source, namespace, None)
|
||||
}
|
||||
|
||||
pub fn execute_incremental(
|
||||
&mut self,
|
||||
source: &str,
|
||||
namespace: &str,
|
||||
viewports: &std::collections::BTreeMap<u64, crate::layout::Size>,
|
||||
) -> Result<ReplResult> {
|
||||
self.execute_mode(source, namespace, Some(viewports))
|
||||
}
|
||||
|
||||
fn execute_mode(
|
||||
&mut self,
|
||||
source: &str,
|
||||
namespace: &str,
|
||||
viewports: Option<&std::collections::BTreeMap<u64, crate::layout::Size>>,
|
||||
) -> Result<ReplResult> {
|
||||
self.require_idle_refresh()?;
|
||||
if self.faulted {
|
||||
bail!(
|
||||
@@ -466,7 +485,7 @@ impl ReplSession {
|
||||
retained?;
|
||||
rendered_value = repr?;
|
||||
}
|
||||
let document = self.refresh_document()?;
|
||||
let document = self.refresh_after_mutation(viewports)?;
|
||||
Ok(ReplResult {
|
||||
value: rendered_value,
|
||||
document,
|
||||
@@ -487,8 +506,10 @@ impl ReplSession {
|
||||
.push_str(" (error; earlier statements may remain live)");
|
||||
}
|
||||
}
|
||||
self.bridge
|
||||
.reclaim(&mut self.candidate.vm, &mut self.candidate.roots)?;
|
||||
if !self.has_pending_refresh() {
|
||||
self.bridge
|
||||
.reclaim(&mut self.candidate.vm, &mut self.candidate.roots)?;
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
@@ -504,6 +525,23 @@ impl ReplSession {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn refresh_after_mutation(
|
||||
&mut self,
|
||||
viewports: Option<&std::collections::BTreeMap<u64, crate::layout::Size>>,
|
||||
) -> Result<Option<RenderDocument>> {
|
||||
let Some(viewports) = viewports else {
|
||||
return self.refresh_document();
|
||||
};
|
||||
let progress = self.poll_refresh(true)?;
|
||||
if let Some(work) = &mut self.refresh {
|
||||
work.viewports = Some(viewports.clone());
|
||||
}
|
||||
Ok(match progress {
|
||||
RefreshProgress::Pending => None,
|
||||
RefreshProgress::Complete(document) => document.map(|document| *document),
|
||||
})
|
||||
}
|
||||
|
||||
fn refresh_document(&mut self) -> Result<Option<RenderDocument>> {
|
||||
loop {
|
||||
match self.poll_refresh(false)? {
|
||||
@@ -824,18 +862,7 @@ impl ReplSession {
|
||||
return Ok(None);
|
||||
}
|
||||
completed = true;
|
||||
if let Some(viewports) = viewports {
|
||||
let progress = self.poll_refresh(true)?;
|
||||
if let Some(work) = &mut self.refresh {
|
||||
work.viewports = Some(viewports.clone());
|
||||
}
|
||||
Ok(match progress {
|
||||
RefreshProgress::Pending => None,
|
||||
RefreshProgress::Complete(document) => document.map(|document| *document),
|
||||
})
|
||||
} else {
|
||||
self.refresh_document()
|
||||
}
|
||||
self.refresh_after_mutation(viewports)
|
||||
})();
|
||||
if result.is_err() {
|
||||
self.faulted = true;
|
||||
@@ -901,7 +928,24 @@ impl ReplSession {
|
||||
self.faulted
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn dispatch(&mut self, input: &crate::events::Input) -> Result<ReplResult> {
|
||||
self.dispatch_mode(input, None)
|
||||
}
|
||||
|
||||
pub fn dispatch_incremental(
|
||||
&mut self,
|
||||
input: &crate::events::Input,
|
||||
viewports: &std::collections::BTreeMap<u64, crate::layout::Size>,
|
||||
) -> Result<ReplResult> {
|
||||
self.dispatch_mode(input, Some(viewports))
|
||||
}
|
||||
|
||||
fn dispatch_mode(
|
||||
&mut self,
|
||||
input: &crate::events::Input,
|
||||
viewports: Option<&std::collections::BTreeMap<u64, crate::layout::Size>>,
|
||||
) -> Result<ReplResult> {
|
||||
self.require_idle_refresh()?;
|
||||
if self.faulted {
|
||||
bail!("runtime stopped after a callback or rendering failure");
|
||||
@@ -915,7 +959,7 @@ impl ReplSession {
|
||||
self.bridge.select_window(input.window)?;
|
||||
let result = (|| {
|
||||
self.bridge.dispatch(&mut self.candidate.vm, input)?;
|
||||
let document = self.refresh_document()?;
|
||||
let document = self.refresh_after_mutation(viewports)?;
|
||||
Ok(ReplResult {
|
||||
value: "nil".into(),
|
||||
document,
|
||||
@@ -934,11 +978,26 @@ impl ReplSession {
|
||||
self.faulted = true;
|
||||
self.bridge.discard_pending(&mut self.candidate.vm)?;
|
||||
}
|
||||
self.bridge
|
||||
.reclaim(&mut self.candidate.vm, &mut self.candidate.roots)?;
|
||||
if !self.has_pending_refresh() {
|
||||
self.bridge
|
||||
.reclaim(&mut self.candidate.vm, &mut self.candidate.roots)?;
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ReplSession {
|
||||
fn drop(&mut self) {
|
||||
if let Some(mut work) = self.refresh.take()
|
||||
&& let Some(pending) = work.pending.take()
|
||||
{
|
||||
// Close the read-only continuation and checkpoint roots before
|
||||
// Candidate releases the globals/services of a discarded domain.
|
||||
let _ = self.bridge.cancel_layout_frame(&mut self.candidate.vm, *pending);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn shift_node_lines(node: &mut CodeNode, offset: usize) {
|
||||
node.start_line += offset;
|
||||
node.end_line += offset;
|
||||
|
||||
Reference in New Issue
Block a user