Refactor: Make it possible to share a remote worktree (#12775)

This PR is an internal refactor in preparation for remote editing. It
restructures the public interface of `Worktree`, reducing the number of
call sites that assume that a worktree is local or remote.

* The Project no longer calls `worktree.as_local_mut().unwrap()` in code
paths related to basic file operations
* Fewer code paths in the app rely on the worktree's `LocalSnapshot`
* Worktree-related RPC message handling is more fully encapsulated by
the `Worktree` type.

to do:
* [x] file manipulation operations
* [x] sending worktree updates when sharing

for later
* opening buffers
* updating open buffers upon worktree changes

Release Notes:

- N/A
This commit is contained in:
Max Brunsfeld 2024-06-07 12:53:01 -07:00 committed by GitHub
parent aa60fc2f19
commit e174f16d50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 952 additions and 839 deletions

View file

@ -343,36 +343,40 @@ impl<P> PathLikeWithPosition<P> {
#[derive(Clone, Debug)]
pub struct PathMatcher {
maybe_path: PathBuf,
source: String,
glob: GlobMatcher,
}
impl std::fmt::Display for PathMatcher {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.maybe_path.to_string_lossy().fmt(f)
self.source.fmt(f)
}
}
impl PartialEq for PathMatcher {
fn eq(&self, other: &Self) -> bool {
self.maybe_path.eq(&other.maybe_path)
self.source.eq(&other.source)
}
}
impl Eq for PathMatcher {}
impl PathMatcher {
pub fn new(maybe_glob: &str) -> Result<Self, globset::Error> {
pub fn new(source: &str) -> Result<Self, globset::Error> {
Ok(PathMatcher {
glob: Glob::new(maybe_glob)?.compile_matcher(),
maybe_path: PathBuf::from(maybe_glob),
glob: Glob::new(source)?.compile_matcher(),
source: String::from(source),
})
}
pub fn source(&self) -> &str {
&self.source
}
pub fn is_match<P: AsRef<Path>>(&self, other: P) -> bool {
let other_path = other.as_ref();
other_path.starts_with(&self.maybe_path)
|| other_path.ends_with(&self.maybe_path)
other_path.starts_with(Path::new(&self.source))
|| other_path.ends_with(Path::new(&self.source))
|| self.glob.is_match(other_path)
|| self.check_with_end_separator(other_path)
}