Eliminate GPUI View, ViewContext, and WindowContext types (#22632)

There's still a bit more work to do on this, but this PR is compiling
(with warnings) after eliminating the key types. When the tasks below
are complete, this will be the new narrative for GPUI:

- `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit
of state, and if `T` implements `Render`, then `Entity<T>` implements
`Element`.
- `&mut App` This replaces `AppContext` and represents the app.
- `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It
is provided by the framework when updating an entity.
- `&mut Window` Broken out of `&mut WindowContext` which no longer
exists. Every method that once took `&mut WindowContext` now takes `&mut
Window, &mut App` and every method that took `&mut ViewContext<T>` now
takes `&mut Window, &mut Context<T>`

Not pictured here are the two other failed attempts. It's been quite a
month!

Tasks:

- [x] Remove `View`, `ViewContext`, `WindowContext` and thread through
`Window`
- [x] [@cole-miller @mikayla-maki] Redraw window when entities change
- [x] [@cole-miller @mikayla-maki] Get examples and Zed running
- [x] [@cole-miller @mikayla-maki] Fix Zed rendering
- [x] [@mikayla-maki] Fix todo! macros and comments
- [x] Fix a bug where the editor would not be redrawn because of view
caching
- [x] remove publicness window.notify() and replace with
`AppContext::notify`
- [x] remove `observe_new_window_models`, replace with
`observe_new_models` with an optional window
- [x] Fix a bug where the project panel would not be redrawn because of
the wrong refresh() call being used
- [x] Fix the tests
- [x] Fix warnings by eliminating `Window` params or using `_`
- [x] Fix conflicts
- [x] Simplify generic code where possible
- [x] Rename types
- [ ] Update docs

### issues post merge

- [x] Issues switching between normal and insert mode
- [x] Assistant re-rendering failure
- [x] Vim test failures
- [x] Mac build issue



Release Notes:

- N/A

---------

Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Cole Miller <cole@zed.dev>
Co-authored-by: Mikayla <mikayla@zed.dev>
Co-authored-by: Joseph <joseph@zed.dev>
Co-authored-by: max <max@zed.dev>
Co-authored-by: Michael Sloan <michael@zed.dev>
Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local>
Co-authored-by: Mikayla <mikayla.c.maki@gmail.com>
Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
Nathan Sobo 2025-01-25 20:02:45 -07:00 committed by GitHub
parent 21b4a0d50e
commit 6fca1d2b0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
648 changed files with 36248 additions and 28208 deletions

View file

@ -12,8 +12,8 @@ use fs::Fs;
use futures::{channel::oneshot, future::Shared, Future, FutureExt as _, StreamExt};
use git::{blame::Blame, diff::BufferDiff, repository::RepoPath};
use gpui::{
AppContext, AsyncAppContext, Context as _, EventEmitter, Model, ModelContext, Subscription,
Task, WeakModel,
App, AppContext as _, AsyncAppContext, Context, Entity, EventEmitter, Subscription, Task,
WeakEntity,
};
use http_client::Url;
use language::{
@ -43,11 +43,11 @@ use worktree::{File, PathChange, ProjectEntryId, UpdatedGitRepositoriesSet, Work
pub struct BufferStore {
state: BufferStoreState,
#[allow(clippy::type_complexity)]
loading_buffers: HashMap<ProjectPath, Shared<Task<Result<Model<Buffer>, Arc<anyhow::Error>>>>>,
loading_buffers: HashMap<ProjectPath, Shared<Task<Result<Entity<Buffer>, Arc<anyhow::Error>>>>>,
#[allow(clippy::type_complexity)]
loading_change_sets:
HashMap<BufferId, Shared<Task<Result<Model<BufferChangeSet>, Arc<anyhow::Error>>>>>,
worktree_store: Model<WorktreeStore>,
HashMap<BufferId, Shared<Task<Result<Entity<BufferChangeSet>, Arc<anyhow::Error>>>>>,
worktree_store: Entity<WorktreeStore>,
opened_buffers: HashMap<BufferId, OpenBuffer>,
downstream_client: Option<(AnyProtoClient, u64)>,
shared_buffers: HashMap<proto::PeerId, HashMap<BufferId, SharedBuffer>>,
@ -55,8 +55,8 @@ pub struct BufferStore {
#[derive(Hash, Eq, PartialEq, Clone)]
struct SharedBuffer {
buffer: Model<Buffer>,
unstaged_changes: Option<Model<BufferChangeSet>>,
buffer: Entity<Buffer>,
unstaged_changes: Option<Entity<BufferChangeSet>>,
lsp_handle: Option<OpenLspBufferHandle>,
}
@ -76,50 +76,46 @@ enum BufferStoreState {
}
struct RemoteBufferStore {
shared_with_me: HashSet<Model<Buffer>>,
shared_with_me: HashSet<Entity<Buffer>>,
upstream_client: AnyProtoClient,
project_id: u64,
loading_remote_buffers_by_id: HashMap<BufferId, Model<Buffer>>,
loading_remote_buffers_by_id: HashMap<BufferId, Entity<Buffer>>,
remote_buffer_listeners:
HashMap<BufferId, Vec<oneshot::Sender<Result<Model<Buffer>, anyhow::Error>>>>,
worktree_store: Model<WorktreeStore>,
HashMap<BufferId, Vec<oneshot::Sender<Result<Entity<Buffer>, anyhow::Error>>>>,
worktree_store: Entity<WorktreeStore>,
}
struct LocalBufferStore {
local_buffer_ids_by_path: HashMap<ProjectPath, BufferId>,
local_buffer_ids_by_entry_id: HashMap<ProjectEntryId, BufferId>,
worktree_store: Model<WorktreeStore>,
worktree_store: Entity<WorktreeStore>,
_subscription: Subscription,
}
enum OpenBuffer {
Complete {
buffer: WeakModel<Buffer>,
unstaged_changes: Option<WeakModel<BufferChangeSet>>,
buffer: WeakEntity<Buffer>,
unstaged_changes: Option<WeakEntity<BufferChangeSet>>,
},
Operations(Vec<Operation>),
}
pub enum BufferStoreEvent {
BufferAdded(Model<Buffer>),
BufferAdded(Entity<Buffer>),
BufferDropped(BufferId),
BufferChangedFilePath {
buffer: Model<Buffer>,
buffer: Entity<Buffer>,
old_file: Option<Arc<dyn language::File>>,
},
}
#[derive(Default, Debug)]
pub struct ProjectTransaction(pub HashMap<Model<Buffer>, language::Transaction>);
pub struct ProjectTransaction(pub HashMap<Entity<Buffer>, language::Transaction>);
impl EventEmitter<BufferStoreEvent> for BufferStore {}
impl RemoteBufferStore {
fn load_staged_text(
&self,
buffer_id: BufferId,
cx: &AppContext,
) -> Task<Result<Option<String>>> {
fn load_staged_text(&self, buffer_id: BufferId, cx: &App) -> Task<Result<Option<String>>> {
let project_id = self.project_id;
let client = self.upstream_client.clone();
cx.background_executor().spawn(async move {
@ -135,8 +131,8 @@ impl RemoteBufferStore {
pub fn wait_for_remote_buffer(
&mut self,
id: BufferId,
cx: &mut ModelContext<BufferStore>,
) -> Task<Result<Model<Buffer>>> {
cx: &mut Context<BufferStore>,
) -> Task<Result<Entity<Buffer>>> {
let (tx, rx) = oneshot::channel();
self.remote_buffer_listeners.entry(id).or_default().push(tx);
@ -157,9 +153,9 @@ impl RemoteBufferStore {
fn save_remote_buffer(
&self,
buffer_handle: Model<Buffer>,
buffer_handle: Entity<Buffer>,
new_path: Option<proto::ProjectPath>,
cx: &ModelContext<BufferStore>,
cx: &Context<BufferStore>,
) -> Task<Result<()>> {
let buffer = buffer_handle.read(cx);
let buffer_id = buffer.remote_id().into();
@ -191,8 +187,8 @@ impl RemoteBufferStore {
envelope: TypedEnvelope<proto::CreateBufferForPeer>,
replica_id: u16,
capability: Capability,
cx: &mut ModelContext<BufferStore>,
) -> Result<Option<Model<Buffer>>> {
cx: &mut Context<BufferStore>,
) -> Result<Option<Entity<Buffer>>> {
match envelope
.payload
.variant
@ -220,7 +216,7 @@ impl RemoteBufferStore {
match buffer_result {
Ok(buffer) => {
let buffer = cx.new_model(|_| buffer);
let buffer = cx.new(|_| buffer);
self.loading_remote_buffers_by_id.insert(buffer_id, buffer);
}
Err(error) => {
@ -292,7 +288,7 @@ impl RemoteBufferStore {
&self,
message: proto::ProjectTransaction,
push_to_history: bool,
cx: &mut ModelContext<BufferStore>,
cx: &mut Context<BufferStore>,
) -> Task<Result<ProjectTransaction>> {
cx.spawn(|this, mut cx| async move {
let mut project_transaction = ProjectTransaction::default();
@ -329,9 +325,9 @@ impl RemoteBufferStore {
fn open_buffer(
&self,
path: Arc<Path>,
worktree: Model<Worktree>,
cx: &mut ModelContext<BufferStore>,
) -> Task<Result<Model<Buffer>>> {
worktree: Entity<Worktree>,
cx: &mut Context<BufferStore>,
) -> Task<Result<Entity<Buffer>>> {
let worktree_id = worktree.read(cx).id().to_proto();
let project_id = self.project_id;
let client = self.upstream_client.clone();
@ -356,7 +352,7 @@ impl RemoteBufferStore {
})
}
fn create_buffer(&self, cx: &mut ModelContext<BufferStore>) -> Task<Result<Model<Buffer>>> {
fn create_buffer(&self, cx: &mut Context<BufferStore>) -> Task<Result<Entity<Buffer>>> {
let create = self.upstream_client.request(proto::OpenNewBuffer {
project_id: self.project_id,
});
@ -373,9 +369,9 @@ impl RemoteBufferStore {
fn reload_buffers(
&self,
buffers: HashSet<Model<Buffer>>,
buffers: HashSet<Entity<Buffer>>,
push_to_history: bool,
cx: &mut ModelContext<BufferStore>,
cx: &mut Context<BufferStore>,
) -> Task<Result<ProjectTransaction>> {
let request = self.upstream_client.request(proto::ReloadBuffers {
project_id: self.project_id,
@ -399,11 +395,7 @@ impl RemoteBufferStore {
}
impl LocalBufferStore {
fn load_staged_text(
&self,
buffer: &Model<Buffer>,
cx: &AppContext,
) -> Task<Result<Option<String>>> {
fn load_staged_text(&self, buffer: &Entity<Buffer>, cx: &App) -> Task<Result<Option<String>>> {
let Some(file) = buffer.read(cx).file() else {
return Task::ready(Ok(None));
};
@ -422,11 +414,11 @@ impl LocalBufferStore {
fn save_local_buffer(
&self,
buffer_handle: Model<Buffer>,
worktree: Model<Worktree>,
buffer_handle: Entity<Buffer>,
worktree: Entity<Worktree>,
path: Arc<Path>,
mut has_changed_file: bool,
cx: &mut ModelContext<BufferStore>,
cx: &mut Context<BufferStore>,
) -> Task<Result<()>> {
let buffer = buffer_handle.read(cx);
@ -480,8 +472,8 @@ impl LocalBufferStore {
fn subscribe_to_worktree(
&mut self,
worktree: &Model<Worktree>,
cx: &mut ModelContext<BufferStore>,
worktree: &Entity<Worktree>,
cx: &mut Context<BufferStore>,
) {
cx.subscribe(worktree, |this, worktree, event, cx| {
if worktree.read(cx).is_local() {
@ -506,9 +498,9 @@ impl LocalBufferStore {
fn local_worktree_entries_changed(
this: &mut BufferStore,
worktree_handle: &Model<Worktree>,
worktree_handle: &Entity<Worktree>,
changes: &[(Arc<Path>, ProjectEntryId, PathChange)],
cx: &mut ModelContext<BufferStore>,
cx: &mut Context<BufferStore>,
) {
let snapshot = worktree_handle.read(cx).snapshot();
for (path, entry_id, _) in changes {
@ -525,9 +517,9 @@ impl LocalBufferStore {
fn local_worktree_git_repos_changed(
this: &mut BufferStore,
worktree_handle: Model<Worktree>,
worktree_handle: Entity<Worktree>,
changed_repos: &UpdatedGitRepositoriesSet,
cx: &mut ModelContext<BufferStore>,
cx: &mut Context<BufferStore>,
) {
debug_assert!(worktree_handle.read(cx).is_local());
@ -609,9 +601,9 @@ impl LocalBufferStore {
this: &mut BufferStore,
entry_id: ProjectEntryId,
path: &Arc<Path>,
worktree: &Model<worktree::Worktree>,
worktree: &Entity<worktree::Worktree>,
snapshot: &worktree::Snapshot,
cx: &mut ModelContext<BufferStore>,
cx: &mut Context<BufferStore>,
) -> Option<()> {
let project_path = ProjectPath {
worktree_id: snapshot.id(),
@ -696,7 +688,7 @@ impl LocalBufferStore {
buffer_id,
);
events.push(BufferStoreEvent::BufferChangedFilePath {
buffer: cx.handle(),
buffer: cx.model(),
old_file: buffer.file().cloned(),
});
}
@ -733,7 +725,7 @@ impl LocalBufferStore {
None
}
fn buffer_changed_file(&mut self, buffer: Model<Buffer>, cx: &mut AppContext) -> Option<()> {
fn buffer_changed_file(&mut self, buffer: Entity<Buffer>, cx: &mut App) -> Option<()> {
let file = File::from_dyn(buffer.read(cx).file())?;
let remote_id = buffer.read(cx).remote_id();
@ -761,8 +753,8 @@ impl LocalBufferStore {
fn save_buffer(
&self,
buffer: Model<Buffer>,
cx: &mut ModelContext<BufferStore>,
buffer: Entity<Buffer>,
cx: &mut Context<BufferStore>,
) -> Task<Result<()>> {
let Some(file) = File::from_dyn(buffer.read(cx).file()) else {
return Task::ready(Err(anyhow!("buffer doesn't have a file")));
@ -773,9 +765,9 @@ impl LocalBufferStore {
fn save_buffer_as(
&self,
buffer: Model<Buffer>,
buffer: Entity<Buffer>,
path: ProjectPath,
cx: &mut ModelContext<BufferStore>,
cx: &mut Context<BufferStore>,
) -> Task<Result<()>> {
let Some(worktree) = self
.worktree_store
@ -790,9 +782,9 @@ impl LocalBufferStore {
fn open_buffer(
&self,
path: Arc<Path>,
worktree: Model<Worktree>,
cx: &mut ModelContext<BufferStore>,
) -> Task<Result<Model<Buffer>>> {
worktree: Entity<Worktree>,
cx: &mut Context<BufferStore>,
) -> Task<Result<Entity<Buffer>>> {
let load_buffer = worktree.update(cx, |worktree, cx| {
let load_file = worktree.load_file(path.as_ref(), cx);
let reservation = cx.reserve_model();
@ -812,7 +804,7 @@ impl LocalBufferStore {
cx.spawn(move |this, mut cx| async move {
let buffer = match load_buffer.await {
Ok(buffer) => Ok(buffer),
Err(error) if is_not_found_error(&error) => cx.new_model(|cx| {
Err(error) if is_not_found_error(&error) => cx.new(|cx| {
let buffer_id = BufferId::from(cx.entity_id().as_non_zero_u64());
let text_buffer = text::Buffer::new(0, buffer_id, "".into());
Buffer::build(
@ -856,11 +848,10 @@ impl LocalBufferStore {
})
}
fn create_buffer(&self, cx: &mut ModelContext<BufferStore>) -> Task<Result<Model<Buffer>>> {
fn create_buffer(&self, cx: &mut Context<BufferStore>) -> Task<Result<Entity<Buffer>>> {
cx.spawn(|buffer_store, mut cx| async move {
let buffer = cx.new_model(|cx| {
Buffer::local("", cx).with_language(language::PLAIN_TEXT.clone(), cx)
})?;
let buffer =
cx.new(|cx| Buffer::local("", cx).with_language(language::PLAIN_TEXT.clone(), cx))?;
buffer_store.update(&mut cx, |buffer_store, cx| {
buffer_store.add_buffer(buffer.clone(), cx).log_err();
})?;
@ -870,9 +861,9 @@ impl LocalBufferStore {
fn reload_buffers(
&self,
buffers: HashSet<Model<Buffer>>,
buffers: HashSet<Entity<Buffer>>,
push_to_history: bool,
cx: &mut ModelContext<BufferStore>,
cx: &mut Context<BufferStore>,
) -> Task<Result<ProjectTransaction>> {
cx.spawn(move |_, mut cx| async move {
let mut project_transaction = ProjectTransaction::default();
@ -885,7 +876,7 @@ impl LocalBufferStore {
if !push_to_history {
buffer.forget_transaction(transaction.id);
}
project_transaction.0.insert(cx.handle(), transaction);
project_transaction.0.insert(cx.model(), transaction);
}
})?;
}
@ -909,7 +900,7 @@ impl BufferStore {
}
/// Creates a buffer store, optionally retaining its buffers.
pub fn local(worktree_store: Model<WorktreeStore>, cx: &mut ModelContext<Self>) -> Self {
pub fn local(worktree_store: Entity<WorktreeStore>, cx: &mut Context<Self>) -> Self {
Self {
state: BufferStoreState::Local(LocalBufferStore {
local_buffer_ids_by_path: Default::default(),
@ -932,10 +923,10 @@ impl BufferStore {
}
pub fn remote(
worktree_store: Model<WorktreeStore>,
worktree_store: Entity<WorktreeStore>,
upstream_client: AnyProtoClient,
remote_id: u64,
_cx: &mut ModelContext<Self>,
_cx: &mut Context<Self>,
) -> Self {
Self {
state: BufferStoreState::Remote(RemoteBufferStore {
@ -979,8 +970,8 @@ impl BufferStore {
pub fn open_buffer(
&mut self,
project_path: ProjectPath,
cx: &mut ModelContext<Self>,
) -> Task<Result<Model<Buffer>>> {
cx: &mut Context<Self>,
) -> Task<Result<Entity<Buffer>>> {
if let Some(buffer) = self.get_by_path(&project_path, cx) {
return Task::ready(Ok(buffer));
}
@ -1024,9 +1015,9 @@ impl BufferStore {
pub fn open_unstaged_changes(
&mut self,
buffer: Model<Buffer>,
cx: &mut ModelContext<Self>,
) -> Task<Result<Model<BufferChangeSet>>> {
buffer: Entity<Buffer>,
cx: &mut Context<Self>,
) -> Task<Result<Entity<BufferChangeSet>>> {
let buffer_id = buffer.read(cx).remote_id();
if let Some(change_set) = self.get_unstaged_changes(buffer_id) {
return Task::ready(Ok(change_set));
@ -1058,17 +1049,17 @@ impl BufferStore {
}
#[cfg(any(test, feature = "test-support"))]
pub fn set_change_set(&mut self, buffer_id: BufferId, change_set: Model<BufferChangeSet>) {
pub fn set_change_set(&mut self, buffer_id: BufferId, change_set: Entity<BufferChangeSet>) {
self.loading_change_sets
.insert(buffer_id, Task::ready(Ok(change_set)).shared());
}
pub async fn open_unstaged_changes_internal(
this: WeakModel<Self>,
this: WeakEntity<Self>,
text: Result<Option<String>>,
buffer: Model<Buffer>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Model<BufferChangeSet>> {
) -> Result<Entity<BufferChangeSet>> {
let text = match text {
Err(e) => {
this.update(&mut cx, |this, cx| {
@ -1080,9 +1071,7 @@ impl BufferStore {
Ok(text) => text,
};
let change_set = cx
.new_model(|cx| BufferChangeSet::new(&buffer, cx))
.unwrap();
let change_set = cx.new(|cx| BufferChangeSet::new(&buffer, cx)).unwrap();
if let Some(text) = text {
change_set
@ -1108,7 +1097,7 @@ impl BufferStore {
Ok(change_set)
}
pub fn create_buffer(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<Model<Buffer>>> {
pub fn create_buffer(&mut self, cx: &mut Context<Self>) -> Task<Result<Entity<Buffer>>> {
match &self.state {
BufferStoreState::Local(this) => this.create_buffer(cx),
BufferStoreState::Remote(this) => this.create_buffer(cx),
@ -1117,8 +1106,8 @@ impl BufferStore {
pub fn save_buffer(
&mut self,
buffer: Model<Buffer>,
cx: &mut ModelContext<Self>,
buffer: Entity<Buffer>,
cx: &mut Context<Self>,
) -> Task<Result<()>> {
match &mut self.state {
BufferStoreState::Local(this) => this.save_buffer(buffer, cx),
@ -1128,9 +1117,9 @@ impl BufferStore {
pub fn save_buffer_as(
&mut self,
buffer: Model<Buffer>,
buffer: Entity<Buffer>,
path: ProjectPath,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> Task<Result<()>> {
let old_file = buffer.read(cx).file().cloned();
let task = match &self.state {
@ -1149,9 +1138,9 @@ impl BufferStore {
pub fn blame_buffer(
&self,
buffer: &Model<Buffer>,
buffer: &Entity<Buffer>,
version: Option<clock::Global>,
cx: &AppContext,
cx: &App,
) -> Task<Result<Option<Blame>>> {
let buffer = buffer.read(cx);
let Some(file) = File::from_dyn(buffer.file()) else {
@ -1211,9 +1200,9 @@ impl BufferStore {
pub fn get_permalink_to_line(
&self,
buffer: &Model<Buffer>,
buffer: &Entity<Buffer>,
selection: Range<u32>,
cx: &AppContext,
cx: &App,
) -> Task<Result<url::Url>> {
let buffer = buffer.read(cx);
let Some(file) = File::from_dyn(buffer.file()) else {
@ -1306,7 +1295,7 @@ impl BufferStore {
}
}
fn add_buffer(&mut self, buffer: Model<Buffer>, cx: &mut ModelContext<Self>) -> Result<()> {
fn add_buffer(&mut self, buffer: Entity<Buffer>, cx: &mut Context<Self>) -> Result<()> {
let remote_id = buffer.read(cx).remote_id();
let is_remote = buffer.read(cx).replica_id() != 0;
let open_buffer = OpenBuffer::Complete {
@ -1314,7 +1303,7 @@ impl BufferStore {
unstaged_changes: None,
};
let handle = cx.handle().downgrade();
let handle = cx.model().downgrade();
buffer.update(cx, move |_, cx| {
cx.on_release(move |buffer, cx| {
handle
@ -1350,7 +1339,7 @@ impl BufferStore {
Ok(())
}
pub fn buffers(&self) -> impl '_ + Iterator<Item = Model<Buffer>> {
pub fn buffers(&self) -> impl '_ + Iterator<Item = Entity<Buffer>> {
self.opened_buffers
.values()
.filter_map(|buffer| buffer.upgrade())
@ -1358,14 +1347,14 @@ impl BufferStore {
pub fn loading_buffers(
&self,
) -> impl Iterator<Item = (&ProjectPath, impl Future<Output = Result<Model<Buffer>>>)> {
) -> impl Iterator<Item = (&ProjectPath, impl Future<Output = Result<Entity<Buffer>>>)> {
self.loading_buffers.iter().map(|(path, task)| {
let task = task.clone();
(path, async move { task.await.map_err(|e| anyhow!("{e}")) })
})
}
pub fn get_by_path(&self, path: &ProjectPath, cx: &AppContext) -> Option<Model<Buffer>> {
pub fn get_by_path(&self, path: &ProjectPath, cx: &App) -> Option<Entity<Buffer>> {
self.buffers().find_map(|buffer| {
let file = File::from_dyn(buffer.read(cx).file())?;
if file.worktree_id(cx) == path.worktree_id && file.path == path.path {
@ -1376,23 +1365,23 @@ impl BufferStore {
})
}
pub fn get(&self, buffer_id: BufferId) -> Option<Model<Buffer>> {
pub fn get(&self, buffer_id: BufferId) -> Option<Entity<Buffer>> {
self.opened_buffers.get(&buffer_id)?.upgrade()
}
pub fn get_existing(&self, buffer_id: BufferId) -> Result<Model<Buffer>> {
pub fn get_existing(&self, buffer_id: BufferId) -> Result<Entity<Buffer>> {
self.get(buffer_id)
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))
}
pub fn get_possibly_incomplete(&self, buffer_id: BufferId) -> Option<Model<Buffer>> {
pub fn get_possibly_incomplete(&self, buffer_id: BufferId) -> Option<Entity<Buffer>> {
self.get(buffer_id).or_else(|| {
self.as_remote()
.and_then(|remote| remote.loading_remote_buffers_by_id.get(&buffer_id).cloned())
})
}
pub fn get_unstaged_changes(&self, buffer_id: BufferId) -> Option<Model<BufferChangeSet>> {
pub fn get_unstaged_changes(&self, buffer_id: BufferId) -> Option<Entity<BufferChangeSet>> {
if let OpenBuffer::Complete {
unstaged_changes, ..
} = self.opened_buffers.get(&buffer_id)?
@ -1403,10 +1392,7 @@ impl BufferStore {
}
}
pub fn buffer_version_info(
&self,
cx: &AppContext,
) -> (Vec<proto::BufferVersion>, Vec<BufferId>) {
pub fn buffer_version_info(&self, cx: &App) -> (Vec<proto::BufferVersion>, Vec<BufferId>) {
let buffers = self
.buffers()
.map(|buffer| {
@ -1424,7 +1410,7 @@ impl BufferStore {
(buffers, incomplete_buffer_ids)
}
pub fn disconnected_from_host(&mut self, cx: &mut AppContext) {
pub fn disconnected_from_host(&mut self, cx: &mut App) {
for open_buffer in self.opened_buffers.values_mut() {
if let Some(buffer) = open_buffer.upgrade() {
buffer.update(cx, |buffer, _| buffer.give_up_waiting());
@ -1444,16 +1430,11 @@ impl BufferStore {
}
}
pub fn shared(
&mut self,
remote_id: u64,
downstream_client: AnyProtoClient,
_cx: &mut AppContext,
) {
pub fn shared(&mut self, remote_id: u64, downstream_client: AnyProtoClient, _cx: &mut App) {
self.downstream_client = Some((downstream_client, remote_id));
}
pub fn unshared(&mut self, _cx: &mut ModelContext<Self>) {
pub fn unshared(&mut self, _cx: &mut Context<Self>) {
self.downstream_client.take();
self.forget_shared_buffers();
}
@ -1468,8 +1449,8 @@ impl BufferStore {
query: &SearchQuery,
mut limit: usize,
fs: Arc<dyn Fs>,
cx: &mut ModelContext<Self>,
) -> Receiver<Model<Buffer>> {
cx: &mut Context<Self>,
) -> Receiver<Entity<Buffer>> {
let (tx, rx) = smol::channel::unbounded();
let mut open_buffers = HashSet::default();
let mut unnamed_buffers = Vec::new();
@ -1520,8 +1501,8 @@ impl BufferStore {
pub fn recalculate_buffer_diffs(
&mut self,
buffers: Vec<Model<Buffer>>,
cx: &mut ModelContext<Self>,
buffers: Vec<Entity<Buffer>>,
cx: &mut Context<Self>,
) -> impl Future<Output = ()> {
let mut futures = Vec::new();
for buffer in buffers {
@ -1549,9 +1530,9 @@ impl BufferStore {
fn on_buffer_event(
&mut self,
buffer: Model<Buffer>,
buffer: Entity<Buffer>,
event: &BufferEvent,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
match event {
BufferEvent::FileHandleChanged => {
@ -1579,7 +1560,7 @@ impl BufferStore {
}
pub async fn handle_update_buffer(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::UpdateBuffer>,
mut cx: AsyncAppContext,
) -> Result<proto::Ack> {
@ -1626,7 +1607,7 @@ impl BufferStore {
pub fn handle_synchronize_buffers(
&mut self,
envelope: TypedEnvelope<proto::SynchronizeBuffers>,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
client: Arc<Client>,
) -> Result<proto::SynchronizeBuffersResponse> {
let project_id = envelope.payload.project_id;
@ -1718,7 +1699,7 @@ impl BufferStore {
envelope: TypedEnvelope<proto::CreateBufferForPeer>,
replica_id: u16,
capability: Capability,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> Result<()> {
let Some(remote) = self.as_remote_mut() else {
return Err(anyhow!("buffer store is not a remote"));
@ -1734,7 +1715,7 @@ impl BufferStore {
}
pub async fn handle_update_buffer_file(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::UpdateBufferFile>,
mut cx: AsyncAppContext,
) -> Result<()> {
@ -1782,7 +1763,7 @@ impl BufferStore {
}
pub async fn handle_save_buffer(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::SaveBuffer>,
mut cx: AsyncAppContext,
) -> Result<proto::BufferSaved> {
@ -1823,7 +1804,7 @@ impl BufferStore {
}
pub async fn handle_close_buffer(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::CloseBuffer>,
mut cx: AsyncAppContext,
) -> Result<()> {
@ -1847,7 +1828,7 @@ impl BufferStore {
}
pub async fn handle_buffer_saved(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::BufferSaved>,
mut cx: AsyncAppContext,
) -> Result<()> {
@ -1875,7 +1856,7 @@ impl BufferStore {
}
pub async fn handle_buffer_reloaded(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::BufferReloaded>,
mut cx: AsyncAppContext,
) -> Result<()> {
@ -1908,7 +1889,7 @@ impl BufferStore {
}
pub async fn handle_blame_buffer(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::BlameBuffer>,
mut cx: AsyncAppContext,
) -> Result<proto::BlameBufferResponse> {
@ -1929,7 +1910,7 @@ impl BufferStore {
}
pub async fn handle_get_permalink_to_line(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::GetPermalinkToLine>,
mut cx: AsyncAppContext,
) -> Result<proto::GetPermalinkToLineResponse> {
@ -1954,7 +1935,7 @@ impl BufferStore {
}
pub async fn handle_get_staged_text(
this: Model<Self>,
this: Entity<Self>,
request: TypedEnvelope<proto::GetStagedText>,
mut cx: AsyncAppContext,
) -> Result<proto::GetStagedTextResponse> {
@ -1983,7 +1964,7 @@ impl BufferStore {
}
pub async fn handle_update_diff_base(
this: Model<Self>,
this: Entity<Self>,
request: TypedEnvelope<proto::UpdateDiffBase>,
mut cx: AsyncAppContext,
) -> Result<()> {
@ -2014,9 +1995,9 @@ impl BufferStore {
pub fn reload_buffers(
&self,
buffers: HashSet<Model<Buffer>>,
buffers: HashSet<Entity<Buffer>>,
push_to_history: bool,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> Task<Result<ProjectTransaction>> {
if buffers.is_empty() {
return Task::ready(Ok(ProjectTransaction::default()));
@ -2028,7 +2009,7 @@ impl BufferStore {
}
async fn handle_reload_buffers(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::ReloadBuffers>,
mut cx: AsyncAppContext,
) -> Result<proto::ReloadBuffersResponse> {
@ -2053,9 +2034,9 @@ impl BufferStore {
pub fn create_buffer_for_peer(
&mut self,
buffer: &Model<Buffer>,
buffer: &Entity<Buffer>,
peer_id: proto::PeerId,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> Task<Result<()>> {
let buffer_id = buffer.read(cx).remote_id();
let shared_buffers = self.shared_buffers.entry(peer_id).or_default();
@ -2140,9 +2121,9 @@ impl BufferStore {
&mut self,
text: &str,
language: Option<Arc<Language>>,
cx: &mut ModelContext<Self>,
) -> Model<Buffer> {
let buffer = cx.new_model(|cx| {
cx: &mut Context<Self>,
) -> Entity<Buffer> {
let buffer = cx.new(|cx| {
Buffer::local(text, cx)
.with_language(language.unwrap_or_else(|| language::PLAIN_TEXT.clone()), cx)
});
@ -2174,7 +2155,7 @@ impl BufferStore {
&mut self,
message: proto::ProjectTransaction,
push_to_history: bool,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> Task<Result<ProjectTransaction>> {
if let Some(this) = self.as_remote_mut() {
this.deserialize_project_transaction(message, push_to_history, cx)
@ -2187,8 +2168,8 @@ impl BufferStore {
pub fn wait_for_remote_buffer(
&mut self,
id: BufferId,
cx: &mut ModelContext<BufferStore>,
) -> Task<Result<Model<Buffer>>> {
cx: &mut Context<BufferStore>,
) -> Task<Result<Entity<Buffer>>> {
if let Some(this) = self.as_remote_mut() {
this.wait_for_remote_buffer(id, cx)
} else {
@ -2201,7 +2182,7 @@ impl BufferStore {
&mut self,
project_transaction: ProjectTransaction,
peer_id: proto::PeerId,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> proto::ProjectTransaction {
let mut serialized_transaction = proto::ProjectTransaction {
buffer_ids: Default::default(),
@ -2222,7 +2203,7 @@ impl BufferStore {
}
impl BufferChangeSet {
pub fn new(buffer: &Model<Buffer>, cx: &mut ModelContext<Self>) -> Self {
pub fn new(buffer: &Entity<Buffer>, cx: &mut Context<Self>) -> Self {
cx.subscribe(buffer, |this, buffer, event, cx| match event {
BufferEvent::LanguageChanged => {
this.language = buffer.read(cx).language().cloned();
@ -2262,8 +2243,8 @@ impl BufferChangeSet {
#[cfg(any(test, feature = "test-support"))]
pub fn new_with_base_text(
base_text: String,
buffer: &Model<Buffer>,
cx: &mut ModelContext<Self>,
buffer: &Entity<Buffer>,
cx: &mut Context<Self>,
) -> Self {
let mut this = Self::new(&buffer, cx);
let _ = this.set_base_text(base_text, buffer.read(cx).text_snapshot(), cx);
@ -2297,7 +2278,7 @@ impl BufferChangeSet {
&mut self,
mut base_text: String,
buffer_snapshot: text::BufferSnapshot,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> oneshot::Receiver<()> {
LineEnding::normalize(&mut base_text);
self.recalculate_diff_internal(base_text, buffer_snapshot, true, cx)
@ -2306,7 +2287,7 @@ impl BufferChangeSet {
pub fn unset_base_text(
&mut self,
buffer_snapshot: text::BufferSnapshot,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
if self.base_text.is_some() {
self.base_text = None;
@ -2319,7 +2300,7 @@ impl BufferChangeSet {
pub fn recalculate_diff(
&mut self,
buffer_snapshot: text::BufferSnapshot,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> oneshot::Receiver<()> {
if let Some(base_text) = self.base_text.clone() {
self.recalculate_diff_internal(base_text.text(), buffer_snapshot, false, cx)
@ -2333,7 +2314,7 @@ impl BufferChangeSet {
base_text: String,
buffer_snapshot: text::BufferSnapshot,
base_text_changed: bool,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> oneshot::Receiver<()> {
let (tx, rx) = oneshot::channel();
self.diff_updated_futures.push(tx);
@ -2381,7 +2362,7 @@ impl BufferChangeSet {
mut base_text: String,
buffer_snapshot: text::BufferSnapshot,
base_text_changed: bool,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
LineEnding::normalize(&mut base_text);
let diff = BufferDiff::build(&base_text, &buffer_snapshot);
@ -2404,7 +2385,7 @@ impl BufferChangeSet {
}
impl OpenBuffer {
fn upgrade(&self) -> Option<Model<Buffer>> {
fn upgrade(&self) -> Option<Entity<Buffer>> {
match self {
OpenBuffer::Complete { buffer, .. } => buffer.upgrade(),
OpenBuffer::Operations(_) => None,

View file

@ -3,25 +3,25 @@ use anyhow::Result;
use client::Client;
use collections::{HashMap, HashSet};
use futures::{FutureExt, StreamExt};
use gpui::{AppContext, AsyncAppContext, Context, Global, Model, ModelContext, Task, WeakModel};
use gpui::{App, AppContext as _, AsyncAppContext, Context, Entity, Global, Task, WeakEntity};
use postage::stream::Stream;
use rpc::proto;
use std::{sync::Arc, time::Duration};
use util::{ResultExt, TryFutureExt};
impl Global for GlobalManager {}
struct GlobalManager(Model<Manager>);
struct GlobalManager(Entity<Manager>);
pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(30);
pub struct Manager {
client: Arc<Client>,
maintain_connection: Option<Task<Option<()>>>,
projects: HashSet<WeakModel<Project>>,
projects: HashSet<WeakEntity<Project>>,
}
pub fn init(client: Arc<Client>, cx: &mut AppContext) {
let manager = cx.new_model(|_| Manager {
pub fn init(client: Arc<Client>, cx: &mut App) {
let manager = cx.new(|_| Manager {
client,
maintain_connection: None,
projects: HashSet::default(),
@ -30,14 +30,14 @@ pub fn init(client: Arc<Client>, cx: &mut AppContext) {
}
impl Manager {
pub fn global(cx: &AppContext) -> Model<Manager> {
pub fn global(cx: &App) -> Entity<Manager> {
cx.global::<GlobalManager>().0.clone()
}
pub fn maintain_project_connection(
&mut self,
project: &Model<Project>,
cx: &mut ModelContext<Self>,
project: &Entity<Project>,
cx: &mut Context<Self>,
) {
let manager = cx.weak_model();
project.update(cx, |_, cx| {
@ -70,7 +70,7 @@ impl Manager {
}
}
fn reconnected(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
fn reconnected(&mut self, cx: &mut Context<Self>) -> Task<Result<()>> {
let mut projects = HashMap::default();
let request = self.client.request_envelope(proto::RejoinRemoteProjects {
@ -118,7 +118,7 @@ impl Manager {
})
}
fn connection_lost(&mut self, cx: &mut ModelContext<Self>) {
fn connection_lost(&mut self, cx: &mut Context<Self>) {
for project in self.projects.drain() {
if let Some(project) = project.upgrade() {
project.update(cx, |project, cx| {
@ -131,7 +131,7 @@ impl Manager {
}
async fn maintain_connection(
this: WeakModel<Self>,
this: WeakEntity<Self>,
client: Arc<Client>,
mut cx: AsyncAppContext,
) -> Result<()> {

View file

@ -1,5 +1,5 @@
use futures::{channel::oneshot, FutureExt};
use gpui::{ModelContext, Task};
use gpui::{Context, Task};
use std::{marker::PhantomData, time::Duration};
pub struct DebouncedDelay<E: 'static> {
@ -23,9 +23,9 @@ impl<E: 'static> DebouncedDelay<E> {
}
}
pub fn fire_new<F>(&mut self, delay: Duration, cx: &mut ModelContext<E>, func: F)
pub fn fire_new<F>(&mut self, delay: Duration, cx: &mut Context<E>, func: F)
where
F: 'static + Send + FnOnce(&mut E, &mut ModelContext<E>) -> Task<()>,
F: 'static + Send + FnOnce(&mut E, &mut Context<E>) -> Task<()>,
{
if let Some(channel) = self.cancel_channel.take() {
_ = channel.send(());

View file

@ -3,7 +3,7 @@ use std::{path::Path, sync::Arc};
use util::ResultExt;
use collections::HashMap;
use gpui::{AppContext, Context, Model, ModelContext, Task};
use gpui::{App, AppContext as _, Context, Entity, Task};
use settings::Settings as _;
use worktree::WorktreeId;
@ -13,7 +13,7 @@ use crate::{
};
pub struct ProjectEnvironment {
worktree_store: Model<WorktreeStore>,
worktree_store: Entity<WorktreeStore>,
cli_environment: Option<HashMap<String, String>>,
environments: HashMap<WorktreeId, Shared<Task<Option<HashMap<String, String>>>>>,
environment_error_messages: HashMap<WorktreeId, EnvironmentErrorMessage>,
@ -21,11 +21,11 @@ pub struct ProjectEnvironment {
impl ProjectEnvironment {
pub fn new(
worktree_store: &Model<WorktreeStore>,
worktree_store: &Entity<WorktreeStore>,
cli_environment: Option<HashMap<String, String>>,
cx: &mut AppContext,
) -> Model<Self> {
cx.new_model(|cx| {
cx: &mut App,
) -> Entity<Self> {
cx.new(|cx| {
cx.subscribe(worktree_store, |this: &mut Self, _, event, _| {
if let WorktreeStoreEvent::WorktreeRemoved(_, id) = event {
this.remove_worktree_environment(*id);
@ -78,7 +78,7 @@ impl ProjectEnvironment {
&mut self,
worktree_id: Option<WorktreeId>,
worktree_abs_path: Option<Arc<Path>>,
cx: &ModelContext<Self>,
cx: &Context<Self>,
) -> Shared<Task<Option<HashMap<String, String>>>> {
if cfg!(any(test, feature = "test-support")) {
return Task::ready(Some(HashMap::default())).shared();
@ -129,7 +129,7 @@ impl ProjectEnvironment {
&mut self,
worktree_id: WorktreeId,
worktree_abs_path: Arc<Path>,
cx: &ModelContext<Self>,
cx: &Context<Self>,
) -> Task<Option<HashMap<String, String>>> {
let load_direnv = ProjectSettings::get_global(cx).load_direnv.clone();

View file

@ -8,8 +8,7 @@ use git::{
status::{GitSummary, TrackedSummary},
};
use gpui::{
AppContext, Context as _, EventEmitter, Model, ModelContext, SharedString, Subscription,
WeakModel,
App, AppContext as _, Context, Entity, EventEmitter, SharedString, Subscription, WeakEntity,
};
use language::{Buffer, LanguageRegistry};
use settings::WorktreeId;
@ -28,11 +27,11 @@ pub struct GitState {
#[derive(Clone)]
pub struct RepositoryHandle {
git_state: WeakModel<GitState>,
git_state: WeakEntity<GitState>,
worktree_id: WorktreeId,
repository_entry: RepositoryEntry,
git_repo: Arc<dyn GitRepository>,
commit_message: Model<Buffer>,
commit_message: Entity<Buffer>,
update_sender: mpsc::UnboundedSender<(Message, mpsc::Sender<anyhow::Error>)>,
}
@ -67,9 +66,9 @@ impl EventEmitter<Event> for GitState {}
impl GitState {
pub fn new(
worktree_store: &Model<WorktreeStore>,
worktree_store: &Entity<WorktreeStore>,
languages: Arc<LanguageRegistry>,
cx: &mut ModelContext<'_, Self>,
cx: &mut Context<'_, Self>,
) -> Self {
let (update_sender, mut update_receiver) =
mpsc::unbounded::<(Message, mpsc::Sender<anyhow::Error>)>();
@ -115,9 +114,9 @@ impl GitState {
fn on_worktree_store_event(
&mut self,
worktree_store: Model<WorktreeStore>,
worktree_store: Entity<WorktreeStore>,
_event: &WorktreeStoreEvent,
cx: &mut ModelContext<'_, Self>,
cx: &mut Context<'_, Self>,
) {
// TODO inspect the event
@ -150,7 +149,7 @@ impl GitState {
existing_handle.repository_entry = repo.clone();
existing_handle
} else {
let commit_message = cx.new_model(|cx| Buffer::local("", cx));
let commit_message = cx.new(|cx| Buffer::local("", cx));
cx.spawn({
let commit_message = commit_message.downgrade();
let languages = self.languages.clone();
@ -194,7 +193,7 @@ impl GitState {
}
impl RepositoryHandle {
pub fn display_name(&self, project: &Project, cx: &AppContext) -> SharedString {
pub fn display_name(&self, project: &Project, cx: &App) -> SharedString {
maybe!({
let path = self.unrelativize(&"".into())?;
Some(
@ -209,7 +208,7 @@ impl RepositoryHandle {
.unwrap_or("".into())
}
pub fn activate(&self, cx: &mut AppContext) {
pub fn activate(&self, cx: &mut App) {
let Some(git_state) = self.git_state.upgrade() else {
return;
};
@ -236,7 +235,7 @@ impl RepositoryHandle {
Some((self.worktree_id, path).into())
}
pub fn commit_message(&self) -> Model<Buffer> {
pub fn commit_message(&self) -> Entity<Buffer> {
self.commit_message.clone()
}
@ -304,7 +303,7 @@ impl RepositoryHandle {
self.repository_entry.status_summary().index != TrackedSummary::UNCHANGED
}
pub fn can_commit(&self, commit_all: bool, cx: &AppContext) -> bool {
pub fn can_commit(&self, commit_all: bool, cx: &App) -> bool {
return self
.commit_message
.read(cx)
@ -314,7 +313,7 @@ impl RepositoryHandle {
&& (commit_all || self.have_staged_changes());
}
pub fn commit(&self, mut err_sender: mpsc::Sender<anyhow::Error>, cx: &mut AppContext) {
pub fn commit(&self, mut err_sender: mpsc::Sender<anyhow::Error>, cx: &mut App) {
let message = self.commit_message.read(cx).as_rope().clone();
let result = self.update_sender.unbounded_send((
Message::Commit(self.git_repo.clone(), message),
@ -335,7 +334,7 @@ impl RepositoryHandle {
});
}
pub fn commit_all(&self, mut err_sender: mpsc::Sender<anyhow::Error>, cx: &mut AppContext) {
pub fn commit_all(&self, mut err_sender: mpsc::Sender<anyhow::Error>, cx: &mut App) {
let to_stage = self
.repository_entry
.status()

View file

@ -6,8 +6,7 @@ use anyhow::{Context as _, Result};
use collections::{hash_map, HashMap, HashSet};
use futures::{channel::oneshot, StreamExt};
use gpui::{
hash, prelude::*, AppContext, EventEmitter, Img, Model, ModelContext, Subscription, Task,
WeakModel,
hash, prelude::*, App, Context, Entity, EventEmitter, Img, Subscription, Task, WeakEntity,
};
use language::{DiskState, File};
use rpc::{AnyProtoClient, ErrorExt as _};
@ -42,7 +41,7 @@ pub enum ImageItemEvent {
impl EventEmitter<ImageItemEvent> for ImageItem {}
pub enum ImageStoreEvent {
ImageAdded(Model<ImageItem>),
ImageAdded(Entity<ImageItem>),
}
impl EventEmitter<ImageStoreEvent> for ImageStore {}
@ -55,7 +54,7 @@ pub struct ImageItem {
}
impl ImageItem {
pub fn project_path(&self, cx: &AppContext) -> ProjectPath {
pub fn project_path(&self, cx: &App) -> ProjectPath {
ProjectPath {
worktree_id: self.file.worktree_id(cx),
path: self.file.path().clone(),
@ -66,7 +65,7 @@ impl ImageItem {
self.file.path()
}
fn file_updated(&mut self, new_file: Arc<dyn File>, cx: &mut ModelContext<Self>) {
fn file_updated(&mut self, new_file: Arc<dyn File>, cx: &mut Context<Self>) {
let mut file_changed = false;
let old_file = self.file.as_ref();
@ -90,7 +89,7 @@ impl ImageItem {
}
}
fn reload(&mut self, cx: &mut ModelContext<Self>) -> Option<oneshot::Receiver<()>> {
fn reload(&mut self, cx: &mut Context<Self>) -> Option<oneshot::Receiver<()>> {
let local_file = self.file.as_local()?;
let (tx, rx) = futures::channel::oneshot::channel();
@ -116,10 +115,10 @@ impl ImageItem {
impl ProjectItem for ImageItem {
fn try_open(
project: &Model<Project>,
project: &Entity<Project>,
path: &ProjectPath,
cx: &mut AppContext,
) -> Option<Task<gpui::Result<Model<Self>>>> {
cx: &mut App,
) -> Option<Task<gpui::Result<Entity<Self>>>> {
let path = path.clone();
let project = project.clone();
@ -152,11 +151,11 @@ impl ProjectItem for ImageItem {
}
}
fn entry_id(&self, _: &AppContext) -> Option<ProjectEntryId> {
fn entry_id(&self, _: &App) -> Option<ProjectEntryId> {
worktree::File::from_dyn(Some(&self.file))?.entry_id
}
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath> {
fn project_path(&self, cx: &App) -> Option<ProjectPath> {
Some(self.project_path(cx).clone())
}
@ -169,17 +168,17 @@ trait ImageStoreImpl {
fn open_image(
&self,
path: Arc<Path>,
worktree: Model<Worktree>,
cx: &mut ModelContext<ImageStore>,
) -> Task<Result<Model<ImageItem>>>;
worktree: Entity<Worktree>,
cx: &mut Context<ImageStore>,
) -> Task<Result<Entity<ImageItem>>>;
fn reload_images(
&self,
images: HashSet<Model<ImageItem>>,
cx: &mut ModelContext<ImageStore>,
images: HashSet<Entity<ImageItem>>,
cx: &mut Context<ImageStore>,
) -> Task<Result<()>>;
fn as_local(&self) -> Option<Model<LocalImageStore>>;
fn as_local(&self) -> Option<Entity<LocalImageStore>>;
}
struct RemoteImageStore {}
@ -187,26 +186,26 @@ struct RemoteImageStore {}
struct LocalImageStore {
local_image_ids_by_path: HashMap<ProjectPath, ImageId>,
local_image_ids_by_entry_id: HashMap<ProjectEntryId, ImageId>,
image_store: WeakModel<ImageStore>,
image_store: WeakEntity<ImageStore>,
_subscription: Subscription,
}
pub struct ImageStore {
state: Box<dyn ImageStoreImpl>,
opened_images: HashMap<ImageId, WeakModel<ImageItem>>,
worktree_store: Model<WorktreeStore>,
opened_images: HashMap<ImageId, WeakEntity<ImageItem>>,
worktree_store: Entity<WorktreeStore>,
#[allow(clippy::type_complexity)]
loading_images_by_path: HashMap<
ProjectPath,
postage::watch::Receiver<Option<Result<Model<ImageItem>, Arc<anyhow::Error>>>>,
postage::watch::Receiver<Option<Result<Entity<ImageItem>, Arc<anyhow::Error>>>>,
>,
}
impl ImageStore {
pub fn local(worktree_store: Model<WorktreeStore>, cx: &mut ModelContext<Self>) -> Self {
pub fn local(worktree_store: Entity<WorktreeStore>, cx: &mut Context<Self>) -> Self {
let this = cx.weak_model();
Self {
state: Box::new(cx.new_model(|cx| {
state: Box::new(cx.new(|cx| {
let subscription = cx.subscribe(
&worktree_store,
|this: &mut LocalImageStore, _, event, cx| {
@ -230,32 +229,32 @@ impl ImageStore {
}
pub fn remote(
worktree_store: Model<WorktreeStore>,
worktree_store: Entity<WorktreeStore>,
_upstream_client: AnyProtoClient,
_remote_id: u64,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> Self {
Self {
state: Box::new(cx.new_model(|_| RemoteImageStore {})),
state: Box::new(cx.new(|_| RemoteImageStore {})),
opened_images: Default::default(),
loading_images_by_path: Default::default(),
worktree_store,
}
}
pub fn images(&self) -> impl '_ + Iterator<Item = Model<ImageItem>> {
pub fn images(&self) -> impl '_ + Iterator<Item = Entity<ImageItem>> {
self.opened_images
.values()
.filter_map(|image| image.upgrade())
}
pub fn get(&self, image_id: ImageId) -> Option<Model<ImageItem>> {
pub fn get(&self, image_id: ImageId) -> Option<Entity<ImageItem>> {
self.opened_images
.get(&image_id)
.and_then(|image| image.upgrade())
}
pub fn get_by_path(&self, path: &ProjectPath, cx: &AppContext) -> Option<Model<ImageItem>> {
pub fn get_by_path(&self, path: &ProjectPath, cx: &App) -> Option<Entity<ImageItem>> {
self.images()
.find(|image| &image.read(cx).project_path(cx) == path)
}
@ -263,8 +262,8 @@ impl ImageStore {
pub fn open_image(
&mut self,
project_path: ProjectPath,
cx: &mut ModelContext<Self>,
) -> Task<Result<Model<ImageItem>>> {
cx: &mut Context<Self>,
) -> Task<Result<Entity<ImageItem>>> {
let existing_image = self.get_by_path(&project_path, cx);
if let Some(existing_image) = existing_image {
return Task::ready(Ok(existing_image));
@ -317,9 +316,9 @@ impl ImageStore {
pub async fn wait_for_loading_image(
mut receiver: postage::watch::Receiver<
Option<Result<Model<ImageItem>, Arc<anyhow::Error>>>,
Option<Result<Entity<ImageItem>, Arc<anyhow::Error>>>,
>,
) -> Result<Model<ImageItem>, Arc<anyhow::Error>> {
) -> Result<Entity<ImageItem>, Arc<anyhow::Error>> {
loop {
if let Some(result) = receiver.borrow().as_ref() {
match result {
@ -333,8 +332,8 @@ impl ImageStore {
pub fn reload_images(
&self,
images: HashSet<Model<ImageItem>>,
cx: &mut ModelContext<ImageStore>,
images: HashSet<Entity<ImageItem>>,
cx: &mut Context<ImageStore>,
) -> Task<Result<()>> {
if images.is_empty() {
return Task::ready(Ok(()));
@ -343,11 +342,7 @@ impl ImageStore {
self.state.reload_images(images, cx)
}
fn add_image(
&mut self,
image: Model<ImageItem>,
cx: &mut ModelContext<ImageStore>,
) -> Result<()> {
fn add_image(&mut self, image: Entity<ImageItem>, cx: &mut Context<ImageStore>) -> Result<()> {
let image_id = image.read(cx).id;
self.opened_images.insert(image_id, image.downgrade());
@ -359,9 +354,9 @@ impl ImageStore {
fn on_image_event(
&mut self,
image: Model<ImageItem>,
image: Entity<ImageItem>,
event: &ImageItemEvent,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
match event {
ImageItemEvent::FileHandleChanged => {
@ -376,13 +371,13 @@ impl ImageStore {
}
}
impl ImageStoreImpl for Model<LocalImageStore> {
impl ImageStoreImpl for Entity<LocalImageStore> {
fn open_image(
&self,
path: Arc<Path>,
worktree: Model<Worktree>,
cx: &mut ModelContext<ImageStore>,
) -> Task<Result<Model<ImageItem>>> {
worktree: Entity<Worktree>,
cx: &mut Context<ImageStore>,
) -> Task<Result<Entity<ImageItem>>> {
let this = self.clone();
let load_file = worktree.update(cx, |worktree, cx| {
@ -392,7 +387,7 @@ impl ImageStoreImpl for Model<LocalImageStore> {
let LoadedBinaryFile { file, content } = load_file.await?;
let image = create_gpui_image(content)?;
let model = cx.new_model(|cx| ImageItem {
let model = cx.new(|cx| ImageItem {
id: cx.entity_id().as_non_zero_u64().into(),
file: file.clone(),
image,
@ -426,8 +421,8 @@ impl ImageStoreImpl for Model<LocalImageStore> {
fn reload_images(
&self,
images: HashSet<Model<ImageItem>>,
cx: &mut ModelContext<ImageStore>,
images: HashSet<Entity<ImageItem>>,
cx: &mut Context<ImageStore>,
) -> Task<Result<()>> {
cx.spawn(move |_, mut cx| async move {
for image in images {
@ -439,13 +434,13 @@ impl ImageStoreImpl for Model<LocalImageStore> {
})
}
fn as_local(&self) -> Option<Model<LocalImageStore>> {
fn as_local(&self) -> Option<Entity<LocalImageStore>> {
Some(self.clone())
}
}
impl LocalImageStore {
fn subscribe_to_worktree(&mut self, worktree: &Model<Worktree>, cx: &mut ModelContext<Self>) {
fn subscribe_to_worktree(&mut self, worktree: &Entity<Worktree>, cx: &mut Context<Self>) {
cx.subscribe(worktree, |this, worktree, event, cx| {
if worktree.read(cx).is_local() {
match event {
@ -461,9 +456,9 @@ impl LocalImageStore {
fn local_worktree_entries_changed(
&mut self,
worktree_handle: &Model<Worktree>,
worktree_handle: &Entity<Worktree>,
changes: &[(Arc<Path>, ProjectEntryId, PathChange)],
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
let snapshot = worktree_handle.read(cx).snapshot();
for (path, entry_id, _) in changes {
@ -475,9 +470,9 @@ impl LocalImageStore {
&mut self,
entry_id: ProjectEntryId,
path: &Arc<Path>,
worktree: &Model<worktree::Worktree>,
worktree: &Entity<worktree::Worktree>,
snapshot: &worktree::Snapshot,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> Option<()> {
let project_path = ProjectPath {
worktree_id: snapshot.id(),
@ -576,7 +571,7 @@ impl LocalImageStore {
None
}
fn image_changed_file(&mut self, image: Model<ImageItem>, cx: &mut AppContext) -> Option<()> {
fn image_changed_file(&mut self, image: Entity<ImageItem>, cx: &mut App) -> Option<()> {
let file = worktree::File::from_dyn(Some(&image.read(cx).file))?;
let image_id = image.read(cx).id;
@ -620,13 +615,13 @@ fn create_gpui_image(content: Vec<u8>) -> anyhow::Result<Arc<gpui::Image>> {
}))
}
impl ImageStoreImpl for Model<RemoteImageStore> {
impl ImageStoreImpl for Entity<RemoteImageStore> {
fn open_image(
&self,
_path: Arc<Path>,
_worktree: Model<Worktree>,
_cx: &mut ModelContext<ImageStore>,
) -> Task<Result<Model<ImageItem>>> {
_worktree: Entity<Worktree>,
_cx: &mut Context<ImageStore>,
) -> Task<Result<Entity<ImageItem>>> {
Task::ready(Err(anyhow::anyhow!(
"Opening images from remote is not supported"
)))
@ -634,15 +629,15 @@ impl ImageStoreImpl for Model<RemoteImageStore> {
fn reload_images(
&self,
_images: HashSet<Model<ImageItem>>,
_cx: &mut ModelContext<ImageStore>,
_images: HashSet<Entity<ImageItem>>,
_cx: &mut Context<ImageStore>,
) -> Task<Result<()>> {
Task::ready(Err(anyhow::anyhow!(
"Reloading images from remote is not supported"
)))
}
fn as_local(&self) -> Option<Model<LocalImageStore>> {
fn as_local(&self) -> Option<Entity<LocalImageStore>> {
None
}
}

View file

@ -6,13 +6,13 @@ use crate::{
InlayHintLabel, InlayHintLabelPart, InlayHintLabelPartTooltip, InlayHintTooltip, Location,
LocationLink, MarkupContent, PrepareRenameResponse, ProjectTransaction, ResolveState,
};
use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, Context as _, Result};
use async_trait::async_trait;
use client::proto::{self, PeerId};
use clock::Global;
use collections::HashSet;
use futures::future;
use gpui::{AppContext, AsyncAppContext, Entity, Model};
use gpui::{App, AsyncAppContext, Entity};
use language::{
language_settings::{language_settings, InlayHintKind, LanguageSettings},
point_from_lsp, point_to_lsp,
@ -87,7 +87,7 @@ pub trait LspCommand: 'static + Sized + Send + std::fmt::Debug {
path: &Path,
buffer: &Buffer,
language_server: &Arc<LanguageServer>,
cx: &AppContext,
cx: &App,
) -> Result<
LspParamsOrResponse<<Self::LspRequest as lsp::request::Request>::Params, Self::Response>,
> {
@ -113,14 +113,14 @@ pub trait LspCommand: 'static + Sized + Send + std::fmt::Debug {
path: &Path,
buffer: &Buffer,
language_server: &Arc<LanguageServer>,
cx: &AppContext,
cx: &App,
) -> Result<<Self::LspRequest as lsp::request::Request>::Params>;
async fn response_from_lsp(
self,
message: <Self::LspRequest as lsp::request::Request>::Result,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
cx: AsyncAppContext,
) -> Result<Self::Response>;
@ -129,8 +129,8 @@ pub trait LspCommand: 'static + Sized + Send + std::fmt::Debug {
async fn from_proto(
message: Self::ProtoRequest,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
cx: AsyncAppContext,
) -> Result<Self>;
@ -139,14 +139,14 @@ pub trait LspCommand: 'static + Sized + Send + std::fmt::Debug {
lsp_store: &mut LspStore,
peer_id: PeerId,
buffer_version: &clock::Global,
cx: &mut AppContext,
cx: &mut App,
) -> <Self::ProtoRequest as proto::RequestMessage>::Response;
async fn response_from_proto(
self,
message: <Self::ProtoRequest as proto::RequestMessage>::Response,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
cx: AsyncAppContext,
) -> Result<Self::Response>;
@ -255,7 +255,7 @@ impl LspCommand for PrepareRename {
path: &Path,
buffer: &Buffer,
language_server: &Arc<LanguageServer>,
cx: &AppContext,
cx: &App,
) -> Result<LspParamsOrResponse<lsp::TextDocumentPositionParams, PrepareRenameResponse>> {
let rename_provider = language_server
.adapter_server_capabilities()
@ -286,7 +286,7 @@ impl LspCommand for PrepareRename {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::TextDocumentPositionParams> {
make_lsp_text_document_position(path, self.position)
}
@ -294,8 +294,8 @@ impl LspCommand for PrepareRename {
async fn response_from_lsp(
self,
message: Option<lsp::PrepareRenameResponse>,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
_: LanguageServerId,
mut cx: AsyncAppContext,
) -> Result<PrepareRenameResponse> {
@ -337,8 +337,8 @@ impl LspCommand for PrepareRename {
async fn from_proto(
message: proto::PrepareRename,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -361,7 +361,7 @@ impl LspCommand for PrepareRename {
_: &mut LspStore,
_: PeerId,
buffer_version: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::PrepareRenameResponse {
match response {
PrepareRenameResponse::Success(range) => proto::PrepareRenameResponse {
@ -391,8 +391,8 @@ impl LspCommand for PrepareRename {
async fn response_from_proto(
self,
message: proto::PrepareRenameResponse,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<PrepareRenameResponse> {
if message.can_rename {
@ -438,7 +438,7 @@ impl LspCommand for PerformRename {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::RenameParams> {
Ok(lsp::RenameParams {
text_document_position: make_lsp_text_document_position(path, self.position)?,
@ -450,8 +450,8 @@ impl LspCommand for PerformRename {
async fn response_from_lsp(
self,
message: Option<lsp::WorkspaceEdit>,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
mut cx: AsyncAppContext,
) -> Result<ProjectTransaction> {
@ -486,8 +486,8 @@ impl LspCommand for PerformRename {
async fn from_proto(
message: proto::PerformRename,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -511,7 +511,7 @@ impl LspCommand for PerformRename {
lsp_store: &mut LspStore,
peer_id: PeerId,
_: &clock::Global,
cx: &mut AppContext,
cx: &mut App,
) -> proto::PerformRenameResponse {
let transaction = lsp_store.buffer_store().update(cx, |buffer_store, cx| {
buffer_store.serialize_project_transaction_for_peer(response, peer_id, cx)
@ -524,8 +524,8 @@ impl LspCommand for PerformRename {
async fn response_from_proto(
self,
message: proto::PerformRenameResponse,
lsp_store: Model<LspStore>,
_: Model<Buffer>,
lsp_store: Entity<LspStore>,
_: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<ProjectTransaction> {
let message = message
@ -567,7 +567,7 @@ impl LspCommand for GetDefinition {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::GotoDefinitionParams> {
Ok(lsp::GotoDefinitionParams {
text_document_position_params: make_lsp_text_document_position(path, self.position)?,
@ -579,8 +579,8 @@ impl LspCommand for GetDefinition {
async fn response_from_lsp(
self,
message: Option<lsp::GotoDefinitionResponse>,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
cx: AsyncAppContext,
) -> Result<Vec<LocationLink>> {
@ -600,8 +600,8 @@ impl LspCommand for GetDefinition {
async fn from_proto(
message: proto::GetDefinition,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -623,7 +623,7 @@ impl LspCommand for GetDefinition {
lsp_store: &mut LspStore,
peer_id: PeerId,
_: &clock::Global,
cx: &mut AppContext,
cx: &mut App,
) -> proto::GetDefinitionResponse {
let links = location_links_to_proto(response, lsp_store, peer_id, cx);
proto::GetDefinitionResponse { links }
@ -632,8 +632,8 @@ impl LspCommand for GetDefinition {
async fn response_from_proto(
self,
message: proto::GetDefinitionResponse,
lsp_store: Model<LspStore>,
_: Model<Buffer>,
lsp_store: Entity<LspStore>,
_: Entity<Buffer>,
cx: AsyncAppContext,
) -> Result<Vec<LocationLink>> {
location_links_from_proto(message.links, lsp_store, cx).await
@ -666,7 +666,7 @@ impl LspCommand for GetDeclaration {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::GotoDeclarationParams> {
Ok(lsp::GotoDeclarationParams {
text_document_position_params: make_lsp_text_document_position(path, self.position)?,
@ -678,8 +678,8 @@ impl LspCommand for GetDeclaration {
async fn response_from_lsp(
self,
message: Option<lsp::GotoDeclarationResponse>,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
cx: AsyncAppContext,
) -> Result<Vec<LocationLink>> {
@ -699,8 +699,8 @@ impl LspCommand for GetDeclaration {
async fn from_proto(
message: proto::GetDeclaration,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -722,7 +722,7 @@ impl LspCommand for GetDeclaration {
lsp_store: &mut LspStore,
peer_id: PeerId,
_: &clock::Global,
cx: &mut AppContext,
cx: &mut App,
) -> proto::GetDeclarationResponse {
let links = location_links_to_proto(response, lsp_store, peer_id, cx);
proto::GetDeclarationResponse { links }
@ -731,8 +731,8 @@ impl LspCommand for GetDeclaration {
async fn response_from_proto(
self,
message: proto::GetDeclarationResponse,
lsp_store: Model<LspStore>,
_: Model<Buffer>,
lsp_store: Entity<LspStore>,
_: Entity<Buffer>,
cx: AsyncAppContext,
) -> Result<Vec<LocationLink>> {
location_links_from_proto(message.links, lsp_store, cx).await
@ -758,7 +758,7 @@ impl LspCommand for GetImplementation {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::GotoImplementationParams> {
Ok(lsp::GotoImplementationParams {
text_document_position_params: make_lsp_text_document_position(path, self.position)?,
@ -770,8 +770,8 @@ impl LspCommand for GetImplementation {
async fn response_from_lsp(
self,
message: Option<lsp::GotoImplementationResponse>,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
cx: AsyncAppContext,
) -> Result<Vec<LocationLink>> {
@ -791,8 +791,8 @@ impl LspCommand for GetImplementation {
async fn from_proto(
message: proto::GetImplementation,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -814,7 +814,7 @@ impl LspCommand for GetImplementation {
lsp_store: &mut LspStore,
peer_id: PeerId,
_: &clock::Global,
cx: &mut AppContext,
cx: &mut App,
) -> proto::GetImplementationResponse {
let links = location_links_to_proto(response, lsp_store, peer_id, cx);
proto::GetImplementationResponse { links }
@ -823,8 +823,8 @@ impl LspCommand for GetImplementation {
async fn response_from_proto(
self,
message: proto::GetImplementationResponse,
project: Model<LspStore>,
_: Model<Buffer>,
project: Entity<LspStore>,
_: Entity<Buffer>,
cx: AsyncAppContext,
) -> Result<Vec<LocationLink>> {
location_links_from_proto(message.links, project, cx).await
@ -857,7 +857,7 @@ impl LspCommand for GetTypeDefinition {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::GotoTypeDefinitionParams> {
Ok(lsp::GotoTypeDefinitionParams {
text_document_position_params: make_lsp_text_document_position(path, self.position)?,
@ -869,8 +869,8 @@ impl LspCommand for GetTypeDefinition {
async fn response_from_lsp(
self,
message: Option<lsp::GotoTypeDefinitionResponse>,
project: Model<LspStore>,
buffer: Model<Buffer>,
project: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
cx: AsyncAppContext,
) -> Result<Vec<LocationLink>> {
@ -890,8 +890,8 @@ impl LspCommand for GetTypeDefinition {
async fn from_proto(
message: proto::GetTypeDefinition,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -913,7 +913,7 @@ impl LspCommand for GetTypeDefinition {
lsp_store: &mut LspStore,
peer_id: PeerId,
_: &clock::Global,
cx: &mut AppContext,
cx: &mut App,
) -> proto::GetTypeDefinitionResponse {
let links = location_links_to_proto(response, lsp_store, peer_id, cx);
proto::GetTypeDefinitionResponse { links }
@ -922,8 +922,8 @@ impl LspCommand for GetTypeDefinition {
async fn response_from_proto(
self,
message: proto::GetTypeDefinitionResponse,
project: Model<LspStore>,
_: Model<Buffer>,
project: Entity<LspStore>,
_: Entity<Buffer>,
cx: AsyncAppContext,
) -> Result<Vec<LocationLink>> {
location_links_from_proto(message.links, project, cx).await
@ -935,8 +935,8 @@ impl LspCommand for GetTypeDefinition {
}
fn language_server_for_buffer(
lsp_store: &Model<LspStore>,
buffer: &Model<Buffer>,
lsp_store: &Entity<LspStore>,
buffer: &Entity<Buffer>,
server_id: LanguageServerId,
cx: &mut AsyncAppContext,
) -> Result<(Arc<CachedLspAdapter>, Arc<LanguageServer>)> {
@ -951,7 +951,7 @@ fn language_server_for_buffer(
async fn location_links_from_proto(
proto_links: Vec<proto::LocationLink>,
lsp_store: Model<LspStore>,
lsp_store: Entity<LspStore>,
mut cx: AsyncAppContext,
) -> Result<Vec<LocationLink>> {
let mut links = Vec::new();
@ -1015,8 +1015,8 @@ async fn location_links_from_proto(
async fn location_links_from_lsp(
message: Option<lsp::GotoDefinitionResponse>,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
mut cx: AsyncAppContext,
) -> Result<Vec<LocationLink>> {
@ -1099,7 +1099,7 @@ fn location_links_to_proto(
links: Vec<LocationLink>,
lsp_store: &mut LspStore,
peer_id: PeerId,
cx: &mut AppContext,
cx: &mut App,
) -> Vec<proto::LocationLink> {
links
.into_iter()
@ -1169,7 +1169,7 @@ impl LspCommand for GetReferences {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::ReferenceParams> {
Ok(lsp::ReferenceParams {
text_document_position: make_lsp_text_document_position(path, self.position)?,
@ -1184,8 +1184,8 @@ impl LspCommand for GetReferences {
async fn response_from_lsp(
self,
locations: Option<Vec<lsp::Location>>,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
mut cx: AsyncAppContext,
) -> Result<Vec<Location>> {
@ -1238,8 +1238,8 @@ impl LspCommand for GetReferences {
async fn from_proto(
message: proto::GetReferences,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -1261,7 +1261,7 @@ impl LspCommand for GetReferences {
lsp_store: &mut LspStore,
peer_id: PeerId,
_: &clock::Global,
cx: &mut AppContext,
cx: &mut App,
) -> proto::GetReferencesResponse {
let locations = response
.into_iter()
@ -1286,8 +1286,8 @@ impl LspCommand for GetReferences {
async fn response_from_proto(
self,
message: proto::GetReferencesResponse,
project: Model<LspStore>,
_: Model<Buffer>,
project: Entity<LspStore>,
_: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Vec<Location>> {
let mut locations = Vec::new();
@ -1344,7 +1344,7 @@ impl LspCommand for GetDocumentHighlights {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::DocumentHighlightParams> {
Ok(lsp::DocumentHighlightParams {
text_document_position_params: make_lsp_text_document_position(path, self.position)?,
@ -1356,8 +1356,8 @@ impl LspCommand for GetDocumentHighlights {
async fn response_from_lsp(
self,
lsp_highlights: Option<Vec<lsp::DocumentHighlight>>,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
_: LanguageServerId,
mut cx: AsyncAppContext,
) -> Result<Vec<DocumentHighlight>> {
@ -1395,8 +1395,8 @@ impl LspCommand for GetDocumentHighlights {
async fn from_proto(
message: proto::GetDocumentHighlights,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -1418,7 +1418,7 @@ impl LspCommand for GetDocumentHighlights {
_: &mut LspStore,
_: PeerId,
_: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::GetDocumentHighlightsResponse {
let highlights = response
.into_iter()
@ -1439,8 +1439,8 @@ impl LspCommand for GetDocumentHighlights {
async fn response_from_proto(
self,
message: proto::GetDocumentHighlightsResponse,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Vec<DocumentHighlight>> {
let mut highlights = Vec::new();
@ -1497,7 +1497,7 @@ impl LspCommand for GetSignatureHelp {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_cx: &AppContext,
_cx: &App,
) -> Result<lsp::SignatureHelpParams> {
Ok(lsp::SignatureHelpParams {
text_document_position_params: make_lsp_text_document_position(path, self.position)?,
@ -1509,8 +1509,8 @@ impl LspCommand for GetSignatureHelp {
async fn response_from_lsp(
self,
message: Option<lsp::SignatureHelp>,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
_: LanguageServerId,
mut cx: AsyncAppContext,
) -> Result<Self::Response> {
@ -1530,8 +1530,8 @@ impl LspCommand for GetSignatureHelp {
async fn from_proto(
payload: Self::ProtoRequest,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
buffer
@ -1555,7 +1555,7 @@ impl LspCommand for GetSignatureHelp {
_: &mut LspStore,
_: PeerId,
_: &Global,
_: &mut AppContext,
_: &mut App,
) -> proto::GetSignatureHelpResponse {
proto::GetSignatureHelpResponse {
signature_help: response
@ -1566,8 +1566,8 @@ impl LspCommand for GetSignatureHelp {
async fn response_from_proto(
self,
response: proto::GetSignatureHelpResponse,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self::Response> {
let language = buffer.update(&mut cx, |buffer, _| buffer.language().cloned())?;
@ -1605,7 +1605,7 @@ impl LspCommand for GetHover {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::HoverParams> {
Ok(lsp::HoverParams {
text_document_position_params: make_lsp_text_document_position(path, self.position)?,
@ -1616,8 +1616,8 @@ impl LspCommand for GetHover {
async fn response_from_lsp(
self,
message: Option<lsp::Hover>,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
_: LanguageServerId,
mut cx: AsyncAppContext,
) -> Result<Self::Response> {
@ -1697,8 +1697,8 @@ impl LspCommand for GetHover {
async fn from_proto(
message: Self::ProtoRequest,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -1720,7 +1720,7 @@ impl LspCommand for GetHover {
_: &mut LspStore,
_: PeerId,
_: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::GetHoverResponse {
if let Some(response) = response {
let (start, end) = if let Some(range) = response.range {
@ -1763,8 +1763,8 @@ impl LspCommand for GetHover {
async fn response_from_proto(
self,
message: proto::GetHoverResponse,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self::Response> {
let contents: Vec<_> = message
@ -1827,7 +1827,7 @@ impl LspCommand for GetCompletions {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::CompletionParams> {
Ok(lsp::CompletionParams {
text_document_position: make_lsp_text_document_position(path, self.position)?,
@ -1840,8 +1840,8 @@ impl LspCommand for GetCompletions {
async fn response_from_lsp(
self,
completions: Option<lsp::CompletionResponse>,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
mut cx: AsyncAppContext,
) -> Result<Self::Response> {
@ -2033,8 +2033,8 @@ impl LspCommand for GetCompletions {
async fn from_proto(
message: proto::GetCompletions,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let version = deserialize_version(&message.version);
@ -2064,7 +2064,7 @@ impl LspCommand for GetCompletions {
_: &mut LspStore,
_: PeerId,
buffer_version: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::GetCompletionsResponse {
proto::GetCompletionsResponse {
completions: completions
@ -2078,8 +2078,8 @@ impl LspCommand for GetCompletions {
async fn response_from_proto(
self,
message: proto::GetCompletionsResponse,
_project: Model<LspStore>,
buffer: Model<Buffer>,
_project: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self::Response> {
buffer
@ -2175,7 +2175,7 @@ impl LspCommand for GetCodeActions {
path: &Path,
buffer: &Buffer,
language_server: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::CodeActionParams> {
let mut relevant_diagnostics = Vec::new();
for entry in buffer
@ -2221,8 +2221,8 @@ impl LspCommand for GetCodeActions {
async fn response_from_lsp(
self,
actions: Option<lsp::CodeActionResponse>,
_: Model<LspStore>,
_: Model<Buffer>,
_: Entity<LspStore>,
_: Entity<Buffer>,
server_id: LanguageServerId,
_: AsyncAppContext,
) -> Result<Vec<CodeAction>> {
@ -2269,8 +2269,8 @@ impl LspCommand for GetCodeActions {
async fn from_proto(
message: proto::GetCodeActions,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let start = message
@ -2298,7 +2298,7 @@ impl LspCommand for GetCodeActions {
_: &mut LspStore,
_: PeerId,
buffer_version: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::GetCodeActionsResponse {
proto::GetCodeActionsResponse {
actions: code_actions
@ -2312,8 +2312,8 @@ impl LspCommand for GetCodeActions {
async fn response_from_proto(
self,
message: proto::GetCodeActionsResponse,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Vec<CodeAction>> {
buffer
@ -2390,7 +2390,7 @@ impl LspCommand for OnTypeFormatting {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::DocumentOnTypeFormattingParams> {
Ok(lsp::DocumentOnTypeFormattingParams {
text_document_position: make_lsp_text_document_position(path, self.position)?,
@ -2402,8 +2402,8 @@ impl LspCommand for OnTypeFormatting {
async fn response_from_lsp(
self,
message: Option<Vec<lsp::TextEdit>>,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
mut cx: AsyncAppContext,
) -> Result<Option<Transaction>> {
@ -2439,8 +2439,8 @@ impl LspCommand for OnTypeFormatting {
async fn from_proto(
message: proto::OnTypeFormatting,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -2472,7 +2472,7 @@ impl LspCommand for OnTypeFormatting {
_: &mut LspStore,
_: PeerId,
_: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::OnTypeFormattingResponse {
proto::OnTypeFormattingResponse {
transaction: response
@ -2483,8 +2483,8 @@ impl LspCommand for OnTypeFormatting {
async fn response_from_proto(
self,
message: proto::OnTypeFormattingResponse,
_: Model<LspStore>,
_: Model<Buffer>,
_: Entity<LspStore>,
_: Entity<Buffer>,
_: AsyncAppContext,
) -> Result<Option<Transaction>> {
let Some(transaction) = message.transaction else {
@ -2501,7 +2501,7 @@ impl LspCommand for OnTypeFormatting {
impl InlayHints {
pub async fn lsp_to_project_hint(
lsp_hint: lsp::InlayHint,
buffer_handle: &Model<Buffer>,
buffer_handle: &Entity<Buffer>,
server_id: LanguageServerId,
resolve_state: ResolveState,
force_no_type_left_padding: bool,
@ -2897,7 +2897,7 @@ impl LspCommand for InlayHints {
path: &Path,
buffer: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::InlayHintParams> {
Ok(lsp::InlayHintParams {
text_document: lsp::TextDocumentIdentifier {
@ -2911,8 +2911,8 @@ impl LspCommand for InlayHints {
async fn response_from_lsp(
self,
message: Option<Vec<lsp::InlayHint>>,
lsp_store: Model<LspStore>,
buffer: Model<Buffer>,
lsp_store: Entity<LspStore>,
buffer: Entity<Buffer>,
server_id: LanguageServerId,
mut cx: AsyncAppContext,
) -> anyhow::Result<Vec<InlayHint>> {
@ -2967,8 +2967,8 @@ impl LspCommand for InlayHints {
async fn from_proto(
message: proto::InlayHints,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let start = message
@ -2993,7 +2993,7 @@ impl LspCommand for InlayHints {
_: &mut LspStore,
_: PeerId,
buffer_version: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::InlayHintsResponse {
proto::InlayHintsResponse {
hints: response
@ -3007,8 +3007,8 @@ impl LspCommand for InlayHints {
async fn response_from_proto(
self,
message: proto::InlayHintsResponse,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> anyhow::Result<Vec<InlayHint>> {
buffer
@ -3058,7 +3058,7 @@ impl LspCommand for LinkedEditingRange {
path: &Path,
buffer: &Buffer,
_server: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<lsp::LinkedEditingRangeParams> {
let position = self.position.to_point_utf16(&buffer.snapshot());
Ok(lsp::LinkedEditingRangeParams {
@ -3070,8 +3070,8 @@ impl LspCommand for LinkedEditingRange {
async fn response_from_lsp(
self,
message: Option<lsp::LinkedEditingRanges>,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
_server_id: LanguageServerId,
cx: AsyncAppContext,
) -> Result<Vec<Range<Anchor>>> {
@ -3105,8 +3105,8 @@ impl LspCommand for LinkedEditingRange {
async fn from_proto(
message: proto::LinkedEditingRange,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Self> {
let position = message
@ -3129,7 +3129,7 @@ impl LspCommand for LinkedEditingRange {
_: &mut LspStore,
_: PeerId,
buffer_version: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::LinkedEditingRangeResponse {
proto::LinkedEditingRangeResponse {
items: response
@ -3146,8 +3146,8 @@ impl LspCommand for LinkedEditingRange {
async fn response_from_proto(
self,
message: proto::LinkedEditingRangeResponse,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> Result<Vec<Range<Anchor>>> {
buffer

View file

@ -1,7 +1,7 @@
use crate::{lsp_command::LspCommand, lsp_store::LspStore, make_text_document_identifier};
use anyhow::{Context, Result};
use anyhow::{Context as _, Result};
use async_trait::async_trait;
use gpui::{AppContext, AsyncAppContext, Model};
use gpui::{App, AsyncAppContext, Entity};
use language::{point_to_lsp, proto::deserialize_anchor, Buffer};
use lsp::{LanguageServer, LanguageServerId};
use rpc::proto::{self, PeerId};
@ -56,7 +56,7 @@ impl LspCommand for ExpandMacro {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<ExpandMacroParams> {
Ok(ExpandMacroParams {
text_document: make_text_document_identifier(path)?,
@ -67,8 +67,8 @@ impl LspCommand for ExpandMacro {
async fn response_from_lsp(
self,
message: Option<ExpandedMacro>,
_: Model<LspStore>,
_: Model<Buffer>,
_: Entity<LspStore>,
_: Entity<Buffer>,
_: LanguageServerId,
_: AsyncAppContext,
) -> anyhow::Result<ExpandedMacro> {
@ -92,8 +92,8 @@ impl LspCommand for ExpandMacro {
async fn from_proto(
message: Self::ProtoRequest,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> anyhow::Result<Self> {
let position = message
@ -110,7 +110,7 @@ impl LspCommand for ExpandMacro {
_: &mut LspStore,
_: PeerId,
_: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::LspExtExpandMacroResponse {
proto::LspExtExpandMacroResponse {
name: response.name,
@ -121,8 +121,8 @@ impl LspCommand for ExpandMacro {
async fn response_from_proto(
self,
message: proto::LspExtExpandMacroResponse,
_: Model<LspStore>,
_: Model<Buffer>,
_: Entity<LspStore>,
_: Entity<Buffer>,
_: AsyncAppContext,
) -> anyhow::Result<ExpandedMacro> {
Ok(ExpandedMacro {
@ -184,7 +184,7 @@ impl LspCommand for OpenDocs {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<OpenDocsParams> {
Ok(OpenDocsParams {
text_document: lsp::TextDocumentIdentifier {
@ -197,8 +197,8 @@ impl LspCommand for OpenDocs {
async fn response_from_lsp(
self,
message: Option<DocsUrls>,
_: Model<LspStore>,
_: Model<Buffer>,
_: Entity<LspStore>,
_: Entity<Buffer>,
_: LanguageServerId,
_: AsyncAppContext,
) -> anyhow::Result<DocsUrls> {
@ -222,8 +222,8 @@ impl LspCommand for OpenDocs {
async fn from_proto(
message: Self::ProtoRequest,
_: Model<LspStore>,
buffer: Model<Buffer>,
_: Entity<LspStore>,
buffer: Entity<Buffer>,
mut cx: AsyncAppContext,
) -> anyhow::Result<Self> {
let position = message
@ -240,7 +240,7 @@ impl LspCommand for OpenDocs {
_: &mut LspStore,
_: PeerId,
_: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::LspExtOpenDocsResponse {
proto::LspExtOpenDocsResponse {
web: response.web,
@ -251,8 +251,8 @@ impl LspCommand for OpenDocs {
async fn response_from_proto(
self,
message: proto::LspExtOpenDocsResponse,
_: Model<LspStore>,
_: Model<Buffer>,
_: Entity<LspStore>,
_: Entity<Buffer>,
_: AsyncAppContext,
) -> anyhow::Result<DocsUrls> {
Ok(DocsUrls {
@ -301,7 +301,7 @@ impl LspCommand for SwitchSourceHeader {
path: &Path,
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
_: &App,
) -> Result<SwitchSourceHeaderParams> {
Ok(SwitchSourceHeaderParams(make_text_document_identifier(
path,
@ -311,8 +311,8 @@ impl LspCommand for SwitchSourceHeader {
async fn response_from_lsp(
self,
message: Option<SwitchSourceHeaderResult>,
_: Model<LspStore>,
_: Model<Buffer>,
_: Entity<LspStore>,
_: Entity<Buffer>,
_: LanguageServerId,
_: AsyncAppContext,
) -> anyhow::Result<SwitchSourceHeaderResult> {
@ -330,8 +330,8 @@ impl LspCommand for SwitchSourceHeader {
async fn from_proto(
_: Self::ProtoRequest,
_: Model<LspStore>,
_: Model<Buffer>,
_: Entity<LspStore>,
_: Entity<Buffer>,
_: AsyncAppContext,
) -> anyhow::Result<Self> {
Ok(Self {})
@ -342,7 +342,7 @@ impl LspCommand for SwitchSourceHeader {
_: &mut LspStore,
_: PeerId,
_: &clock::Global,
_: &mut AppContext,
_: &mut App,
) -> proto::LspExtSwitchSourceHeaderResponse {
proto::LspExtSwitchSourceHeaderResponse {
target_file: response.0,
@ -352,8 +352,8 @@ impl LspCommand for SwitchSourceHeader {
async fn response_from_proto(
self,
message: proto::LspExtSwitchSourceHeaderResponse,
_: Model<LspStore>,
_: Model<Buffer>,
_: Entity<LspStore>,
_: Entity<Buffer>,
_: AsyncAppContext,
) -> anyhow::Result<SwitchSourceHeaderResult> {
Ok(SwitchSourceHeaderResult(message.target_file))

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@ use std::{
sync::Arc,
};
use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, Context as _, Result};
use collections::{HashMap, HashSet};
use fs::Fs;
use futures::{
@ -12,7 +12,7 @@ use futures::{
stream::FuturesUnordered,
FutureExt,
};
use gpui::{AsyncAppContext, EventEmitter, Model, ModelContext, Task, WeakModel};
use gpui::{AsyncAppContext, Context, Entity, EventEmitter, Task, WeakEntity};
use language::{
language_settings::{Formatter, LanguageSettings, SelectedFormatter},
Buffer, LanguageRegistry, LocalFile,
@ -33,7 +33,7 @@ pub struct PrettierStore {
node: NodeRuntime,
fs: Arc<dyn Fs>,
languages: Arc<LanguageRegistry>,
worktree_store: Model<WorktreeStore>,
worktree_store: Entity<WorktreeStore>,
default_prettier: DefaultPrettier,
prettiers_per_worktree: HashMap<WorktreeId, HashSet<Option<PathBuf>>>,
prettier_ignores_per_worktree: HashMap<WorktreeId, HashSet<PathBuf>>,
@ -56,8 +56,8 @@ impl PrettierStore {
node: NodeRuntime,
fs: Arc<dyn Fs>,
languages: Arc<LanguageRegistry>,
worktree_store: Model<WorktreeStore>,
_: &mut ModelContext<Self>,
worktree_store: Entity<WorktreeStore>,
_: &mut Context<Self>,
) -> Self {
Self {
node,
@ -71,7 +71,7 @@ impl PrettierStore {
}
}
pub fn remove_worktree(&mut self, id_to_remove: WorktreeId, cx: &mut ModelContext<Self>) {
pub fn remove_worktree(&mut self, id_to_remove: WorktreeId, cx: &mut Context<Self>) {
self.prettier_ignores_per_worktree.remove(&id_to_remove);
let mut prettier_instances_to_clean = FuturesUnordered::new();
if let Some(prettier_paths) = self.prettiers_per_worktree.remove(&id_to_remove) {
@ -104,8 +104,8 @@ impl PrettierStore {
fn prettier_instance_for_buffer(
&mut self,
buffer: &Model<Buffer>,
cx: &mut ModelContext<Self>,
buffer: &Entity<Buffer>,
cx: &mut Context<Self>,
) -> Task<Option<(Option<PathBuf>, PrettierTask)>> {
let buffer = buffer.read(cx);
let buffer_file = buffer.file();
@ -216,8 +216,8 @@ impl PrettierStore {
fn prettier_ignore_for_buffer(
&mut self,
buffer: &Model<Buffer>,
cx: &mut ModelContext<Self>,
buffer: &Entity<Buffer>,
cx: &mut Context<Self>,
) -> Task<Option<PathBuf>> {
let buffer = buffer.read(cx);
let buffer_file = buffer.file();
@ -277,7 +277,7 @@ impl PrettierStore {
node: NodeRuntime,
prettier_dir: PathBuf,
worktree_id: Option<WorktreeId>,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> PrettierTask {
cx.spawn(|prettier_store, mut cx| async move {
log::info!("Starting prettier at path {prettier_dir:?}");
@ -305,7 +305,7 @@ impl PrettierStore {
fn start_default_prettier(
node: NodeRuntime,
worktree_id: Option<WorktreeId>,
cx: &mut ModelContext<PrettierStore>,
cx: &mut Context<PrettierStore>,
) -> Task<anyhow::Result<PrettierTask>> {
cx.spawn(|prettier_store, mut cx| async move {
let installation_task = prettier_store.update(&mut cx, |prettier_store, _| {
@ -383,7 +383,7 @@ impl PrettierStore {
}
fn register_new_prettier(
prettier_store: &WeakModel<Self>,
prettier_store: &WeakEntity<Self>,
prettier: &Prettier,
worktree_id: Option<WorktreeId>,
new_server_id: LanguageServerId,
@ -442,9 +442,9 @@ impl PrettierStore {
pub fn update_prettier_settings(
&self,
worktree: &Model<Worktree>,
worktree: &Entity<Worktree>,
changes: &[(Arc<Path>, ProjectEntryId, PathChange)],
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
let prettier_config_files = Prettier::CONFIG_FILE_NAMES
.iter()
@ -516,7 +516,7 @@ impl PrettierStore {
&mut self,
worktree: Option<WorktreeId>,
plugins: impl Iterator<Item = Arc<str>>,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
if cfg!(any(test, feature = "test-support")) {
self.default_prettier.installed_plugins.extend(plugins);
@ -668,7 +668,7 @@ impl PrettierStore {
pub fn on_settings_changed(
&mut self,
language_formatters_to_check: Vec<(Option<WorktreeId>, LanguageSettings)>,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
let mut prettier_plugins_by_worktree = HashMap::default();
for (worktree, language_settings) in language_formatters_to_check {
@ -705,8 +705,8 @@ pub fn prettier_plugins_for_language(
}
pub(super) async fn format_with_prettier(
prettier_store: &WeakModel<PrettierStore>,
buffer: &Model<Buffer>,
prettier_store: &WeakEntity<PrettierStore>,
buffer: &Entity<Buffer>,
cx: &mut AsyncAppContext,
) -> Option<Result<crate::lsp_store::FormatOperation>> {
let prettier_instance = prettier_store
@ -822,7 +822,7 @@ impl DefaultPrettier {
&mut self,
node: &NodeRuntime,
worktree_id: Option<WorktreeId>,
cx: &mut ModelContext<PrettierStore>,
cx: &mut Context<PrettierStore>,
) -> Option<Task<anyhow::Result<PrettierTask>>> {
match &mut self.prettier {
PrettierInstallation::NotInstalled { .. } => Some(
@ -841,7 +841,7 @@ impl PrettierInstance {
node: &NodeRuntime,
prettier_dir: Option<&Path>,
worktree_id: Option<WorktreeId>,
cx: &mut ModelContext<PrettierStore>,
cx: &mut Context<PrettierStore>,
) -> Option<Task<anyhow::Result<PrettierTask>>> {
if self.attempt > prettier::FAIL_THRESHOLD {
match prettier_dir {

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
use anyhow::Context;
use anyhow::Context as _;
use collections::HashMap;
use fs::Fs;
use gpui::{AppContext, AsyncAppContext, BorrowAppContext, EventEmitter, Model, ModelContext};
use gpui::{App, AsyncAppContext, BorrowAppContext, Context, Entity, EventEmitter};
use lsp::LanguageServerName;
use paths::{
local_settings_file_relative_path, local_tasks_file_relative_path,
@ -208,10 +208,7 @@ impl Settings for ProjectSettings {
type FileContent = Self;
fn load(
sources: SettingsSources<Self::FileContent>,
_: &mut AppContext,
) -> anyhow::Result<Self> {
fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> anyhow::Result<Self> {
sources.json_merge()
}
}
@ -231,9 +228,9 @@ impl EventEmitter<SettingsObserverEvent> for SettingsObserver {}
pub struct SettingsObserver {
mode: SettingsObserverMode,
downstream_client: Option<AnyProtoClient>,
worktree_store: Model<WorktreeStore>,
worktree_store: Entity<WorktreeStore>,
project_id: u64,
task_store: Model<TaskStore>,
task_store: Entity<TaskStore>,
}
/// SettingsObserver observers changes to .zed/{settings, task}.json files in local worktrees
@ -248,9 +245,9 @@ impl SettingsObserver {
pub fn new_local(
fs: Arc<dyn Fs>,
worktree_store: Model<WorktreeStore>,
task_store: Model<TaskStore>,
cx: &mut ModelContext<Self>,
worktree_store: Entity<WorktreeStore>,
task_store: Entity<TaskStore>,
cx: &mut Context<Self>,
) -> Self {
cx.subscribe(&worktree_store, Self::on_worktree_store_event)
.detach();
@ -265,9 +262,9 @@ impl SettingsObserver {
}
pub fn new_remote(
worktree_store: Model<WorktreeStore>,
task_store: Model<TaskStore>,
_: &mut ModelContext<Self>,
worktree_store: Entity<WorktreeStore>,
task_store: Entity<TaskStore>,
_: &mut Context<Self>,
) -> Self {
Self {
worktree_store,
@ -282,7 +279,7 @@ impl SettingsObserver {
&mut self,
project_id: u64,
downstream_client: AnyProtoClient,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
self.project_id = project_id;
self.downstream_client = Some(downstream_client.clone());
@ -319,12 +316,12 @@ impl SettingsObserver {
}
}
pub fn unshared(&mut self, _: &mut ModelContext<Self>) {
pub fn unshared(&mut self, _: &mut Context<Self>) {
self.downstream_client = None;
}
async fn handle_update_worktree_settings(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::UpdateWorktreeSettings>,
mut cx: AsyncAppContext,
) -> anyhow::Result<()> {
@ -358,9 +355,9 @@ impl SettingsObserver {
fn on_worktree_store_event(
&mut self,
_: Model<WorktreeStore>,
_: Entity<WorktreeStore>,
event: &WorktreeStoreEvent,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
if let WorktreeStoreEvent::WorktreeAdded(worktree) = event {
cx.subscribe(worktree, |this, worktree, event, cx| {
@ -374,9 +371,9 @@ impl SettingsObserver {
fn update_local_worktree_settings(
&mut self,
worktree: &Model<Worktree>,
worktree: &Entity<Worktree>,
changes: &UpdatedEntriesSet,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
let SettingsObserverMode::Local(fs) = &self.mode else {
return;
@ -496,9 +493,9 @@ impl SettingsObserver {
fn update_settings(
&mut self,
worktree: Model<Worktree>,
worktree: Entity<Worktree>,
settings_contents: impl IntoIterator<Item = (Arc<Path>, LocalSettingsKind, Option<String>)>,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
let worktree_id = worktree.read(cx).id();
let remote_worktree_id = worktree.read(cx).id();

View file

@ -2,7 +2,7 @@ use crate::{Event, *};
use ::git::diff::assert_hunks;
use fs::FakeFs;
use futures::{future, StreamExt};
use gpui::{AppContext, SemanticVersion, UpdateGlobal};
use gpui::{App, SemanticVersion, UpdateGlobal};
use http_client::Url;
use language::{
language_settings::{language_settings, AllLanguageSettings, LanguageSettingsContent},
@ -2643,10 +2643,7 @@ async fn test_definition(cx: &mut gpui::TestAppContext) {
assert_eq!(list_worktrees(&project, cx), [("/dir/b.rs".as_ref(), true)]);
});
fn list_worktrees<'a>(
project: &'a Model<Project>,
cx: &'a AppContext,
) -> Vec<(&'a Path, bool)> {
fn list_worktrees<'a>(project: &'a Entity<Project>, cx: &'a App) -> Vec<(&'a Path, bool)> {
project
.read(cx)
.worktrees(cx)
@ -5688,7 +5685,7 @@ async fn test_unstaged_changes_for_buffer(cx: &mut gpui::TestAppContext) {
}
async fn search(
project: &Model<Project>,
project: &Entity<Project>,
query: SearchQuery,
cx: &mut gpui::TestAppContext,
) -> Result<HashMap<String, Vec<Range<usize>>>> {
@ -5807,10 +5804,10 @@ fn tsx_lang() -> Arc<Language> {
}
fn get_all_tasks(
project: &Model<Project>,
project: &Entity<Project>,
worktree_id: Option<WorktreeId>,
task_context: &TaskContext,
cx: &mut AppContext,
cx: &mut App,
) -> Vec<(TaskSourceKind, ResolvedTask)> {
let (mut old, new) = project.update(cx, |project, cx| {
project

View file

@ -2,7 +2,7 @@ use aho_corasick::{AhoCorasick, AhoCorasickBuilder};
use anyhow::Result;
use client::proto;
use fancy_regex::{Captures, Regex, RegexBuilder};
use gpui::Model;
use gpui::Entity;
use language::{Buffer, BufferSnapshot, CharKind};
use smol::future::yield_now;
use std::{
@ -17,7 +17,7 @@ use util::paths::PathMatcher;
pub enum SearchResult {
Buffer {
buffer: Model<Buffer>,
buffer: Entity<Buffer>,
ranges: Vec<Range<Anchor>>,
},
LimitReached,
@ -35,7 +35,7 @@ pub struct SearchInputs {
query: Arc<str>,
files_to_include: PathMatcher,
files_to_exclude: PathMatcher,
buffers: Option<Vec<Model<Buffer>>>,
buffers: Option<Vec<Entity<Buffer>>>,
}
impl SearchInputs {
@ -48,7 +48,7 @@ impl SearchInputs {
pub fn files_to_exclude(&self) -> &PathMatcher {
&self.files_to_exclude
}
pub fn buffers(&self) -> &Option<Vec<Model<Buffer>>> {
pub fn buffers(&self) -> &Option<Vec<Entity<Buffer>>> {
&self.buffers
}
}
@ -88,7 +88,7 @@ impl SearchQuery {
include_ignored: bool,
files_to_include: PathMatcher,
files_to_exclude: PathMatcher,
buffers: Option<Vec<Model<Buffer>>>,
buffers: Option<Vec<Entity<Buffer>>>,
) -> Result<Self> {
let query = query.to_string();
let search = AhoCorasickBuilder::new()
@ -117,7 +117,7 @@ impl SearchQuery {
include_ignored: bool,
files_to_include: PathMatcher,
files_to_exclude: PathMatcher,
buffers: Option<Vec<Model<Buffer>>>,
buffers: Option<Vec<Entity<Buffer>>>,
) -> Result<Self> {
let mut query = query.to_string();
let initial_query = Arc::from(query.as_str());
@ -426,7 +426,7 @@ impl SearchQuery {
self.as_inner().files_to_exclude()
}
pub fn buffers(&self) -> Option<&Vec<Model<Buffer>>> {
pub fn buffers(&self) -> Option<&Vec<Entity<Buffer>>> {
self.as_inner().buffers.as_ref()
}

View file

@ -8,9 +8,9 @@ use std::{
sync::Arc,
};
use anyhow::{Context, Result};
use anyhow::{Context as _, Result};
use collections::{HashMap, HashSet, VecDeque};
use gpui::{AppContext, Context as _, Model, Task};
use gpui::{App, AppContext as _, Entity, Task};
use itertools::Itertools;
use language::{ContextProvider, File, Language, LanguageToolchainStore, Location};
use settings::{parse_json_with_comments, SettingsLocation};
@ -76,8 +76,8 @@ impl TaskSourceKind {
}
impl Inventory {
pub fn new(cx: &mut AppContext) -> Model<Self> {
cx.new_model(|_| Self::default())
pub fn new(cx: &mut App) -> Entity<Self> {
cx.new(|_| Self::default())
}
/// Pulls its task sources relevant to the worktree and the language given,
@ -88,7 +88,7 @@ impl Inventory {
file: Option<Arc<dyn File>>,
language: Option<Arc<Language>>,
worktree: Option<WorktreeId>,
cx: &AppContext,
cx: &App,
) -> Vec<(TaskSourceKind, TaskTemplate)> {
let task_source_kind = language.as_ref().map(|language| TaskSourceKind::Language {
name: language.name().0,
@ -115,7 +115,7 @@ impl Inventory {
worktree: Option<WorktreeId>,
location: Option<Location>,
task_context: &TaskContext,
cx: &AppContext,
cx: &App,
) -> (
Vec<(TaskSourceKind, ResolvedTask)>,
Vec<(TaskSourceKind, ResolvedTask)>,
@ -371,7 +371,7 @@ fn task_variables_preference(task: &ResolvedTask) -> Reverse<usize> {
#[cfg(test)]
mod test_inventory {
use gpui::{Model, TestAppContext};
use gpui::{Entity, TestAppContext};
use itertools::Itertools;
use task::TaskContext;
use worktree::WorktreeId;
@ -381,7 +381,7 @@ mod test_inventory {
use super::TaskSourceKind;
pub(super) fn task_template_names(
inventory: &Model<Inventory>,
inventory: &Entity<Inventory>,
worktree: Option<WorktreeId>,
cx: &mut TestAppContext,
) -> Vec<String> {
@ -396,7 +396,7 @@ mod test_inventory {
}
pub(super) fn register_task_used(
inventory: &Model<Inventory>,
inventory: &Entity<Inventory>,
task_name: &str,
cx: &mut TestAppContext,
) {
@ -416,7 +416,7 @@ mod test_inventory {
}
pub(super) async fn list_tasks(
inventory: &Model<Inventory>,
inventory: &Entity<Inventory>,
worktree: Option<WorktreeId>,
cx: &mut TestAppContext,
) -> Vec<(TaskSourceKind, String)> {
@ -438,11 +438,11 @@ mod test_inventory {
/// A context provided that tries to provide values for all non-custom [`VariableName`] variants for a currently opened file.
/// Applied as a base for every custom [`ContextProvider`] unless explicitly oped out.
pub struct BasicContextProvider {
worktree_store: Model<WorktreeStore>,
worktree_store: Entity<WorktreeStore>,
}
impl BasicContextProvider {
pub fn new(worktree_store: Model<WorktreeStore>) -> Self {
pub fn new(worktree_store: Entity<WorktreeStore>) -> Self {
Self { worktree_store }
}
}
@ -453,7 +453,7 @@ impl ContextProvider for BasicContextProvider {
location: &Location,
_: Option<HashMap<String, String>>,
_: Arc<dyn LanguageToolchainStore>,
cx: &mut AppContext,
cx: &mut App,
) -> Task<Result<TaskVariables>> {
let buffer = location.buffer.read(cx);
let buffer_snapshot = buffer.snapshot();
@ -553,7 +553,7 @@ impl ContextProvider for ContextProviderWithTasks {
fn associated_tasks(
&self,
_: Option<Arc<dyn language::File>>,
_: &AppContext,
_: &App,
) -> Option<TaskTemplates> {
Some(self.templates.clone())
}
@ -859,7 +859,7 @@ mod tests {
}
async fn resolved_task_names(
inventory: &Model<Inventory>,
inventory: &Entity<Inventory>,
worktree: Option<WorktreeId>,
cx: &mut TestAppContext,
) -> Vec<String> {
@ -888,7 +888,7 @@ mod tests {
}
async fn list_tasks_sorted_by_last_used(
inventory: &Model<Inventory>,
inventory: &Entity<Inventory>,
worktree: Option<WorktreeId>,
cx: &mut TestAppContext,
) -> Vec<(TaskSourceKind, String)> {

View file

@ -4,7 +4,7 @@ use anyhow::Context as _;
use collections::HashMap;
use fs::Fs;
use futures::StreamExt as _;
use gpui::{AppContext, AsyncAppContext, EventEmitter, Model, ModelContext, Task, WeakModel};
use gpui::{App, AsyncAppContext, Context, Entity, EventEmitter, Task, WeakEntity};
use language::{
proto::{deserialize_anchor, serialize_anchor},
ContextProvider as _, LanguageToolchainStore, Location,
@ -28,9 +28,9 @@ pub enum TaskStore {
pub struct StoreState {
mode: StoreMode,
task_inventory: Model<Inventory>,
buffer_store: WeakModel<BufferStore>,
worktree_store: Model<WorktreeStore>,
task_inventory: Entity<Inventory>,
buffer_store: WeakEntity<BufferStore>,
worktree_store: Entity<WorktreeStore>,
toolchain_store: Arc<dyn LanguageToolchainStore>,
_global_task_config_watcher: Task<()>,
}
@ -38,7 +38,7 @@ pub struct StoreState {
enum StoreMode {
Local {
downstream_client: Option<(AnyProtoClient, u64)>,
environment: Model<ProjectEnvironment>,
environment: Entity<ProjectEnvironment>,
},
Remote {
upstream_client: AnyProtoClient,
@ -56,7 +56,7 @@ impl TaskStore {
}
async fn handle_task_context_for_location(
store: Model<Self>,
store: Entity<Self>,
envelope: TypedEnvelope<proto::TaskContextForLocation>,
mut cx: AsyncAppContext,
) -> anyhow::Result<proto::TaskContext> {
@ -153,11 +153,11 @@ impl TaskStore {
pub fn local(
fs: Arc<dyn Fs>,
buffer_store: WeakModel<BufferStore>,
worktree_store: Model<WorktreeStore>,
buffer_store: WeakEntity<BufferStore>,
worktree_store: Entity<WorktreeStore>,
toolchain_store: Arc<dyn LanguageToolchainStore>,
environment: Model<ProjectEnvironment>,
cx: &mut ModelContext<'_, Self>,
environment: Entity<ProjectEnvironment>,
cx: &mut Context<'_, Self>,
) -> Self {
Self::Functional(StoreState {
mode: StoreMode::Local {
@ -174,12 +174,12 @@ impl TaskStore {
pub fn remote(
fs: Arc<dyn Fs>,
buffer_store: WeakModel<BufferStore>,
worktree_store: Model<WorktreeStore>,
buffer_store: WeakEntity<BufferStore>,
worktree_store: Entity<WorktreeStore>,
toolchain_store: Arc<dyn LanguageToolchainStore>,
upstream_client: AnyProtoClient,
project_id: u64,
cx: &mut ModelContext<'_, Self>,
cx: &mut Context<'_, Self>,
) -> Self {
Self::Functional(StoreState {
mode: StoreMode::Remote {
@ -198,7 +198,7 @@ impl TaskStore {
&self,
captured_variables: TaskVariables,
location: Location,
cx: &mut AppContext,
cx: &mut App,
) -> Task<Option<TaskContext>> {
match self {
TaskStore::Functional(state) => match &state.mode {
@ -227,19 +227,14 @@ impl TaskStore {
}
}
pub fn task_inventory(&self) -> Option<&Model<Inventory>> {
pub fn task_inventory(&self) -> Option<&Entity<Inventory>> {
match self {
TaskStore::Functional(state) => Some(&state.task_inventory),
TaskStore::Noop => None,
}
}
pub fn shared(
&mut self,
remote_id: u64,
new_downstream_client: AnyProtoClient,
_cx: &mut AppContext,
) {
pub fn shared(&mut self, remote_id: u64, new_downstream_client: AnyProtoClient, _cx: &mut App) {
if let Self::Functional(StoreState {
mode: StoreMode::Local {
downstream_client, ..
@ -251,7 +246,7 @@ impl TaskStore {
}
}
pub fn unshared(&mut self, _: &mut ModelContext<Self>) {
pub fn unshared(&mut self, _: &mut Context<Self>) {
if let Self::Functional(StoreState {
mode: StoreMode::Local {
downstream_client, ..
@ -267,7 +262,7 @@ impl TaskStore {
&self,
location: Option<SettingsLocation<'_>>,
raw_tasks_json: Option<&str>,
cx: &mut ModelContext<'_, Self>,
cx: &mut Context<'_, Self>,
) -> anyhow::Result<()> {
let task_inventory = match self {
TaskStore::Functional(state) => &state.task_inventory,
@ -284,7 +279,7 @@ impl TaskStore {
fn subscribe_to_global_task_file_changes(
fs: Arc<dyn Fs>,
cx: &mut ModelContext<'_, Self>,
cx: &mut Context<'_, Self>,
) -> Task<()> {
let mut user_tasks_file_rx =
watch_config_file(&cx.background_executor(), fs, paths::tasks_file().clone());
@ -309,7 +304,7 @@ impl TaskStore {
message: format!("Invalid global tasks file\n{err}"),
});
}
cx.refresh();
cx.refresh_windows();
}) else {
break; // App dropped
};
@ -319,12 +314,12 @@ impl TaskStore {
}
fn local_task_context_for_location(
worktree_store: Model<WorktreeStore>,
worktree_store: Entity<WorktreeStore>,
toolchain_store: Arc<dyn LanguageToolchainStore>,
environment: Model<ProjectEnvironment>,
environment: Entity<ProjectEnvironment>,
captured_variables: TaskVariables,
location: Location,
cx: &AppContext,
cx: &App,
) -> Task<Option<TaskContext>> {
let worktree_id = location.buffer.read(cx).file().map(|f| f.worktree_id(cx));
let worktree_abs_path = worktree_id
@ -368,11 +363,11 @@ fn local_task_context_for_location(
fn remote_task_context_for_location(
project_id: u64,
upstream_client: AnyProtoClient,
worktree_store: Model<WorktreeStore>,
worktree_store: Entity<WorktreeStore>,
captured_variables: TaskVariables,
location: Location,
toolchain_store: Arc<dyn LanguageToolchainStore>,
cx: &mut AppContext,
cx: &mut App,
) -> Task<Option<TaskContext>> {
cx.spawn(|cx| async move {
// We need to gather a client context, as the headless one may lack certain information (e.g. tree-sitter parsing is disabled there, so symbols are not available).
@ -434,7 +429,7 @@ fn combine_task_variables(
project_env: Option<HashMap<String, String>>,
baseline: BasicContextProvider,
toolchain_store: Arc<dyn LanguageToolchainStore>,
cx: &mut AppContext,
cx: &mut App,
) -> Task<anyhow::Result<TaskVariables>> {
let language_context_provider = location
.buffer

View file

@ -1,7 +1,7 @@
use crate::Project;
use anyhow::{Context as _, Result};
use collections::HashMap;
use gpui::{AnyWindowHandle, AppContext, Context, Entity, Model, ModelContext, Task, WeakModel};
use gpui::{AnyWindowHandle, App, AppContext as _, Context, Entity, Task, WeakEntity};
use itertools::Itertools;
use language::LanguageName;
use settings::{Settings, SettingsLocation};
@ -24,7 +24,7 @@ use util::ResultExt;
// use std::os::unix::ffi::OsStrExt;
pub struct Terminals {
pub(crate) local_handles: Vec<WeakModel<terminal::Terminal>>,
pub(crate) local_handles: Vec<WeakEntity<terminal::Terminal>>,
}
/// Terminals are opened either for the users shell, or to run a task.
@ -44,7 +44,7 @@ pub struct SshCommand {
}
impl Project {
pub fn active_project_directory(&self, cx: &AppContext) -> Option<Arc<Path>> {
pub fn active_project_directory(&self, cx: &App) -> Option<Arc<Path>> {
let worktree = self
.active_entry()
.and_then(|entry_id| self.worktree_for_entry(entry_id, cx))
@ -54,7 +54,7 @@ impl Project {
worktree
}
pub fn first_project_directory(&self, cx: &AppContext) -> Option<PathBuf> {
pub fn first_project_directory(&self, cx: &App) -> Option<PathBuf> {
let worktree = self.worktrees(cx).next()?;
let worktree = worktree.read(cx);
if worktree.root_entry()?.is_dir() {
@ -64,7 +64,7 @@ impl Project {
}
}
pub fn ssh_details(&self, cx: &AppContext) -> Option<(String, SshCommand)> {
pub fn ssh_details(&self, cx: &App) -> Option<(String, SshCommand)> {
if let Some(ssh_client) = &self.ssh_client {
let ssh_client = ssh_client.read(cx);
if let Some(args) = ssh_client.ssh_args() {
@ -82,8 +82,8 @@ impl Project {
&mut self,
kind: TerminalKind,
window: AnyWindowHandle,
cx: &mut ModelContext<Self>,
) -> Task<Result<Model<Terminal>>> {
cx: &mut Context<Self>,
) -> Task<Result<Entity<Terminal>>> {
let path: Option<Arc<Path>> = match &kind {
TerminalKind::Shell(path) => path.as_ref().map(|path| Arc::from(path.as_ref())),
TerminalKind::Task(spawn_task) => {
@ -125,7 +125,7 @@ impl Project {
pub fn terminal_settings<'a>(
&'a self,
path: &'a Option<PathBuf>,
cx: &'a AppContext,
cx: &'a App,
) -> &'a TerminalSettings {
let mut settings_location = None;
if let Some(path) = path.as_ref() {
@ -139,7 +139,7 @@ impl Project {
TerminalSettings::get(settings_location, cx)
}
pub fn exec_in_shell(&self, command: String, cx: &AppContext) -> std::process::Command {
pub fn exec_in_shell(&self, command: String, cx: &App) -> std::process::Command {
let path = self.first_project_directory(cx);
let ssh_details = self.ssh_details(cx);
let settings = self.terminal_settings(&path, cx).clone();
@ -184,8 +184,8 @@ impl Project {
kind: TerminalKind,
python_venv_directory: Option<PathBuf>,
window: AnyWindowHandle,
cx: &mut ModelContext<Self>,
) -> Result<Model<Terminal>> {
cx: &mut Context<Self>,
) -> Result<Entity<Terminal>> {
let this = &mut *self;
let path: Option<Arc<Path>> = match &kind {
TerminalKind::Shell(path) => path.as_ref().map(|path| Arc::from(path.as_ref())),
@ -339,7 +339,7 @@ impl Project {
cx,
)
.map(|builder| {
let terminal_handle = cx.new_model(|cx| builder.subscribe(cx));
let terminal_handle = cx.new(|cx| builder.subscribe(cx));
this.terminals
.local_handles
@ -370,7 +370,7 @@ impl Project {
&self,
abs_path: Arc<Path>,
venv_settings: VenvSettings,
cx: &ModelContext<Project>,
cx: &Context<Project>,
) -> Task<Option<PathBuf>> {
cx.spawn(move |this, mut cx| async move {
if let Some((worktree, _)) = this
@ -409,7 +409,7 @@ impl Project {
&self,
abs_path: &Path,
venv_settings: &terminal_settings::VenvSettingsContent,
cx: &AppContext,
cx: &App,
) -> Option<PathBuf> {
let bin_dir_name = match std::env::consts::OS {
"windows" => "Scripts",
@ -433,7 +433,7 @@ impl Project {
&self,
abs_path: &Path,
venv_settings: &terminal_settings::VenvSettingsContent,
cx: &AppContext,
cx: &App,
) -> Option<PathBuf> {
let (worktree, _) = self.find_worktree(abs_path, cx)?;
let fs = worktree.read(cx).as_local()?.fs();
@ -503,13 +503,13 @@ impl Project {
fn activate_python_virtual_environment(
&self,
command: String,
terminal_handle: &Model<Terminal>,
cx: &mut AppContext,
terminal_handle: &Entity<Terminal>,
cx: &mut App,
) {
terminal_handle.update(cx, |terminal, _| terminal.input_bytes(command.into_bytes()));
}
pub fn local_terminal_handles(&self) -> &Vec<WeakModel<terminal::Terminal>> {
pub fn local_terminal_handles(&self) -> &Vec<WeakEntity<terminal::Terminal>> {
&self.terminals.local_handles
}
}

View file

@ -5,8 +5,8 @@ use anyhow::{bail, Result};
use async_trait::async_trait;
use collections::BTreeMap;
use gpui::{
AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Subscription, Task,
WeakModel,
App, AppContext as _, AsyncAppContext, Context, Entity, EventEmitter, Subscription, Task,
WeakEntity,
};
use language::{LanguageName, LanguageRegistry, LanguageToolchainStore, Toolchain, ToolchainList};
use rpc::{proto, AnyProtoClient, TypedEnvelope};
@ -17,8 +17,11 @@ use crate::{worktree_store::WorktreeStore, ProjectEnvironment};
pub struct ToolchainStore(ToolchainStoreInner);
enum ToolchainStoreInner {
Local(Model<LocalToolchainStore>, #[allow(dead_code)] Subscription),
Remote(Model<RemoteToolchainStore>),
Local(
Entity<LocalToolchainStore>,
#[allow(dead_code)] Subscription,
),
Remote(Entity<RemoteToolchainStore>),
}
impl EventEmitter<ToolchainStoreEvent> for ToolchainStore {}
@ -31,11 +34,11 @@ impl ToolchainStore {
pub fn local(
languages: Arc<LanguageRegistry>,
worktree_store: Model<WorktreeStore>,
project_environment: Model<ProjectEnvironment>,
cx: &mut ModelContext<Self>,
worktree_store: Entity<WorktreeStore>,
project_environment: Entity<ProjectEnvironment>,
cx: &mut Context<Self>,
) -> Self {
let model = cx.new_model(|_| LocalToolchainStore {
let model = cx.new(|_| LocalToolchainStore {
languages,
worktree_store,
project_environment,
@ -46,16 +49,16 @@ impl ToolchainStore {
});
Self(ToolchainStoreInner::Local(model, subscription))
}
pub(super) fn remote(project_id: u64, client: AnyProtoClient, cx: &mut AppContext) -> Self {
pub(super) fn remote(project_id: u64, client: AnyProtoClient, cx: &mut App) -> Self {
Self(ToolchainStoreInner::Remote(
cx.new_model(|_| RemoteToolchainStore { client, project_id }),
cx.new(|_| RemoteToolchainStore { client, project_id }),
))
}
pub(crate) fn activate_toolchain(
&self,
worktree_id: WorktreeId,
toolchain: Toolchain,
cx: &mut AppContext,
cx: &mut App,
) -> Task<Option<()>> {
match &self.0 {
ToolchainStoreInner::Local(local, _) => local.update(cx, |this, cx| {
@ -72,7 +75,7 @@ impl ToolchainStore {
&self,
worktree_id: WorktreeId,
language_name: LanguageName,
cx: &AppContext,
cx: &App,
) -> Task<Option<ToolchainList>> {
match &self.0 {
ToolchainStoreInner::Local(local, _) => {
@ -91,7 +94,7 @@ impl ToolchainStore {
&self,
worktree_id: WorktreeId,
language_name: LanguageName,
cx: &AppContext,
cx: &App,
) -> Task<Option<Toolchain>> {
match &self.0 {
ToolchainStoreInner::Local(local, _) => {
@ -107,7 +110,7 @@ impl ToolchainStore {
}
}
async fn handle_activate_toolchain(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::ActivateToolchain>,
mut cx: AsyncAppContext,
) -> Result<proto::Ack> {
@ -129,7 +132,7 @@ impl ToolchainStore {
Ok(proto::Ack {})
}
async fn handle_active_toolchain(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::ActiveToolchain>,
mut cx: AsyncAppContext,
) -> Result<proto::ActiveToolchainResponse> {
@ -151,7 +154,7 @@ impl ToolchainStore {
}
async fn handle_list_toolchains(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::ListToolchains>,
mut cx: AsyncAppContext,
) -> Result<proto::ListToolchainsResponse> {
@ -207,8 +210,8 @@ impl ToolchainStore {
struct LocalToolchainStore {
languages: Arc<LanguageRegistry>,
worktree_store: Model<WorktreeStore>,
project_environment: Model<ProjectEnvironment>,
worktree_store: Entity<WorktreeStore>,
project_environment: Entity<ProjectEnvironment>,
active_toolchains: BTreeMap<(WorktreeId, LanguageName), Toolchain>,
}
@ -258,8 +261,8 @@ impl language::LanguageToolchainStore for EmptyToolchainStore {
None
}
}
struct LocalStore(WeakModel<LocalToolchainStore>);
struct RemoteStore(WeakModel<RemoteToolchainStore>);
struct LocalStore(WeakEntity<LocalToolchainStore>);
struct RemoteStore(WeakEntity<RemoteToolchainStore>);
#[derive(Clone)]
pub(crate) enum ToolchainStoreEvent {
@ -273,7 +276,7 @@ impl LocalToolchainStore {
&self,
worktree_id: WorktreeId,
toolchain: Toolchain,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> Task<Option<()>> {
cx.spawn(move |this, mut cx| async move {
this.update(&mut cx, |this, cx| {
@ -291,7 +294,7 @@ impl LocalToolchainStore {
&self,
worktree_id: WorktreeId,
language_name: LanguageName,
cx: &AppContext,
cx: &App,
) -> Task<Option<ToolchainList>> {
let registry = self.languages.clone();
let Some(root) = self
@ -325,7 +328,7 @@ impl LocalToolchainStore {
&self,
worktree_id: WorktreeId,
language_name: LanguageName,
_: &AppContext,
_: &App,
) -> Task<Option<Toolchain>> {
Task::ready(
self.active_toolchains
@ -344,7 +347,7 @@ impl RemoteToolchainStore {
&self,
worktree_id: WorktreeId,
toolchain: Toolchain,
cx: &AppContext,
cx: &App,
) -> Task<Option<()>> {
let project_id = self.project_id;
let client = self.client.clone();
@ -370,7 +373,7 @@ impl RemoteToolchainStore {
&self,
worktree_id: WorktreeId,
language_name: LanguageName,
cx: &AppContext,
cx: &App,
) -> Task<Option<ToolchainList>> {
let project_id = self.project_id;
let client = self.client.clone();
@ -416,7 +419,7 @@ impl RemoteToolchainStore {
&self,
worktree_id: WorktreeId,
language_name: LanguageName,
cx: &AppContext,
cx: &App,
) -> Task<Option<Toolchain>> {
let project_id = self.project_id;
let client = self.client.clone();

View file

@ -12,9 +12,7 @@ use futures::{
future::{BoxFuture, Shared},
FutureExt, SinkExt,
};
use gpui::{
AppContext, AsyncAppContext, EntityId, EventEmitter, Model, ModelContext, Task, WeakModel,
};
use gpui::{App, AsyncAppContext, Context, Entity, EntityId, EventEmitter, Task, WeakEntity};
use postage::oneshot;
use rpc::{
proto::{self, SSH_PROJECT_ID},
@ -54,16 +52,16 @@ pub struct WorktreeStore {
worktrees_reordered: bool,
#[allow(clippy::type_complexity)]
loading_worktrees:
HashMap<SanitizedPath, Shared<Task<Result<Model<Worktree>, Arc<anyhow::Error>>>>>,
HashMap<SanitizedPath, Shared<Task<Result<Entity<Worktree>, Arc<anyhow::Error>>>>>,
state: WorktreeStoreState,
}
pub enum WorktreeStoreEvent {
WorktreeAdded(Model<Worktree>),
WorktreeAdded(Entity<Worktree>),
WorktreeRemoved(EntityId, WorktreeId),
WorktreeReleased(EntityId, WorktreeId),
WorktreeOrderChanged,
WorktreeUpdateSent(Model<Worktree>),
WorktreeUpdateSent(Entity<Worktree>),
WorktreeUpdatedEntries(WorktreeId, UpdatedEntriesSet),
WorktreeUpdatedGitRepositories(WorktreeId),
WorktreeDeletedEntry(WorktreeId, ProjectEntryId),
@ -113,7 +111,7 @@ impl WorktreeStore {
}
/// Iterates through all worktrees, including ones that don't appear in the project panel
pub fn worktrees(&self) -> impl '_ + DoubleEndedIterator<Item = Model<Worktree>> {
pub fn worktrees(&self) -> impl '_ + DoubleEndedIterator<Item = Entity<Worktree>> {
self.worktrees
.iter()
.filter_map(move |worktree| worktree.upgrade())
@ -122,18 +120,18 @@ impl WorktreeStore {
/// Iterates through all user-visible worktrees, the ones that appear in the project panel.
pub fn visible_worktrees<'a>(
&'a self,
cx: &'a AppContext,
) -> impl 'a + DoubleEndedIterator<Item = Model<Worktree>> {
cx: &'a App,
) -> impl 'a + DoubleEndedIterator<Item = Entity<Worktree>> {
self.worktrees()
.filter(|worktree| worktree.read(cx).is_visible())
}
pub fn worktree_for_id(&self, id: WorktreeId, cx: &AppContext) -> Option<Model<Worktree>> {
pub fn worktree_for_id(&self, id: WorktreeId, cx: &App) -> Option<Entity<Worktree>> {
self.worktrees()
.find(|worktree| worktree.read(cx).id() == id)
}
pub fn current_branch(&self, repository: ProjectPath, cx: &AppContext) -> Option<Arc<str>> {
pub fn current_branch(&self, repository: ProjectPath, cx: &App) -> Option<Arc<str>> {
self.worktree_for_id(repository.worktree_id, cx)?
.read(cx)
.git_entry(repository.path)?
@ -143,8 +141,8 @@ impl WorktreeStore {
pub fn worktree_for_entry(
&self,
entry_id: ProjectEntryId,
cx: &AppContext,
) -> Option<Model<Worktree>> {
cx: &App,
) -> Option<Entity<Worktree>> {
self.worktrees()
.find(|worktree| worktree.read(cx).contains_entry(entry_id))
}
@ -152,8 +150,8 @@ impl WorktreeStore {
pub fn find_worktree(
&self,
abs_path: impl Into<SanitizedPath>,
cx: &AppContext,
) -> Option<(Model<Worktree>, PathBuf)> {
cx: &App,
) -> Option<(Entity<Worktree>, PathBuf)> {
let abs_path: SanitizedPath = abs_path.into();
for tree in self.worktrees() {
if let Ok(relative_path) = abs_path.as_path().strip_prefix(tree.read(cx).abs_path()) {
@ -167,8 +165,8 @@ impl WorktreeStore {
&mut self,
abs_path: impl AsRef<Path>,
visible: bool,
cx: &mut ModelContext<Self>,
) -> Task<Result<(Model<Worktree>, PathBuf)>> {
cx: &mut Context<Self>,
) -> Task<Result<(Entity<Worktree>, PathBuf)>> {
let abs_path = abs_path.as_ref();
if let Some((tree, relative_path)) = self.find_worktree(abs_path, cx) {
Task::ready(Ok((tree, relative_path)))
@ -179,11 +177,7 @@ impl WorktreeStore {
}
}
pub fn entry_for_id<'a>(
&'a self,
entry_id: ProjectEntryId,
cx: &'a AppContext,
) -> Option<&'a Entry> {
pub fn entry_for_id<'a>(&'a self, entry_id: ProjectEntryId, cx: &'a App) -> Option<&'a Entry> {
self.worktrees()
.find_map(|worktree| worktree.read(cx).entry_for_id(entry_id))
}
@ -191,8 +185,8 @@ impl WorktreeStore {
pub fn worktree_and_entry_for_id<'a>(
&'a self,
entry_id: ProjectEntryId,
cx: &'a AppContext,
) -> Option<(Model<Worktree>, &'a Entry)> {
cx: &'a App,
) -> Option<(Entity<Worktree>, &'a Entry)> {
self.worktrees().find_map(|worktree| {
worktree
.read(cx)
@ -201,7 +195,7 @@ impl WorktreeStore {
})
}
pub fn entry_for_path(&self, path: &ProjectPath, cx: &AppContext) -> Option<Entry> {
pub fn entry_for_path(&self, path: &ProjectPath, cx: &App) -> Option<Entry> {
self.worktree_for_id(path.worktree_id, cx)?
.read(cx)
.entry_for_path(&path.path)
@ -212,8 +206,8 @@ impl WorktreeStore {
&mut self,
abs_path: impl Into<SanitizedPath>,
visible: bool,
cx: &mut ModelContext<Self>,
) -> Task<Result<Model<Worktree>>> {
cx: &mut Context<Self>,
) -> Task<Result<Entity<Worktree>>> {
let abs_path: SanitizedPath = abs_path.into();
if !self.loading_worktrees.contains_key(&abs_path) {
let task = match &self.state {
@ -256,8 +250,8 @@ impl WorktreeStore {
client: AnyProtoClient,
abs_path: impl Into<SanitizedPath>,
visible: bool,
cx: &mut ModelContext<Self>,
) -> Task<Result<Model<Worktree>, Arc<anyhow::Error>>> {
cx: &mut Context<Self>,
) -> Task<Result<Entity<Worktree>, Arc<anyhow::Error>>> {
let mut abs_path = Into::<SanitizedPath>::into(abs_path).to_string();
// If we start with `/~` that means the ssh path was something like `ssh://user@host/~/home-dir-folder/`
// in which case want to strip the leading the `/`.
@ -318,8 +312,8 @@ impl WorktreeStore {
fs: Arc<dyn Fs>,
abs_path: impl Into<SanitizedPath>,
visible: bool,
cx: &mut ModelContext<Self>,
) -> Task<Result<Model<Worktree>, Arc<anyhow::Error>>> {
cx: &mut Context<Self>,
) -> Task<Result<Entity<Worktree>, Arc<anyhow::Error>>> {
let next_entry_id = self.next_entry_id.clone();
let path: SanitizedPath = abs_path.into();
@ -341,7 +335,7 @@ impl WorktreeStore {
})
}
pub fn add(&mut self, worktree: &Model<Worktree>, cx: &mut ModelContext<Self>) {
pub fn add(&mut self, worktree: &Entity<Worktree>, cx: &mut Context<Self>) {
let worktree_id = worktree.read(cx).id();
debug_assert!(self.worktrees().all(|w| w.read(cx).id() != worktree_id));
@ -402,7 +396,7 @@ impl WorktreeStore {
.detach();
}
pub fn remove_worktree(&mut self, id_to_remove: WorktreeId, cx: &mut ModelContext<Self>) {
pub fn remove_worktree(&mut self, id_to_remove: WorktreeId, cx: &mut Context<Self>) {
self.worktrees.retain(|worktree| {
if let Some(worktree) = worktree.upgrade() {
if worktree.read(cx).id() == id_to_remove {
@ -440,7 +434,7 @@ impl WorktreeStore {
&mut self,
worktrees: Vec<proto::WorktreeMetadata>,
replica_id: ReplicaId,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> Result<()> {
let mut old_worktrees_by_id = self
.worktrees
@ -484,7 +478,7 @@ impl WorktreeStore {
&mut self,
source: WorktreeId,
destination: WorktreeId,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) -> Result<()> {
if source == destination {
return Ok(());
@ -526,7 +520,7 @@ impl WorktreeStore {
Ok(())
}
pub fn disconnected_from_host(&mut self, cx: &mut AppContext) {
pub fn disconnected_from_host(&mut self, cx: &mut App) {
for worktree in &self.worktrees {
if let Some(worktree) = worktree.upgrade() {
worktree.update(cx, |worktree, _| {
@ -538,7 +532,7 @@ impl WorktreeStore {
}
}
pub fn send_project_updates(&mut self, cx: &mut ModelContext<Self>) {
pub fn send_project_updates(&mut self, cx: &mut Context<Self>) {
let Some((downstream_client, project_id)) = self.downstream_client.clone() else {
return;
};
@ -592,7 +586,7 @@ impl WorktreeStore {
.detach_and_log_err(cx);
}
pub fn worktree_metadata_protos(&self, cx: &AppContext) -> Vec<proto::WorktreeMetadata> {
pub fn worktree_metadata_protos(&self, cx: &App) -> Vec<proto::WorktreeMetadata> {
self.worktrees()
.map(|worktree| {
let worktree = worktree.read(cx);
@ -610,7 +604,7 @@ impl WorktreeStore {
&mut self,
remote_id: u64,
downstream_client: AnyProtoClient,
cx: &mut ModelContext<Self>,
cx: &mut Context<Self>,
) {
self.retain_worktrees = true;
self.downstream_client = Some((downstream_client, remote_id));
@ -629,7 +623,7 @@ impl WorktreeStore {
self.send_project_updates(cx);
}
pub fn unshared(&mut self, cx: &mut ModelContext<Self>) {
pub fn unshared(&mut self, cx: &mut Context<Self>) {
self.retain_worktrees = false;
self.downstream_client.take();
@ -654,7 +648,7 @@ impl WorktreeStore {
limit: usize,
open_entries: HashSet<ProjectEntryId>,
fs: Arc<dyn Fs>,
cx: &ModelContext<Self>,
cx: &Context<Self>,
) -> Receiver<ProjectPath> {
let snapshots = self
.visible_worktrees(cx)
@ -890,7 +884,7 @@ impl WorktreeStore {
pub fn branches(
&self,
project_path: ProjectPath,
cx: &AppContext,
cx: &App,
) -> Task<Result<Vec<git::repository::Branch>>> {
let Some(worktree) = self.worktree_for_id(project_path.worktree_id, cx) else {
return Task::ready(Err(anyhow!("No worktree found for ProjectPath")));
@ -956,7 +950,7 @@ impl WorktreeStore {
&self,
repository: ProjectPath,
new_branch: String,
cx: &AppContext,
cx: &App,
) -> Task<Result<()>> {
let Some(worktree) = self.worktree_for_id(repository.worktree_id, cx) else {
return Task::ready(Err(anyhow!("No worktree found for ProjectPath")));
@ -1045,7 +1039,7 @@ impl WorktreeStore {
}
pub async fn handle_create_project_entry(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::CreateProjectEntry>,
mut cx: AsyncAppContext,
) -> Result<proto::ProjectEntryResponse> {
@ -1058,7 +1052,7 @@ impl WorktreeStore {
}
pub async fn handle_copy_project_entry(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::CopyProjectEntry>,
mut cx: AsyncAppContext,
) -> Result<proto::ProjectEntryResponse> {
@ -1071,7 +1065,7 @@ impl WorktreeStore {
}
pub async fn handle_delete_project_entry(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::DeleteProjectEntry>,
mut cx: AsyncAppContext,
) -> Result<proto::ProjectEntryResponse> {
@ -1084,7 +1078,7 @@ impl WorktreeStore {
}
pub async fn handle_expand_project_entry(
this: Model<Self>,
this: Entity<Self>,
envelope: TypedEnvelope<proto::ExpandProjectEntry>,
mut cx: AsyncAppContext,
) -> Result<proto::ExpandProjectEntryResponse> {
@ -1096,7 +1090,7 @@ impl WorktreeStore {
}
pub async fn handle_git_branches(
this: Model<Self>,
this: Entity<Self>,
branches: TypedEnvelope<proto::GitBranches>,
cx: AsyncAppContext,
) -> Result<proto::GitBranchesResponse> {
@ -1127,7 +1121,7 @@ impl WorktreeStore {
}
pub async fn handle_update_branch(
this: Model<Self>,
this: Entity<Self>,
update_branch: TypedEnvelope<proto::UpdateGitBranch>,
cx: AsyncAppContext,
) -> Result<proto::Ack> {
@ -1153,12 +1147,12 @@ impl WorktreeStore {
#[derive(Clone, Debug)]
enum WorktreeHandle {
Strong(Model<Worktree>),
Weak(WeakModel<Worktree>),
Strong(Entity<Worktree>),
Weak(WeakEntity<Worktree>),
}
impl WorktreeHandle {
fn upgrade(&self) -> Option<Model<Worktree>> {
fn upgrade(&self) -> Option<Entity<Worktree>> {
match self {
WorktreeHandle::Strong(handle) => Some(handle.clone()),
WorktreeHandle::Weak(handle) => handle.upgrade(),

View file

@ -14,7 +14,7 @@ use std::{
use anyhow::Result;
use collections::HashMap;
use fs::Fs;
use gpui::{AppContext, Context, Model, ModelContext, Task};
use gpui::{App, AppContext as _, Context, Entity, Task};
use util::ResultExt;
pub(crate) struct YarnPathStore {
@ -57,8 +57,8 @@ fn resolve_virtual(path: &Path) -> Option<Arc<Path>> {
}
impl YarnPathStore {
pub(crate) fn new(fs: Arc<dyn Fs>, cx: &mut AppContext) -> Model<Self> {
cx.new_model(|_| Self {
pub(crate) fn new(fs: Arc<dyn Fs>, cx: &mut App) -> Entity<Self> {
cx.new(|_| Self {
temp_dirs: Default::default(),
fs,
})
@ -67,7 +67,7 @@ impl YarnPathStore {
&mut self,
path: &Path,
protocol: &str,
cx: &ModelContext<Self>,
cx: &Context<Self>,
) -> Task<Option<(Arc<Path>, Arc<Path>)>> {
let mut is_zip = protocol.eq("zip");