Fetch code actions on cursor movement instead of on-demand
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
763d57c94a
commit
2fcdcac080
9 changed files with 134 additions and 70 deletions
|
@ -80,8 +80,14 @@ pub trait UpdateModel {
|
|||
}
|
||||
|
||||
pub trait UpgradeModelHandle {
|
||||
fn upgrade_model_handle<T: Entity>(&self, handle: WeakModelHandle<T>)
|
||||
-> Option<ModelHandle<T>>;
|
||||
fn upgrade_model_handle<T: Entity>(
|
||||
&self,
|
||||
handle: &WeakModelHandle<T>,
|
||||
) -> Option<ModelHandle<T>>;
|
||||
}
|
||||
|
||||
pub trait UpgradeViewHandle {
|
||||
fn upgrade_view_handle<T: View>(&self, handle: &WeakViewHandle<T>) -> Option<ViewHandle<T>>;
|
||||
}
|
||||
|
||||
pub trait ReadView {
|
||||
|
@ -558,12 +564,18 @@ impl UpdateModel for AsyncAppContext {
|
|||
impl UpgradeModelHandle for AsyncAppContext {
|
||||
fn upgrade_model_handle<T: Entity>(
|
||||
&self,
|
||||
handle: WeakModelHandle<T>,
|
||||
handle: &WeakModelHandle<T>,
|
||||
) -> Option<ModelHandle<T>> {
|
||||
self.0.borrow_mut().upgrade_model_handle(handle)
|
||||
}
|
||||
}
|
||||
|
||||
impl UpgradeViewHandle for AsyncAppContext {
|
||||
fn upgrade_view_handle<T: View>(&self, handle: &WeakViewHandle<T>) -> Option<ViewHandle<T>> {
|
||||
self.0.borrow_mut().upgrade_view_handle(handle)
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadModelWith for AsyncAppContext {
|
||||
fn read_model_with<E: Entity, T>(
|
||||
&self,
|
||||
|
@ -1732,12 +1744,18 @@ impl UpdateModel for MutableAppContext {
|
|||
impl UpgradeModelHandle for MutableAppContext {
|
||||
fn upgrade_model_handle<T: Entity>(
|
||||
&self,
|
||||
handle: WeakModelHandle<T>,
|
||||
handle: &WeakModelHandle<T>,
|
||||
) -> Option<ModelHandle<T>> {
|
||||
self.cx.upgrade_model_handle(handle)
|
||||
}
|
||||
}
|
||||
|
||||
impl UpgradeViewHandle for MutableAppContext {
|
||||
fn upgrade_view_handle<T: View>(&self, handle: &WeakViewHandle<T>) -> Option<ViewHandle<T>> {
|
||||
self.cx.upgrade_view_handle(handle)
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadView for MutableAppContext {
|
||||
fn read_view<T: View>(&self, handle: &ViewHandle<T>) -> &T {
|
||||
if let Some(view) = self.cx.views.get(&(handle.window_id, handle.view_id)) {
|
||||
|
@ -1846,7 +1864,7 @@ impl ReadModel for AppContext {
|
|||
impl UpgradeModelHandle for AppContext {
|
||||
fn upgrade_model_handle<T: Entity>(
|
||||
&self,
|
||||
handle: WeakModelHandle<T>,
|
||||
handle: &WeakModelHandle<T>,
|
||||
) -> Option<ModelHandle<T>> {
|
||||
if self.models.contains_key(&handle.model_id) {
|
||||
Some(ModelHandle::new(handle.model_id, &self.ref_counts))
|
||||
|
@ -1856,6 +1874,20 @@ impl UpgradeModelHandle for AppContext {
|
|||
}
|
||||
}
|
||||
|
||||
impl UpgradeViewHandle for AppContext {
|
||||
fn upgrade_view_handle<T: View>(&self, handle: &WeakViewHandle<T>) -> Option<ViewHandle<T>> {
|
||||
if self.ref_counts.lock().is_entity_alive(handle.view_id) {
|
||||
Some(ViewHandle::new(
|
||||
handle.window_id,
|
||||
handle.view_id,
|
||||
&self.ref_counts,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadView for AppContext {
|
||||
fn read_view<T: View>(&self, handle: &ViewHandle<T>) -> &T {
|
||||
if let Some(view) = self.views.get(&(handle.window_id, handle.view_id)) {
|
||||
|
@ -2228,7 +2260,7 @@ impl<M> UpdateModel for ModelContext<'_, M> {
|
|||
impl<M> UpgradeModelHandle for ModelContext<'_, M> {
|
||||
fn upgrade_model_handle<T: Entity>(
|
||||
&self,
|
||||
handle: WeakModelHandle<T>,
|
||||
handle: &WeakModelHandle<T>,
|
||||
) -> Option<ModelHandle<T>> {
|
||||
self.cx.upgrade_model_handle(handle)
|
||||
}
|
||||
|
@ -2558,12 +2590,18 @@ impl<V> ReadModel for ViewContext<'_, V> {
|
|||
impl<V> UpgradeModelHandle for ViewContext<'_, V> {
|
||||
fn upgrade_model_handle<T: Entity>(
|
||||
&self,
|
||||
handle: WeakModelHandle<T>,
|
||||
handle: &WeakModelHandle<T>,
|
||||
) -> Option<ModelHandle<T>> {
|
||||
self.cx.upgrade_model_handle(handle)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> UpgradeViewHandle for ViewContext<'_, V> {
|
||||
fn upgrade_view_handle<T: View>(&self, handle: &WeakViewHandle<T>) -> Option<ViewHandle<T>> {
|
||||
self.cx.upgrade_view_handle(handle)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> UpdateModel for ViewContext<'_, V> {
|
||||
fn update_model<T: Entity, O>(
|
||||
&mut self,
|
||||
|
@ -2861,7 +2899,7 @@ impl<T: Entity> WeakModelHandle<T> {
|
|||
self.model_id
|
||||
}
|
||||
|
||||
pub fn upgrade(self, cx: &impl UpgradeModelHandle) -> Option<ModelHandle<T>> {
|
||||
pub fn upgrade(&self, cx: &impl UpgradeModelHandle) -> Option<ModelHandle<T>> {
|
||||
cx.upgrade_model_handle(self)
|
||||
}
|
||||
}
|
||||
|
@ -3277,16 +3315,8 @@ impl<T: View> WeakViewHandle<T> {
|
|||
self.view_id
|
||||
}
|
||||
|
||||
pub fn upgrade(&self, cx: &AppContext) -> Option<ViewHandle<T>> {
|
||||
if cx.ref_counts.lock().is_entity_alive(self.view_id) {
|
||||
Some(ViewHandle::new(
|
||||
self.window_id,
|
||||
self.view_id,
|
||||
&cx.ref_counts,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
pub fn upgrade(&self, cx: &impl UpgradeViewHandle) -> Option<ViewHandle<T>> {
|
||||
cx.upgrade_view_handle(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue