text: Wrap BufferId into a newtype
This commit is contained in:
@@ -21,7 +21,7 @@ use lsp::{
|
||||
OneOf, ServerCapabilities,
|
||||
};
|
||||
use std::{cmp::Reverse, ops::Range, path::Path, sync::Arc};
|
||||
use text::LineEnding;
|
||||
use text::{BufferId, LineEnding};
|
||||
|
||||
pub fn lsp_formatting_options(tab_size: u32) -> lsp::FormattingOptions {
|
||||
lsp::FormattingOptions {
|
||||
@@ -84,7 +84,7 @@ pub trait LspCommand: 'static + Sized + Send {
|
||||
cx: AsyncAppContext,
|
||||
) -> Result<Self::Response>;
|
||||
|
||||
fn buffer_id_from_proto(message: &Self::ProtoRequest) -> u64;
|
||||
fn buffer_id_from_proto(message: &Self::ProtoRequest) -> Result<BufferId>;
|
||||
}
|
||||
|
||||
pub(crate) struct PrepareRename {
|
||||
@@ -205,7 +205,7 @@ impl LspCommand for PrepareRename {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::PrepareRename {
|
||||
proto::PrepareRename {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
position: Some(language::proto::serialize_anchor(
|
||||
&buffer.anchor_before(self.position),
|
||||
)),
|
||||
@@ -274,8 +274,8 @@ impl LspCommand for PrepareRename {
|
||||
}
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::PrepareRename) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::PrepareRename) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ impl LspCommand for PerformRename {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::PerformRename {
|
||||
proto::PerformRename {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
position: Some(language::proto::serialize_anchor(
|
||||
&buffer.anchor_before(self.position),
|
||||
)),
|
||||
@@ -393,8 +393,8 @@ impl LspCommand for PerformRename {
|
||||
.await
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::PerformRename) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::PerformRename) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,7 +437,7 @@ impl LspCommand for GetDefinition {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::GetDefinition {
|
||||
proto::GetDefinition {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
position: Some(language::proto::serialize_anchor(
|
||||
&buffer.anchor_before(self.position),
|
||||
)),
|
||||
@@ -486,8 +486,8 @@ impl LspCommand for GetDefinition {
|
||||
location_links_from_proto(message.links, project, cx).await
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::GetDefinition) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::GetDefinition) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,7 +538,7 @@ impl LspCommand for GetTypeDefinition {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::GetTypeDefinition {
|
||||
proto::GetTypeDefinition {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
position: Some(language::proto::serialize_anchor(
|
||||
&buffer.anchor_before(self.position),
|
||||
)),
|
||||
@@ -587,8 +587,8 @@ impl LspCommand for GetTypeDefinition {
|
||||
location_links_from_proto(message.links, project, cx).await
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::GetTypeDefinition) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::GetTypeDefinition) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -617,9 +617,10 @@ async fn location_links_from_proto(
|
||||
for link in proto_links {
|
||||
let origin = match link.origin {
|
||||
Some(origin) => {
|
||||
let buffer_id = BufferId::new(origin.buffer_id)?;
|
||||
let buffer = project
|
||||
.update(&mut cx, |this, cx| {
|
||||
this.wait_for_remote_buffer(origin.buffer_id, cx)
|
||||
this.wait_for_remote_buffer(buffer_id, cx)
|
||||
})?
|
||||
.await?;
|
||||
let start = origin
|
||||
@@ -642,9 +643,10 @@ async fn location_links_from_proto(
|
||||
};
|
||||
|
||||
let target = link.target.ok_or_else(|| anyhow!("missing target"))?;
|
||||
let buffer_id = BufferId::new(target.buffer_id)?;
|
||||
let buffer = project
|
||||
.update(&mut cx, |this, cx| {
|
||||
this.wait_for_remote_buffer(target.buffer_id, cx)
|
||||
this.wait_for_remote_buffer(buffer_id, cx)
|
||||
})?
|
||||
.await?;
|
||||
let start = target
|
||||
@@ -761,7 +763,9 @@ fn location_links_to_proto(
|
||||
.into_iter()
|
||||
.map(|definition| {
|
||||
let origin = definition.origin.map(|origin| {
|
||||
let buffer_id = project.create_buffer_for_peer(&origin.buffer, peer_id, cx);
|
||||
let buffer_id = project
|
||||
.create_buffer_for_peer(&origin.buffer, peer_id, cx)
|
||||
.into();
|
||||
proto::Location {
|
||||
start: Some(serialize_anchor(&origin.range.start)),
|
||||
end: Some(serialize_anchor(&origin.range.end)),
|
||||
@@ -769,7 +773,9 @@ fn location_links_to_proto(
|
||||
}
|
||||
});
|
||||
|
||||
let buffer_id = project.create_buffer_for_peer(&definition.target.buffer, peer_id, cx);
|
||||
let buffer_id = project
|
||||
.create_buffer_for_peer(&definition.target.buffer, peer_id, cx)
|
||||
.into();
|
||||
let target = proto::Location {
|
||||
start: Some(serialize_anchor(&definition.target.range.start)),
|
||||
end: Some(serialize_anchor(&definition.target.range.end)),
|
||||
@@ -859,7 +865,7 @@ impl LspCommand for GetReferences {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::GetReferences {
|
||||
proto::GetReferences {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
position: Some(language::proto::serialize_anchor(
|
||||
&buffer.anchor_before(self.position),
|
||||
)),
|
||||
@@ -901,7 +907,7 @@ impl LspCommand for GetReferences {
|
||||
proto::Location {
|
||||
start: Some(serialize_anchor(&definition.range.start)),
|
||||
end: Some(serialize_anchor(&definition.range.end)),
|
||||
buffer_id,
|
||||
buffer_id: buffer_id.into(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
@@ -917,9 +923,10 @@ impl LspCommand for GetReferences {
|
||||
) -> Result<Vec<Location>> {
|
||||
let mut locations = Vec::new();
|
||||
for location in message.locations {
|
||||
let buffer_id = BufferId::new(location.buffer_id)?;
|
||||
let target_buffer = project
|
||||
.update(&mut cx, |this, cx| {
|
||||
this.wait_for_remote_buffer(location.buffer_id, cx)
|
||||
this.wait_for_remote_buffer(buffer_id, cx)
|
||||
})?
|
||||
.await?;
|
||||
let start = location
|
||||
@@ -941,8 +948,8 @@ impl LspCommand for GetReferences {
|
||||
Ok(locations)
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::GetReferences) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::GetReferences) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1007,7 +1014,7 @@ impl LspCommand for GetDocumentHighlights {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::GetDocumentHighlights {
|
||||
proto::GetDocumentHighlights {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
position: Some(language::proto::serialize_anchor(
|
||||
&buffer.anchor_before(self.position),
|
||||
)),
|
||||
@@ -1092,8 +1099,8 @@ impl LspCommand for GetDocumentHighlights {
|
||||
Ok(highlights)
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::GetDocumentHighlights) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::GetDocumentHighlights) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1195,7 +1202,7 @@ impl LspCommand for GetHover {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> Self::ProtoRequest {
|
||||
proto::GetHover {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
position: Some(language::proto::serialize_anchor(
|
||||
&buffer.anchor_before(self.position),
|
||||
)),
|
||||
@@ -1308,8 +1315,8 @@ impl LspCommand for GetHover {
|
||||
}))
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &Self::ProtoRequest) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &Self::ProtoRequest) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1492,7 +1499,7 @@ impl LspCommand for GetCompletions {
|
||||
let anchor = buffer.anchor_after(self.position);
|
||||
proto::GetCompletions {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
position: Some(language::proto::serialize_anchor(&anchor)),
|
||||
version: serialize_version(&buffer.version()),
|
||||
}
|
||||
@@ -1556,8 +1563,8 @@ impl LspCommand for GetCompletions {
|
||||
future::try_join_all(completions).await
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::GetCompletions) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::GetCompletions) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1630,7 +1637,7 @@ impl LspCommand for GetCodeActions {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::GetCodeActions {
|
||||
proto::GetCodeActions {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
start: Some(language::proto::serialize_anchor(&self.range.start)),
|
||||
end: Some(language::proto::serialize_anchor(&self.range.end)),
|
||||
version: serialize_version(&buffer.version()),
|
||||
@@ -1695,8 +1702,8 @@ impl LspCommand for GetCodeActions {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::GetCodeActions) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::GetCodeActions) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1768,7 +1775,7 @@ impl LspCommand for OnTypeFormatting {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::OnTypeFormatting {
|
||||
proto::OnTypeFormatting {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
position: Some(language::proto::serialize_anchor(
|
||||
&buffer.anchor_before(self.position),
|
||||
)),
|
||||
@@ -1831,8 +1838,8 @@ impl LspCommand for OnTypeFormatting {
|
||||
Ok(Some(language::proto::deserialize_transaction(transaction)?))
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::OnTypeFormatting) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::OnTypeFormatting) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2291,7 +2298,7 @@ impl LspCommand for InlayHints {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::InlayHints {
|
||||
proto::InlayHints {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
start: Some(language::proto::serialize_anchor(&self.range.start)),
|
||||
end: Some(language::proto::serialize_anchor(&self.range.end)),
|
||||
version: serialize_version(&buffer.version()),
|
||||
@@ -2358,7 +2365,7 @@ impl LspCommand for InlayHints {
|
||||
Ok(hints)
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::InlayHints) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::InlayHints) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use std::{path::Path, sync::Arc};
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::{Context, Result};
|
||||
use async_trait::async_trait;
|
||||
use gpui::{AppContext, AsyncAppContext, Model};
|
||||
use language::{point_to_lsp, proto::deserialize_anchor, Buffer};
|
||||
use lsp::{LanguageServer, LanguageServerId};
|
||||
use rpc::proto::{self, PeerId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use text::{PointUtf16, ToPointUtf16};
|
||||
use text::{BufferId, PointUtf16, ToPointUtf16};
|
||||
|
||||
use crate::{lsp_command::LspCommand, Project};
|
||||
|
||||
@@ -83,7 +83,7 @@ impl LspCommand for ExpandMacro {
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::LspExtExpandMacro {
|
||||
proto::LspExtExpandMacro {
|
||||
project_id,
|
||||
buffer_id: buffer.remote_id(),
|
||||
buffer_id: buffer.remote_id().into(),
|
||||
position: Some(language::proto::serialize_anchor(
|
||||
&buffer.anchor_before(self.position),
|
||||
)),
|
||||
@@ -131,7 +131,7 @@ impl LspCommand for ExpandMacro {
|
||||
})
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::LspExtExpandMacro) -> u64 {
|
||||
message.buffer_id
|
||||
fn buffer_id_from_proto(message: &proto::LspExtExpandMacro) -> Result<BufferId> {
|
||||
BufferId::new(message.buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
+107
-80
@@ -12,7 +12,7 @@ mod project_tests;
|
||||
#[cfg(test)]
|
||||
mod worktree_tests;
|
||||
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use anyhow::{anyhow, bail, Context as _, Result};
|
||||
use client::{proto, Client, Collaborator, TypedEnvelope, UserStore};
|
||||
use clock::ReplicaId;
|
||||
use collections::{hash_map, BTreeMap, HashMap, HashSet, VecDeque};
|
||||
@@ -81,7 +81,7 @@ use std::{
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use terminals::Terminals;
|
||||
use text::Anchor;
|
||||
use text::{Anchor, BufferId};
|
||||
use util::{
|
||||
debug_panic, defer, http::HttpClient, merge_json_value_into,
|
||||
paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt, TryFutureExt as _,
|
||||
@@ -120,9 +120,9 @@ pub struct Project {
|
||||
collaborators: HashMap<proto::PeerId, Collaborator>,
|
||||
client_subscriptions: Vec<client::Subscription>,
|
||||
_subscriptions: Vec<gpui::Subscription>,
|
||||
next_buffer_id: u64,
|
||||
next_buffer_id: BufferId,
|
||||
opened_buffer: (watch::Sender<()>, watch::Receiver<()>),
|
||||
shared_buffers: HashMap<proto::PeerId, HashSet<u64>>,
|
||||
shared_buffers: HashMap<proto::PeerId, HashSet<BufferId>>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
loading_buffers_by_path: HashMap<
|
||||
ProjectPath,
|
||||
@@ -131,14 +131,14 @@ pub struct Project {
|
||||
#[allow(clippy::type_complexity)]
|
||||
loading_local_worktrees:
|
||||
HashMap<Arc<Path>, Shared<Task<Result<Model<Worktree>, Arc<anyhow::Error>>>>>,
|
||||
opened_buffers: HashMap<u64, OpenBuffer>,
|
||||
local_buffer_ids_by_path: HashMap<ProjectPath, u64>,
|
||||
local_buffer_ids_by_entry_id: HashMap<ProjectEntryId, u64>,
|
||||
opened_buffers: HashMap<BufferId, OpenBuffer>,
|
||||
local_buffer_ids_by_path: HashMap<ProjectPath, BufferId>,
|
||||
local_buffer_ids_by_entry_id: HashMap<ProjectEntryId, BufferId>,
|
||||
/// A mapping from a buffer ID to None means that we've started waiting for an ID but haven't finished loading it.
|
||||
/// Used for re-issuing buffer requests when peers temporarily disconnect
|
||||
incomplete_remote_buffers: HashMap<u64, Option<Model<Buffer>>>,
|
||||
buffer_snapshots: HashMap<u64, HashMap<LanguageServerId, Vec<LspBufferSnapshot>>>, // buffer_id -> server_id -> vec of snapshots
|
||||
buffers_being_formatted: HashSet<u64>,
|
||||
incomplete_remote_buffers: HashMap<BufferId, Option<Model<Buffer>>>,
|
||||
buffer_snapshots: HashMap<BufferId, HashMap<LanguageServerId, Vec<LspBufferSnapshot>>>, // buffer_id -> server_id -> vec of snapshots
|
||||
buffers_being_formatted: HashSet<BufferId>,
|
||||
buffers_needing_diff: HashSet<WeakModel<Buffer>>,
|
||||
git_diff_debouncer: DelayedDebounced,
|
||||
nonce: u128,
|
||||
@@ -210,7 +210,7 @@ struct LspBufferSnapshot {
|
||||
/// Message ordered with respect to buffer operations
|
||||
enum BufferOrderedMessage {
|
||||
Operation {
|
||||
buffer_id: u64,
|
||||
buffer_id: BufferId,
|
||||
operation: proto::Operation,
|
||||
},
|
||||
LanguageServerUpdate {
|
||||
@@ -224,7 +224,7 @@ enum LocalProjectUpdate {
|
||||
WorktreesChanged,
|
||||
CreateBufferForPeer {
|
||||
peer_id: proto::PeerId,
|
||||
buffer_id: u64,
|
||||
buffer_id: BufferId,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -636,7 +636,7 @@ impl Project {
|
||||
worktrees: Vec::new(),
|
||||
buffer_ordered_messages_tx: tx,
|
||||
collaborators: Default::default(),
|
||||
next_buffer_id: 0,
|
||||
next_buffer_id: BufferId::new(1).unwrap(),
|
||||
opened_buffers: Default::default(),
|
||||
shared_buffers: Default::default(),
|
||||
incomplete_remote_buffers: Default::default(),
|
||||
@@ -722,7 +722,7 @@ impl Project {
|
||||
worktrees: Vec::new(),
|
||||
buffer_ordered_messages_tx: tx,
|
||||
loading_buffers_by_path: Default::default(),
|
||||
next_buffer_id: 0,
|
||||
next_buffer_id: BufferId::default(),
|
||||
opened_buffer: watch::channel(),
|
||||
shared_buffers: Default::default(),
|
||||
incomplete_remote_buffers: Default::default(),
|
||||
@@ -997,7 +997,7 @@ impl Project {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn buffer_for_id(&self, remote_id: u64) -> Option<Model<Buffer>> {
|
||||
pub fn buffer_for_id(&self, remote_id: BufferId) -> Option<Model<Buffer>> {
|
||||
self.opened_buffers
|
||||
.get(&remote_id)
|
||||
.and_then(|buffer| buffer.upgrade())
|
||||
@@ -1479,7 +1479,7 @@ impl Project {
|
||||
variant: Some(
|
||||
proto::create_buffer_for_peer::Variant::Chunk(
|
||||
proto::BufferChunk {
|
||||
buffer_id,
|
||||
buffer_id: buffer_id.into(),
|
||||
operations: chunk,
|
||||
is_last,
|
||||
},
|
||||
@@ -1713,7 +1713,7 @@ impl Project {
|
||||
if self.is_remote() {
|
||||
return Err(anyhow!("creating buffers as a guest is not supported yet"));
|
||||
}
|
||||
let id = post_inc(&mut self.next_buffer_id);
|
||||
let id = self.next_buffer_id.next();
|
||||
let buffer = cx.new_model(|cx| {
|
||||
Buffer::new(self.replica_id(), id, text)
|
||||
.with_language(language.unwrap_or_else(|| language::PLAIN_TEXT.clone()), cx)
|
||||
@@ -1814,7 +1814,7 @@ impl Project {
|
||||
worktree: &Model<Worktree>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Model<Buffer>>> {
|
||||
let buffer_id = post_inc(&mut self.next_buffer_id);
|
||||
let buffer_id = self.next_buffer_id.next();
|
||||
let load_buffer = worktree.update(cx, |worktree, cx| {
|
||||
let worktree = worktree.as_local_mut().unwrap();
|
||||
worktree.load_buffer(buffer_id, path, cx)
|
||||
@@ -1845,8 +1845,9 @@ impl Project {
|
||||
path: path_string,
|
||||
})
|
||||
.await?;
|
||||
let buffer_id = BufferId::new(response.buffer_id)?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.wait_for_remote_buffer(response.buffer_id, cx)
|
||||
this.wait_for_remote_buffer(buffer_id, cx)
|
||||
})?
|
||||
.await
|
||||
})
|
||||
@@ -1895,7 +1896,7 @@ impl Project {
|
||||
|
||||
pub fn open_buffer_by_id(
|
||||
&mut self,
|
||||
id: u64,
|
||||
id: BufferId,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Model<Buffer>>> {
|
||||
if let Some(buffer) = self.buffer_for_id(id) {
|
||||
@@ -1903,11 +1904,12 @@ impl Project {
|
||||
} else if self.is_local() {
|
||||
Task::ready(Err(anyhow!("buffer {} does not exist", id)))
|
||||
} else if let Some(project_id) = self.remote_id() {
|
||||
let request = self
|
||||
.client
|
||||
.request(proto::OpenBufferById { project_id, id });
|
||||
let request = self.client.request(proto::OpenBufferById {
|
||||
project_id,
|
||||
id: id.into(),
|
||||
});
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
let buffer_id = request.await?.buffer_id;
|
||||
let buffer_id = BufferId::new(request.await?.buffer_id)?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.wait_for_remote_buffer(buffer_id, cx)
|
||||
})?
|
||||
@@ -2223,7 +2225,7 @@ impl Project {
|
||||
let mut operations_by_buffer_id = HashMap::default();
|
||||
async fn flush_operations(
|
||||
this: &WeakModel<Project>,
|
||||
operations_by_buffer_id: &mut HashMap<u64, Vec<proto::Operation>>,
|
||||
operations_by_buffer_id: &mut HashMap<BufferId, Vec<proto::Operation>>,
|
||||
needs_resync_with_host: &mut bool,
|
||||
is_local: bool,
|
||||
cx: &mut AsyncAppContext,
|
||||
@@ -2232,7 +2234,7 @@ impl Project {
|
||||
let request = this.update(cx, |this, _| {
|
||||
let project_id = this.remote_id()?;
|
||||
Some(this.client.request(proto::UpdateBuffer {
|
||||
buffer_id,
|
||||
buffer_id: buffer_id.into(),
|
||||
project_id,
|
||||
operations,
|
||||
}))
|
||||
@@ -4078,7 +4080,9 @@ impl Project {
|
||||
buffer_ids: remote_buffers
|
||||
.iter()
|
||||
.filter_map(|buffer| {
|
||||
buffer.update(&mut cx, |buffer, _| buffer.remote_id()).ok()
|
||||
buffer
|
||||
.update(&mut cx, |buffer, _| buffer.remote_id().into())
|
||||
.ok()
|
||||
})
|
||||
.collect(),
|
||||
})
|
||||
@@ -4324,7 +4328,7 @@ impl Project {
|
||||
buffer_ids: buffers
|
||||
.iter()
|
||||
.map(|buffer| {
|
||||
buffer.update(&mut cx, |buffer, _| buffer.remote_id())
|
||||
buffer.update(&mut cx, |buffer, _| buffer.remote_id().into())
|
||||
})
|
||||
.collect::<Result<_>>()?,
|
||||
})
|
||||
@@ -4720,8 +4724,9 @@ impl Project {
|
||||
});
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
let response = request.await?;
|
||||
let buffer_id = BufferId::new(response.buffer_id)?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.wait_for_remote_buffer(response.buffer_id, cx)
|
||||
this.wait_for_remote_buffer(buffer_id, cx)
|
||||
})?
|
||||
.await
|
||||
})
|
||||
@@ -5047,7 +5052,7 @@ impl Project {
|
||||
let response = client
|
||||
.request(proto::ApplyCompletionAdditionalEdits {
|
||||
project_id,
|
||||
buffer_id,
|
||||
buffer_id: buffer_id.into(),
|
||||
completion: Some(language::proto::serialize_completion(&completion)),
|
||||
})
|
||||
.await?;
|
||||
@@ -5179,7 +5184,7 @@ impl Project {
|
||||
let client = self.client.clone();
|
||||
let request = proto::ApplyCodeAction {
|
||||
project_id,
|
||||
buffer_id: buffer_handle.read(cx).remote_id(),
|
||||
buffer_id: buffer_handle.read(cx).remote_id().into(),
|
||||
action: Some(language::proto::serialize_code_action(&action)),
|
||||
};
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
@@ -5242,7 +5247,7 @@ impl Project {
|
||||
let client = self.client.clone();
|
||||
let request = proto::OnTypeFormatting {
|
||||
project_id,
|
||||
buffer_id: buffer.read(cx).remote_id(),
|
||||
buffer_id: buffer.read(cx).remote_id().into(),
|
||||
position: Some(serialize_anchor(&position)),
|
||||
trigger,
|
||||
version: serialize_version(&buffer.read(cx).version()),
|
||||
@@ -5531,7 +5536,7 @@ impl Project {
|
||||
let range = buffer.anchor_before(range.start)..buffer.anchor_before(range.end);
|
||||
let range_start = range.start;
|
||||
let range_end = range.end;
|
||||
let buffer_id = buffer.remote_id();
|
||||
let buffer_id = buffer.remote_id().into();
|
||||
let buffer_version = buffer.version().clone();
|
||||
let lsp_request = InlayHints { range };
|
||||
|
||||
@@ -5624,7 +5629,7 @@ impl Project {
|
||||
let client = self.client.clone();
|
||||
let request = proto::ResolveInlayHint {
|
||||
project_id,
|
||||
buffer_id: buffer_handle.read(cx).remote_id(),
|
||||
buffer_id: buffer_handle.read(cx).remote_id().into(),
|
||||
language_server_id: server_id.0 as u64,
|
||||
hint: Some(InlayHints::project_to_proto_hint(hint.clone())),
|
||||
};
|
||||
@@ -5659,9 +5664,10 @@ impl Project {
|
||||
let response = request.await?;
|
||||
let mut result = HashMap::default();
|
||||
for location in response.locations {
|
||||
let buffer_id = BufferId::new(location.buffer_id)?;
|
||||
let target_buffer = this
|
||||
.update(&mut cx, |this, cx| {
|
||||
this.wait_for_remote_buffer(location.buffer_id, cx)
|
||||
this.wait_for_remote_buffer(buffer_id, cx)
|
||||
})?
|
||||
.await?;
|
||||
let start = location
|
||||
@@ -6555,7 +6561,7 @@ impl Project {
|
||||
self.client
|
||||
.send(proto::UpdateBufferFile {
|
||||
project_id,
|
||||
buffer_id: buffer_id as u64,
|
||||
buffer_id: buffer_id.into(),
|
||||
file: Some(new_file.to_proto()),
|
||||
})
|
||||
.log_err();
|
||||
@@ -6721,7 +6727,7 @@ impl Project {
|
||||
for (buffer, diff_base) in diff_bases_by_buffer {
|
||||
let buffer_id = buffer.update(&mut cx, |buffer, cx| {
|
||||
buffer.set_diff_base(diff_base.clone(), cx);
|
||||
buffer.remote_id()
|
||||
buffer.remote_id().into()
|
||||
})?;
|
||||
if let Some(project_id) = remote_id {
|
||||
client
|
||||
@@ -7353,7 +7359,7 @@ impl Project {
|
||||
) -> Result<proto::Ack> {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let payload = envelope.payload.clone();
|
||||
let buffer_id = payload.buffer_id;
|
||||
let buffer_id = BufferId::new(payload.buffer_id)?;
|
||||
let ops = payload
|
||||
.operations
|
||||
.into_iter()
|
||||
@@ -7404,7 +7410,7 @@ impl Project {
|
||||
as Arc<dyn language::File>);
|
||||
}
|
||||
|
||||
let buffer_id = state.id;
|
||||
let buffer_id = BufferId::new(state.id)?;
|
||||
let buffer = cx.new_model(|_| {
|
||||
Buffer::from_proto(this.replica_id(), this.capability(), state, buffer_file)
|
||||
.unwrap()
|
||||
@@ -7413,9 +7419,10 @@ impl Project {
|
||||
.insert(buffer_id, Some(buffer));
|
||||
}
|
||||
proto::create_buffer_for_peer::Variant::Chunk(chunk) => {
|
||||
let buffer_id = BufferId::new(chunk.buffer_id)?;
|
||||
let buffer = this
|
||||
.incomplete_remote_buffers
|
||||
.get(&chunk.buffer_id)
|
||||
.get(&buffer_id)
|
||||
.cloned()
|
||||
.flatten()
|
||||
.ok_or_else(|| {
|
||||
@@ -7432,7 +7439,7 @@ impl Project {
|
||||
buffer.update(cx, |buffer, cx| buffer.apply_ops(operations, cx))?;
|
||||
|
||||
if chunk.is_last {
|
||||
this.incomplete_remote_buffers.remove(&chunk.buffer_id);
|
||||
this.incomplete_remote_buffers.remove(&buffer_id);
|
||||
this.register_buffer(&buffer, cx)?;
|
||||
}
|
||||
}
|
||||
@@ -7450,6 +7457,7 @@ impl Project {
|
||||
) -> Result<()> {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let buffer_id = envelope.payload.buffer_id;
|
||||
let buffer_id = BufferId::new(buffer_id)?;
|
||||
let diff_base = envelope.payload.diff_base;
|
||||
if let Some(buffer) = this
|
||||
.opened_buffers
|
||||
@@ -7475,6 +7483,7 @@ impl Project {
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<()> {
|
||||
let buffer_id = envelope.payload.buffer_id;
|
||||
let buffer_id = BufferId::new(buffer_id)?;
|
||||
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let payload = envelope.payload.clone();
|
||||
@@ -7509,7 +7518,7 @@ impl Project {
|
||||
_: Arc<Client>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::BufferSaved> {
|
||||
let buffer_id = envelope.payload.buffer_id;
|
||||
let buffer_id = BufferId::new(envelope.payload.buffer_id)?;
|
||||
let (project_id, buffer) = this.update(&mut cx, |this, _cx| {
|
||||
let project_id = this.remote_id().ok_or_else(|| anyhow!("not connected"))?;
|
||||
let buffer = this
|
||||
@@ -7530,7 +7539,7 @@ impl Project {
|
||||
.await?;
|
||||
Ok(buffer.update(&mut cx, |buffer, _| proto::BufferSaved {
|
||||
project_id,
|
||||
buffer_id,
|
||||
buffer_id: buffer_id.into(),
|
||||
version: serialize_version(buffer.saved_version()),
|
||||
mtime: Some(buffer.saved_mtime().into()),
|
||||
fingerprint: language::proto::serialize_fingerprint(buffer.saved_version_fingerprint()),
|
||||
@@ -7547,9 +7556,10 @@ impl Project {
|
||||
let reload = this.update(&mut cx, |this, cx| {
|
||||
let mut buffers = HashSet::default();
|
||||
for buffer_id in &envelope.payload.buffer_ids {
|
||||
let buffer_id = BufferId::new(*buffer_id)?;
|
||||
buffers.insert(
|
||||
this.opened_buffers
|
||||
.get(buffer_id)
|
||||
.get(&buffer_id)
|
||||
.and_then(|buffer| buffer.upgrade())
|
||||
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))?,
|
||||
);
|
||||
@@ -7580,12 +7590,12 @@ impl Project {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let Some(guest_id) = envelope.original_sender_id else {
|
||||
error!("missing original_sender_id on SynchronizeBuffers request");
|
||||
return;
|
||||
bail!("missing original_sender_id on SynchronizeBuffers request");
|
||||
};
|
||||
|
||||
this.shared_buffers.entry(guest_id).or_default().clear();
|
||||
for buffer in envelope.payload.buffers {
|
||||
let buffer_id = buffer.id;
|
||||
let buffer_id = BufferId::new(buffer.id)?;
|
||||
let remote_version = language::proto::deserialize_version(&buffer.version);
|
||||
if let Some(buffer) = this.buffer_for_id(buffer_id) {
|
||||
this.shared_buffers
|
||||
@@ -7595,7 +7605,7 @@ impl Project {
|
||||
|
||||
let buffer = buffer.read(cx);
|
||||
response.buffers.push(proto::BufferVersion {
|
||||
id: buffer_id,
|
||||
id: buffer_id.into(),
|
||||
version: language::proto::serialize_version(&buffer.version),
|
||||
});
|
||||
|
||||
@@ -7605,7 +7615,7 @@ impl Project {
|
||||
client
|
||||
.send(proto::UpdateBufferFile {
|
||||
project_id,
|
||||
buffer_id: buffer_id as u64,
|
||||
buffer_id: buffer_id.into(),
|
||||
file: Some(file.to_proto()),
|
||||
})
|
||||
.log_err();
|
||||
@@ -7614,7 +7624,7 @@ impl Project {
|
||||
client
|
||||
.send(proto::UpdateDiffBase {
|
||||
project_id,
|
||||
buffer_id: buffer_id as u64,
|
||||
buffer_id: buffer_id.into(),
|
||||
diff_base: buffer.diff_base().map(Into::into),
|
||||
})
|
||||
.log_err();
|
||||
@@ -7622,7 +7632,7 @@ impl Project {
|
||||
client
|
||||
.send(proto::BufferReloaded {
|
||||
project_id,
|
||||
buffer_id,
|
||||
buffer_id: buffer_id.into(),
|
||||
version: language::proto::serialize_version(buffer.saved_version()),
|
||||
mtime: Some(buffer.saved_mtime().into()),
|
||||
fingerprint: language::proto::serialize_fingerprint(
|
||||
@@ -7642,7 +7652,7 @@ impl Project {
|
||||
client
|
||||
.request(proto::UpdateBuffer {
|
||||
project_id,
|
||||
buffer_id,
|
||||
buffer_id: buffer_id.into(),
|
||||
operations: chunk,
|
||||
})
|
||||
.await?;
|
||||
@@ -7654,7 +7664,8 @@ impl Project {
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
})?;
|
||||
Ok(())
|
||||
})??;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
@@ -7669,9 +7680,10 @@ impl Project {
|
||||
let format = this.update(&mut cx, |this, cx| {
|
||||
let mut buffers = HashSet::default();
|
||||
for buffer_id in &envelope.payload.buffer_ids {
|
||||
let buffer_id = BufferId::new(*buffer_id)?;
|
||||
buffers.insert(
|
||||
this.opened_buffers
|
||||
.get(buffer_id)
|
||||
.get(&buffer_id)
|
||||
.and_then(|buffer| buffer.upgrade())
|
||||
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))?,
|
||||
);
|
||||
@@ -7696,11 +7708,12 @@ impl Project {
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::ApplyCompletionAdditionalEditsResponse> {
|
||||
let (buffer, completion) = this.update(&mut cx, |this, cx| {
|
||||
let buffer_id = BufferId::new(envelope.payload.buffer_id)?;
|
||||
let buffer = this
|
||||
.opened_buffers
|
||||
.get(&envelope.payload.buffer_id)
|
||||
.get(&buffer_id)
|
||||
.and_then(|buffer| buffer.upgrade())
|
||||
.ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))?;
|
||||
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))?;
|
||||
let language = buffer.read(cx).language();
|
||||
let completion = language::proto::deserialize_completion(
|
||||
envelope
|
||||
@@ -7774,9 +7787,10 @@ impl Project {
|
||||
.ok_or_else(|| anyhow!("invalid action"))?,
|
||||
)?;
|
||||
let apply_code_action = this.update(&mut cx, |this, cx| {
|
||||
let buffer_id = BufferId::new(envelope.payload.buffer_id)?;
|
||||
let buffer = this
|
||||
.opened_buffers
|
||||
.get(&envelope.payload.buffer_id)
|
||||
.get(&buffer_id)
|
||||
.and_then(|buffer| buffer.upgrade())
|
||||
.ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))?;
|
||||
Ok::<_, anyhow::Error>(this.apply_code_action(buffer, action, false, cx))
|
||||
@@ -7798,11 +7812,12 @@ impl Project {
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::OnTypeFormattingResponse> {
|
||||
let on_type_formatting = this.update(&mut cx, |this, cx| {
|
||||
let buffer_id = BufferId::new(envelope.payload.buffer_id)?;
|
||||
let buffer = this
|
||||
.opened_buffers
|
||||
.get(&envelope.payload.buffer_id)
|
||||
.get(&buffer_id)
|
||||
.and_then(|buffer| buffer.upgrade())
|
||||
.ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))?;
|
||||
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))?;
|
||||
let position = envelope
|
||||
.payload
|
||||
.position
|
||||
@@ -7830,9 +7845,10 @@ impl Project {
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::InlayHintsResponse> {
|
||||
let sender_id = envelope.original_sender_id()?;
|
||||
let buffer_id = BufferId::new(envelope.payload.buffer_id)?;
|
||||
let buffer = this.update(&mut cx, |this, _| {
|
||||
this.opened_buffers
|
||||
.get(&envelope.payload.buffer_id)
|
||||
.get(&buffer_id)
|
||||
.and_then(|buffer| buffer.upgrade())
|
||||
.ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))
|
||||
})??;
|
||||
@@ -7886,10 +7902,11 @@ impl Project {
|
||||
let hint = InlayHints::proto_to_project_hint(proto_hint)
|
||||
.context("resolved proto inlay hint conversion")?;
|
||||
let buffer = this.update(&mut cx, |this, _cx| {
|
||||
let buffer_id = BufferId::new(envelope.payload.buffer_id)?;
|
||||
this.opened_buffers
|
||||
.get(&envelope.payload.buffer_id)
|
||||
.get(&buffer_id)
|
||||
.and_then(|buffer| buffer.upgrade())
|
||||
.ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))
|
||||
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))
|
||||
})??;
|
||||
let response_hint = this
|
||||
.update(&mut cx, |project, cx| {
|
||||
@@ -7930,7 +7947,7 @@ impl Project {
|
||||
<T::LspRequest as lsp::request::Request>::Result: Send,
|
||||
{
|
||||
let sender_id = envelope.original_sender_id()?;
|
||||
let buffer_id = T::buffer_id_from_proto(&envelope.payload);
|
||||
let buffer_id = T::buffer_id_from_proto(&envelope.payload)?;
|
||||
let buffer_handle = this.update(&mut cx, |this, _cx| {
|
||||
this.opened_buffers
|
||||
.get(&buffer_id)
|
||||
@@ -7995,7 +8012,7 @@ impl Project {
|
||||
let start = serialize_anchor(&range.start);
|
||||
let end = serialize_anchor(&range.end);
|
||||
let buffer_id = this.update(&mut cx, |this, cx| {
|
||||
this.create_buffer_for_peer(&buffer, peer_id, cx)
|
||||
this.create_buffer_for_peer(&buffer, peer_id, cx).into()
|
||||
})?;
|
||||
locations.push(proto::Location {
|
||||
buffer_id,
|
||||
@@ -8037,7 +8054,7 @@ impl Project {
|
||||
|
||||
Ok(proto::OpenBufferForSymbolResponse {
|
||||
buffer_id: this.update(&mut cx, |this, cx| {
|
||||
this.create_buffer_for_peer(&buffer, peer_id, cx)
|
||||
this.create_buffer_for_peer(&buffer, peer_id, cx).into()
|
||||
})?,
|
||||
})
|
||||
}
|
||||
@@ -8057,14 +8074,13 @@ impl Project {
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::OpenBufferResponse> {
|
||||
let peer_id = envelope.original_sender_id()?;
|
||||
let buffer_id = BufferId::new(envelope.payload.id)?;
|
||||
let buffer = this
|
||||
.update(&mut cx, |this, cx| {
|
||||
this.open_buffer_by_id(envelope.payload.id, cx)
|
||||
})?
|
||||
.update(&mut cx, |this, cx| this.open_buffer_by_id(buffer_id, cx))?
|
||||
.await?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
Ok(proto::OpenBufferResponse {
|
||||
buffer_id: this.create_buffer_for_peer(&buffer, peer_id, cx),
|
||||
buffer_id: this.create_buffer_for_peer(&buffer, peer_id, cx).into(),
|
||||
})
|
||||
})?
|
||||
}
|
||||
@@ -8090,7 +8106,7 @@ impl Project {
|
||||
let buffer = open_buffer.await?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
Ok(proto::OpenBufferResponse {
|
||||
buffer_id: this.create_buffer_for_peer(&buffer, peer_id, cx),
|
||||
buffer_id: this.create_buffer_for_peer(&buffer, peer_id, cx).into(),
|
||||
})
|
||||
})?
|
||||
}
|
||||
@@ -8108,7 +8124,7 @@ impl Project {
|
||||
for (buffer, transaction) in project_transaction.0 {
|
||||
serialized_transaction
|
||||
.buffer_ids
|
||||
.push(self.create_buffer_for_peer(&buffer, peer_id, cx));
|
||||
.push(self.create_buffer_for_peer(&buffer, peer_id, cx).into());
|
||||
serialized_transaction
|
||||
.transactions
|
||||
.push(language::proto::serialize_transaction(&transaction));
|
||||
@@ -8126,6 +8142,7 @@ impl Project {
|
||||
let mut project_transaction = ProjectTransaction::default();
|
||||
for (buffer_id, transaction) in message.buffer_ids.into_iter().zip(message.transactions)
|
||||
{
|
||||
let buffer_id = BufferId::new(buffer_id)?;
|
||||
let buffer = this
|
||||
.update(&mut cx, |this, cx| {
|
||||
this.wait_for_remote_buffer(buffer_id, cx)
|
||||
@@ -8158,7 +8175,7 @@ impl Project {
|
||||
buffer: &Model<Buffer>,
|
||||
peer_id: proto::PeerId,
|
||||
cx: &mut AppContext,
|
||||
) -> u64 {
|
||||
) -> BufferId {
|
||||
let buffer_id = buffer.read(cx).remote_id();
|
||||
if let ProjectClientState::Shared { updates_tx, .. } = &self.client_state {
|
||||
updates_tx
|
||||
@@ -8170,7 +8187,7 @@ impl Project {
|
||||
|
||||
fn wait_for_remote_buffer(
|
||||
&mut self,
|
||||
id: u64,
|
||||
id: BufferId,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Model<Buffer>>> {
|
||||
let mut opened_buffer_rx = self.opened_buffer.1.clone();
|
||||
@@ -8239,7 +8256,7 @@ impl Project {
|
||||
.filter_map(|(id, buffer)| {
|
||||
let buffer = buffer.upgrade()?;
|
||||
Some(proto::BufferVersion {
|
||||
id: *id,
|
||||
id: (*id).into(),
|
||||
version: language::proto::serialize_version(&buffer.read(cx).version),
|
||||
})
|
||||
})
|
||||
@@ -8265,7 +8282,12 @@ impl Project {
|
||||
.into_iter()
|
||||
.map(|buffer| {
|
||||
let client = client.clone();
|
||||
let buffer_id = buffer.id;
|
||||
let buffer_id = match BufferId::new(buffer.id) {
|
||||
Ok(id) => id,
|
||||
Err(e) => {
|
||||
return Task::ready(Err(e));
|
||||
}
|
||||
};
|
||||
let remote_version = language::proto::deserialize_version(&buffer.version);
|
||||
if let Some(buffer) = this.buffer_for_id(buffer_id) {
|
||||
let operations =
|
||||
@@ -8276,7 +8298,7 @@ impl Project {
|
||||
client
|
||||
.request(proto::UpdateBuffer {
|
||||
project_id,
|
||||
buffer_id,
|
||||
buffer_id: buffer_id.into(),
|
||||
operations: chunk,
|
||||
})
|
||||
.await?;
|
||||
@@ -8294,7 +8316,10 @@ impl Project {
|
||||
// creates these buffers for us again to unblock any waiting futures.
|
||||
for id in incomplete_buffer_ids {
|
||||
cx.background_executor()
|
||||
.spawn(client.request(proto::OpenBufferById { project_id, id }))
|
||||
.spawn(client.request(proto::OpenBufferById {
|
||||
project_id,
|
||||
id: id.into(),
|
||||
}))
|
||||
.detach();
|
||||
}
|
||||
|
||||
@@ -8436,6 +8461,7 @@ impl Project {
|
||||
) -> Result<()> {
|
||||
let fingerprint = deserialize_fingerprint(&envelope.payload.fingerprint)?;
|
||||
let version = deserialize_version(&envelope.payload.version);
|
||||
let buffer_id = BufferId::new(envelope.payload.buffer_id)?;
|
||||
let mtime = envelope
|
||||
.payload
|
||||
.mtime
|
||||
@@ -8445,11 +8471,11 @@ impl Project {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let buffer = this
|
||||
.opened_buffers
|
||||
.get(&envelope.payload.buffer_id)
|
||||
.get(&buffer_id)
|
||||
.and_then(|buffer| buffer.upgrade())
|
||||
.or_else(|| {
|
||||
this.incomplete_remote_buffers
|
||||
.get(&envelope.payload.buffer_id)
|
||||
.get(&buffer_id)
|
||||
.and_then(|b| b.clone())
|
||||
});
|
||||
if let Some(buffer) = buffer {
|
||||
@@ -8478,14 +8504,15 @@ impl Project {
|
||||
.mtime
|
||||
.ok_or_else(|| anyhow!("missing mtime"))?
|
||||
.into();
|
||||
let buffer_id = BufferId::new(payload.buffer_id)?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let buffer = this
|
||||
.opened_buffers
|
||||
.get(&payload.buffer_id)
|
||||
.get(&buffer_id)
|
||||
.and_then(|buffer| buffer.upgrade())
|
||||
.or_else(|| {
|
||||
this.incomplete_remote_buffers
|
||||
.get(&payload.buffer_id)
|
||||
.get(&buffer_id)
|
||||
.cloned()
|
||||
.flatten()
|
||||
});
|
||||
|
||||
@@ -62,6 +62,7 @@ use std::{
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
use sum_tree::{Bias, Edit, SeekTarget, SumTree, TreeMap, TreeSet};
|
||||
use text::BufferId;
|
||||
use util::{
|
||||
paths::{PathMatcher, HOME},
|
||||
ResultExt,
|
||||
@@ -672,7 +673,7 @@ impl LocalWorktree {
|
||||
|
||||
pub(crate) fn load_buffer(
|
||||
&mut self,
|
||||
id: u64,
|
||||
id: BufferId,
|
||||
path: &Path,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) -> Task<Result<Model<Buffer>>> {
|
||||
@@ -1043,7 +1044,7 @@ impl LocalWorktree {
|
||||
let buffer = buffer_handle.read(cx);
|
||||
|
||||
let rpc = self.client.clone();
|
||||
let buffer_id = buffer.remote_id();
|
||||
let buffer_id: u64 = buffer.remote_id().into();
|
||||
let project_id = self.share.as_ref().map(|share| share.project_id);
|
||||
|
||||
let text = buffer.as_rope().clone();
|
||||
@@ -1481,7 +1482,7 @@ impl RemoteWorktree {
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) -> Task<Result<()>> {
|
||||
let buffer = buffer_handle.read(cx);
|
||||
let buffer_id = buffer.remote_id();
|
||||
let buffer_id = buffer.remote_id().into();
|
||||
let version = buffer.version();
|
||||
let rpc = self.client.clone();
|
||||
let project_id = self.project_id;
|
||||
@@ -2840,7 +2841,7 @@ impl language::LocalFile for File {
|
||||
|
||||
fn buffer_reloaded(
|
||||
&self,
|
||||
buffer_id: u64,
|
||||
buffer_id: BufferId,
|
||||
version: &clock::Global,
|
||||
fingerprint: RopeFingerprint,
|
||||
line_ending: LineEnding,
|
||||
@@ -2853,7 +2854,7 @@ impl language::LocalFile for File {
|
||||
.client
|
||||
.send(proto::BufferReloaded {
|
||||
project_id,
|
||||
buffer_id,
|
||||
buffer_id: buffer_id.into(),
|
||||
version: serialize_version(version),
|
||||
mtime: Some(mtime.into()),
|
||||
fingerprint: serialize_fingerprint(fingerprint),
|
||||
|
||||
@@ -21,6 +21,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
use text::BufferId;
|
||||
use util::{http::FakeHttpClient, test::temp_tree, ResultExt};
|
||||
|
||||
#[gpui::test]
|
||||
@@ -511,9 +512,11 @@ async fn test_open_gitignored_files(cx: &mut TestAppContext) {
|
||||
let prev_read_dir_count = fs.read_dir_call_count();
|
||||
let buffer = tree
|
||||
.update(cx, |tree, cx| {
|
||||
tree.as_local_mut()
|
||||
.unwrap()
|
||||
.load_buffer(0, "one/node_modules/b/b1.js".as_ref(), cx)
|
||||
tree.as_local_mut().unwrap().load_buffer(
|
||||
BufferId::new(1).unwrap(),
|
||||
"one/node_modules/b/b1.js".as_ref(),
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -553,9 +556,11 @@ async fn test_open_gitignored_files(cx: &mut TestAppContext) {
|
||||
let prev_read_dir_count = fs.read_dir_call_count();
|
||||
let buffer = tree
|
||||
.update(cx, |tree, cx| {
|
||||
tree.as_local_mut()
|
||||
.unwrap()
|
||||
.load_buffer(0, "one/node_modules/a/a2.js".as_ref(), cx)
|
||||
tree.as_local_mut().unwrap().load_buffer(
|
||||
BufferId::new(1).unwrap(),
|
||||
"one/node_modules/a/a2.js".as_ref(),
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user