mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 21:32:40 +00:00
Merge branch 'main' into adjust-font
This commit is contained in:
commit
09a3003224
2 changed files with 24 additions and 15 deletions
|
@ -455,18 +455,18 @@ impl Background {
|
||||||
T: 'static,
|
T: 'static,
|
||||||
F: 'static + Unpin + Future<Output = T>,
|
F: 'static + Unpin + Future<Output = T>,
|
||||||
{
|
{
|
||||||
let output = match self {
|
if !timeout.is_zero() {
|
||||||
Self::Production { .. } => {
|
let output = match self {
|
||||||
smol::block_on(util::timeout(timeout, Pin::new(&mut future))).ok()
|
Self::Production { .. } => {
|
||||||
|
smol::block_on(util::timeout(timeout, Pin::new(&mut future))).ok()
|
||||||
|
}
|
||||||
|
Self::Deterministic(executor) => executor.block_on(Pin::new(&mut future)),
|
||||||
|
};
|
||||||
|
if let Some(output) = output {
|
||||||
|
return Ok(output);
|
||||||
}
|
}
|
||||||
Self::Deterministic(executor) => executor.block_on(Pin::new(&mut future)),
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(output) = output {
|
|
||||||
Ok(output)
|
|
||||||
} else {
|
|
||||||
Err(future)
|
|
||||||
}
|
}
|
||||||
|
Err(future)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn scoped<'scope, F>(&self, scheduler: F)
|
pub async fn scoped<'scope, F>(&self, scheduler: F)
|
||||||
|
|
|
@ -119,6 +119,7 @@ pub struct Buffer {
|
||||||
history: History,
|
history: History,
|
||||||
file: Option<File>,
|
file: Option<File>,
|
||||||
language: Option<Arc<Language>>,
|
language: Option<Arc<Language>>,
|
||||||
|
sync_parse_timeout: Duration,
|
||||||
syntax_tree: Mutex<Option<SyntaxTree>>,
|
syntax_tree: Mutex<Option<SyntaxTree>>,
|
||||||
parsing_in_background: bool,
|
parsing_in_background: bool,
|
||||||
parse_count: usize,
|
parse_count: usize,
|
||||||
|
@ -583,6 +584,7 @@ impl Buffer {
|
||||||
syntax_tree: Mutex::new(None),
|
syntax_tree: Mutex::new(None),
|
||||||
parsing_in_background: false,
|
parsing_in_background: false,
|
||||||
parse_count: 0,
|
parse_count: 0,
|
||||||
|
sync_parse_timeout: Duration::from_millis(1),
|
||||||
language,
|
language,
|
||||||
saved_mtime,
|
saved_mtime,
|
||||||
selections: HashMap::default(),
|
selections: HashMap::default(),
|
||||||
|
@ -828,6 +830,11 @@ impl Buffer {
|
||||||
self.parsing_in_background
|
self.parsing_in_background
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn set_sync_parse_timeout(&mut self, timeout: Duration) {
|
||||||
|
self.sync_parse_timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
fn reparse(&mut self, cx: &mut ModelContext<Self>) -> bool {
|
fn reparse(&mut self, cx: &mut ModelContext<Self>) -> bool {
|
||||||
if self.parsing_in_background {
|
if self.parsing_in_background {
|
||||||
return false;
|
return false;
|
||||||
|
@ -846,7 +853,7 @@ impl Buffer {
|
||||||
|
|
||||||
match cx
|
match cx
|
||||||
.background()
|
.background()
|
||||||
.block_with_timeout(Duration::from_millis(1), parse_task)
|
.block_with_timeout(self.sync_parse_timeout, parse_task)
|
||||||
{
|
{
|
||||||
Ok(new_tree) => {
|
Ok(new_tree) => {
|
||||||
*self.syntax_tree.lock() = Some(SyntaxTree {
|
*self.syntax_tree.lock() = Some(SyntaxTree {
|
||||||
|
@ -1931,6 +1938,7 @@ impl Clone for Buffer {
|
||||||
language: self.language.clone(),
|
language: self.language.clone(),
|
||||||
syntax_tree: Mutex::new(self.syntax_tree.lock().clone()),
|
syntax_tree: Mutex::new(self.syntax_tree.lock().clone()),
|
||||||
parsing_in_background: false,
|
parsing_in_background: false,
|
||||||
|
sync_parse_timeout: self.sync_parse_timeout,
|
||||||
parse_count: self.parse_count,
|
parse_count: self.parse_count,
|
||||||
deferred_replicas: self.deferred_replicas.clone(),
|
deferred_replicas: self.deferred_replicas.clone(),
|
||||||
replica_id: self.replica_id,
|
replica_id: self.replica_id,
|
||||||
|
@ -3853,10 +3861,7 @@ mod tests {
|
||||||
|
|
||||||
let buffer = cx.add_model(|cx| {
|
let buffer = cx.add_model(|cx| {
|
||||||
let text = "fn a() {}".into();
|
let text = "fn a() {}".into();
|
||||||
let buffer = Buffer::from_history(0, History::new(text), None, rust_lang.cloned(), cx);
|
Buffer::from_history(0, History::new(text), None, rust_lang.cloned(), cx)
|
||||||
assert!(buffer.is_parsing());
|
|
||||||
assert!(buffer.syntax_tree().is_none());
|
|
||||||
buffer
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wait for the initial text to parse
|
// Wait for the initial text to parse
|
||||||
|
@ -3872,6 +3877,10 @@ mod tests {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
buffer.update(&mut cx, |buffer, _| {
|
||||||
|
buffer.set_sync_parse_timeout(Duration::ZERO)
|
||||||
|
});
|
||||||
|
|
||||||
// Perform some edits (add parameter and variable reference)
|
// Perform some edits (add parameter and variable reference)
|
||||||
// Parsing doesn't begin until the transaction is complete
|
// Parsing doesn't begin until the transaction is complete
|
||||||
buffer.update(&mut cx, |buf, cx| {
|
buffer.update(&mut cx, |buf, cx| {
|
||||||
|
|
Loading…
Reference in a new issue