From 1f161b9aa1154629fa2041812e42529d3af2201f Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 17 Oct 2022 13:35:45 -0700 Subject: [PATCH] Show full, absolute paths when displaying a local worktree --- crates/fs/src/fs.rs | 3 +++ crates/project/src/worktree.rs | 20 ++++++++++++++++++-- crates/zed/src/main.rs | 4 +++- crates/zed/src/paths.rs | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rs index 2061d3734b..c1ea6feee5 100644 --- a/crates/fs/src/fs.rs +++ b/crates/fs/src/fs.rs @@ -92,6 +92,9 @@ impl LineEnding { } } } + +pub struct HomeDir(pub PathBuf); + #[async_trait::async_trait] pub trait Fs: Send + Sync { async fn create_dir(&self, path: &Path) -> Result<()>; diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 383c9ac35b..bafabc6761 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -5,8 +5,8 @@ use anyhow::{anyhow, Context, Result}; use client::{proto, Client}; use clock::ReplicaId; use collections::{HashMap, VecDeque}; -use fs::LineEnding; use fs::{repository::GitRepository, Fs}; +use fs::{HomeDir, LineEnding}; use futures::{ channel::{ mpsc::{self, UnboundedSender}, @@ -1839,7 +1839,23 @@ impl language::File for File { fn full_path(&self, cx: &AppContext) -> PathBuf { let mut full_path = PathBuf::new(); - full_path.push(self.worktree.read(cx).root_name()); + let worktree = self.worktree.read(cx); + if worktree.is_visible() { + full_path.push(worktree.root_name()); + } else { + let home_dir = cx.global::(); + let local_path = worktree.as_local().map(|local| local.abs_path.clone()); + if let Some(path) = local_path { + if let Ok(path) = path.strip_prefix(home_dir.0.as_path()) { + full_path.push("~"); + full_path.push(path); + } else { + full_path.push(path) + } + } else { + full_path.push(Path::new("/host-filesystem/")) + } + } if self.path.components().next().is_some() { full_path.push(&self.path); } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index a921bc2680..e62317146c 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -23,7 +23,7 @@ use isahc::{config::Configurable, Request}; use language::LanguageRegistry; use log::LevelFilter; use parking_lot::Mutex; -use project::{Fs, ProjectStore}; +use project::{Fs, HomeDir, ProjectStore}; use serde_json::json; use settings::{ self, settings_file::SettingsFile, KeymapFileContent, Settings, SettingsFileContent, @@ -99,6 +99,8 @@ fn main() { let (settings_file_content, keymap_file) = cx.background().block(config_files).unwrap(); + cx.set_global(HomeDir(zed::paths::HOME.to_path_buf())); + //Setup settings global before binding actions cx.set_global(SettingsFile::new( &*zed::paths::SETTINGS, diff --git a/crates/zed/src/paths.rs b/crates/zed/src/paths.rs index d6d99288c7..02db8ab55e 100644 --- a/crates/zed/src/paths.rs +++ b/crates/zed/src/paths.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; lazy_static::lazy_static! { - static ref HOME: PathBuf = dirs::home_dir().expect("failed to determine home directory"); + pub static ref HOME: PathBuf = dirs::home_dir().expect("failed to determine home directory"); pub static ref CONFIG_DIR: PathBuf = HOME.join(".config").join("zed"); pub static ref LOGS_DIR: PathBuf = HOME.join("Library/Logs/Zed"); pub static ref LANGUAGES_DIR: PathBuf = HOME.join("Library/Application Support/Zed/languages");