Show full, absolute paths when displaying a local worktree

This commit is contained in:
Mikayla Maki 2022-10-17 13:35:45 -07:00
parent 354fefe61b
commit 1f161b9aa1
4 changed files with 25 additions and 4 deletions

View File

@ -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<()>;

View File

@ -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::<HomeDir>();
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);
}

View File

@ -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,

View File

@ -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");