Fix different kinds values used for worktree_id
(#17523)
This commit is contained in:
parent
47aec5e64d
commit
8985fd87c2
18 changed files with 136 additions and 127 deletions
|
@ -37,6 +37,7 @@ use postage::{
|
|||
watch,
|
||||
};
|
||||
use rpc::proto::{self, AnyProtoClient};
|
||||
pub use settings::WorktreeId;
|
||||
use settings::{Settings, SettingsLocation, SettingsStore};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use smol::channel::{self, Sender};
|
||||
|
@ -68,15 +69,6 @@ pub const FS_WATCH_LATENCY: Duration = Duration::from_millis(100);
|
|||
#[cfg(not(feature = "test-support"))]
|
||||
pub const FS_WATCH_LATENCY: Duration = Duration::from_millis(100);
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
|
||||
pub struct WorktreeId(usize);
|
||||
|
||||
impl From<WorktreeId> for usize {
|
||||
fn from(value: WorktreeId) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of local or remote files that are being opened as part of a project.
|
||||
/// Responsible for tracking related FS (for local)/collab (for remote) events and corresponding updates.
|
||||
/// Stores git repositories data and the diagnostics for the file(s).
|
||||
|
@ -385,24 +377,6 @@ impl Worktree {
|
|||
});
|
||||
|
||||
cx.new_model(move |cx: &mut ModelContext<Worktree>| {
|
||||
let worktree_id = cx.handle().entity_id().as_u64();
|
||||
let settings_location = Some(SettingsLocation {
|
||||
worktree_id: worktree_id as usize,
|
||||
path: Path::new(EMPTY_PATH),
|
||||
});
|
||||
|
||||
let settings = WorktreeSettings::get(settings_location, cx).clone();
|
||||
cx.observe_global::<SettingsStore>(move |this, cx| {
|
||||
if let Self::Local(this) = this {
|
||||
let settings = WorktreeSettings::get(settings_location, cx).clone();
|
||||
if settings != this.settings {
|
||||
this.settings = settings;
|
||||
this.restart_background_scanners(cx);
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
let mut snapshot = LocalSnapshot {
|
||||
ignores_by_parent_abs_path: Default::default(),
|
||||
git_repositories: Default::default(),
|
||||
|
@ -428,6 +402,24 @@ impl Worktree {
|
|||
);
|
||||
}
|
||||
|
||||
let worktree_id = snapshot.id();
|
||||
let settings_location = Some(SettingsLocation {
|
||||
worktree_id,
|
||||
path: Path::new(EMPTY_PATH),
|
||||
});
|
||||
|
||||
let settings = WorktreeSettings::get(settings_location, cx).clone();
|
||||
cx.observe_global::<SettingsStore>(move |this, cx| {
|
||||
if let Self::Local(this) = this {
|
||||
let settings = WorktreeSettings::get(settings_location, cx).clone();
|
||||
if settings != this.settings {
|
||||
this.settings = settings;
|
||||
this.restart_background_scanners(cx);
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
let (scan_requests_tx, scan_requests_rx) = channel::unbounded();
|
||||
let (path_prefixes_to_scan_tx, path_prefixes_to_scan_rx) = channel::unbounded();
|
||||
let mut worktree = LocalWorktree {
|
||||
|
@ -2978,30 +2970,6 @@ async fn build_gitignore(abs_path: &Path, fs: &dyn Fs) -> Result<Gitignore> {
|
|||
Ok(builder.build()?)
|
||||
}
|
||||
|
||||
impl WorktreeId {
|
||||
pub fn from_usize(handle_id: usize) -> Self {
|
||||
Self(handle_id)
|
||||
}
|
||||
|
||||
pub fn from_proto(id: u64) -> Self {
|
||||
Self(id as usize)
|
||||
}
|
||||
|
||||
pub fn to_proto(&self) -> u64 {
|
||||
self.0 as u64
|
||||
}
|
||||
|
||||
pub fn to_usize(&self) -> usize {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for WorktreeId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Worktree {
|
||||
type Target = Snapshot;
|
||||
|
||||
|
@ -3123,8 +3091,8 @@ impl language::File for File {
|
|||
.unwrap_or_else(|| OsStr::new(&self.worktree.read(cx).root_name))
|
||||
}
|
||||
|
||||
fn worktree_id(&self) -> usize {
|
||||
self.worktree.entity_id().as_u64() as usize
|
||||
fn worktree_id(&self, cx: &AppContext) -> WorktreeId {
|
||||
self.worktree.read(cx).id()
|
||||
}
|
||||
|
||||
fn is_deleted(&self) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue