diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 78f5bcc82747bbe65bb993ca386af518519105a8..a2413f248ad86f01be0adc0aa5999ae8b35772c3 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -122,13 +122,9 @@ impl ItemView for Editor { } fn title(&self, cx: &AppContext) -> String { - let filename = self - .buffer() - .read(cx) - .file(cx) - .and_then(|file| file.file_name(cx)); - if let Some(name) = filename { - name.to_string_lossy().into() + let file = self.buffer().read(cx).file(cx); + if let Some(file) = file { + file.file_name(cx).to_string_lossy().into() } else { "untitled".into() } diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index cceef3992ef17f1309645424ba1c10816676bf00..3d0ef512d4a998a20b886f4fc93ace7ea4fb9c68 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -170,7 +170,7 @@ pub trait File { /// Returns the last component of this handle's absolute path. If this handle refers to the root /// of its worktree, then this method will return the name of the worktree itself. - fn file_name(&self, cx: &AppContext) -> Option; + fn file_name(&self, cx: &AppContext) -> OsString; fn is_deleted(&self) -> bool; diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index ea87a1434179a7c14ee272b22abd97f06ab19882..bbdaaeb00779276fad8a015748bba1cd5b052250 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -543,6 +543,10 @@ impl LocalWorktree { Ok((tree, scan_states_tx)) } + pub fn abs_path(&self) -> &Arc { + &self.abs_path + } + pub fn authorized_logins(&self) -> Vec { self.config.collaborators.clone() } @@ -1092,10 +1096,6 @@ impl Snapshot { } } - pub fn abs_path(&self) -> &Arc { - &self.abs_path - } - pub fn root_entry(&self) -> Option<&Entry> { self.entry_for_path("") } @@ -1360,29 +1360,26 @@ impl language::File for File { } fn abs_path(&self, cx: &AppContext) -> Option { - if self.is_local { - Some(self.worktree.read(cx).abs_path().join(&self.path)) - } else { - None - } + self.worktree + .read(cx) + .as_local() + .map(|local_worktree| local_worktree.abs_path.join(&self.path)) } fn full_path(&self, cx: &AppContext) -> PathBuf { let mut full_path = PathBuf::new(); - if let Some(worktree_name) = self.worktree.read(cx).abs_path().file_name() { - full_path.push(worktree_name); - } + full_path.push(self.worktree.read(cx).root_name()); full_path.push(&self.path); full_path } /// Returns the last component of this handle's absolute path. If this handle refers to the root /// of its worktree, then this method will return the name of the worktree itself. - fn file_name<'a>(&'a self, cx: &AppContext) -> Option { + fn file_name(&self, cx: &AppContext) -> OsString { self.path .file_name() - .or_else(|| self.worktree.read(cx).abs_path().file_name()) - .map(Into::into) + .map(|name| name.into()) + .unwrap_or_else(|| OsString::from(&self.worktree.read(cx).root_name)) } fn is_deleted(&self) -> bool {