Finished refactoring out fs and rope
This commit is contained in:
parent
0a8e2f6bb0
commit
0beb97547e
58 changed files with 328 additions and 223 deletions
|
@ -8,11 +8,23 @@ path = "src/fs.rs"
|
|||
|
||||
[dependencies]
|
||||
collections = { path = "../collections" }
|
||||
fsevent = { path = "../fsevent" }
|
||||
gpui = { path = "../gpui" }
|
||||
lsp = { path = "../lsp" }
|
||||
rope = { path = "../rope" }
|
||||
util = { path = "../util" }
|
||||
anyhow = "1.0.57"
|
||||
async-trait = "0.1"
|
||||
futures = "0.3"
|
||||
fsevent = { path = "../fsevent" }
|
||||
lazy_static = "1.4.0"
|
||||
parking_lot = "0.11.1"
|
||||
smol = "1.2.5"
|
||||
text = { path = "../text" }
|
||||
util = { path = "../util" }
|
||||
regex = "1.5"
|
||||
git2 = { version = "0.15", default-features = false }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
log = { version = "0.4.16", features = ["kv_unstable_serde"] }
|
||||
libc = "0.2"
|
||||
|
||||
[features]
|
||||
test-support = []
|
||||
|
|
|
@ -3,8 +3,15 @@ pub mod repository;
|
|||
use anyhow::{anyhow, Result};
|
||||
use fsevent::EventStream;
|
||||
use futures::{future::BoxFuture, Stream, StreamExt};
|
||||
use git2::Repository as LibGitRepository;
|
||||
use lazy_static::lazy_static;
|
||||
use parking_lot::Mutex as SyncMutex;
|
||||
use regex::Regex;
|
||||
use repository::GitRepository;
|
||||
use rope::Rope;
|
||||
use smol::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use std::borrow::Cow;
|
||||
use std::cmp;
|
||||
use std::sync::Arc;
|
||||
use std::{
|
||||
io,
|
||||
|
@ -13,7 +20,6 @@ use std::{
|
|||
pin::Pin,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
use text::Rope;
|
||||
use util::ResultExt;
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
|
@ -21,10 +27,14 @@ use collections::{btree_map, BTreeMap};
|
|||
#[cfg(any(test, feature = "test-support"))]
|
||||
use futures::lock::Mutex;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
use git::repository::FakeGitRepositoryState;
|
||||
use repository::FakeGitRepositoryState;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
use std::sync::Weak;
|
||||
|
||||
lazy_static! {
|
||||
static ref CARRIAGE_RETURNS_REGEX: Regex = Regex::new("\r\n|\r").unwrap();
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum LineEnding {
|
||||
Unix,
|
||||
|
@ -72,7 +82,7 @@ impl LineEnding {
|
|||
}
|
||||
}
|
||||
|
||||
fn normalize_arc(text: Arc<str>) -> Arc<str> {
|
||||
pub fn normalize_arc(text: Arc<str>) -> Arc<str> {
|
||||
if let Cow::Owned(replaced) = CARRIAGE_RETURNS_REGEX.replace_all(&text, "\n") {
|
||||
replaced.into()
|
||||
} else {
|
||||
|
@ -141,6 +151,33 @@ pub struct Metadata {
|
|||
pub is_dir: bool,
|
||||
}
|
||||
|
||||
impl From<lsp::CreateFileOptions> for CreateOptions {
|
||||
fn from(options: lsp::CreateFileOptions) -> Self {
|
||||
Self {
|
||||
overwrite: options.overwrite.unwrap_or(false),
|
||||
ignore_if_exists: options.ignore_if_exists.unwrap_or(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<lsp::RenameFileOptions> for RenameOptions {
|
||||
fn from(options: lsp::RenameFileOptions) -> Self {
|
||||
Self {
|
||||
overwrite: options.overwrite.unwrap_or(false),
|
||||
ignore_if_exists: options.ignore_if_exists.unwrap_or(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<lsp::DeleteFileOptions> for RemoveOptions {
|
||||
fn from(options: lsp::DeleteFileOptions) -> Self {
|
||||
Self {
|
||||
recursive: options.recursive.unwrap_or(false),
|
||||
ignore_if_not_exists: options.ignore_if_not_exists.unwrap_or(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RealFs;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
@ -340,7 +377,7 @@ enum FakeFsEntry {
|
|||
inode: u64,
|
||||
mtime: SystemTime,
|
||||
entries: BTreeMap<String, Arc<Mutex<FakeFsEntry>>>,
|
||||
git_repo_state: Option<Arc<SyncMutex<git::repository::FakeGitRepositoryState>>>,
|
||||
git_repo_state: Option<Arc<SyncMutex<repository::FakeGitRepositoryState>>>,
|
||||
},
|
||||
Symlink {
|
||||
target: PathBuf,
|
||||
|
@ -952,7 +989,7 @@ impl Fs for FakeFs {
|
|||
Arc::new(SyncMutex::new(FakeGitRepositoryState::default()))
|
||||
})
|
||||
.clone();
|
||||
Some(git::repository::FakeGitRepository::open(state))
|
||||
Some(repository::FakeGitRepository::open(state))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue