manifest.rs

 1use std::{borrow::Borrow, sync::Arc};
 2
 3use gpui::SharedString;
 4use settings::WorktreeId;
 5use util::rel_path::RelPath;
 6
 7#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
 8pub struct ManifestName(SharedString);
 9
10impl Borrow<SharedString> for ManifestName {
11    fn borrow(&self) -> &SharedString {
12        &self.0
13    }
14}
15
16impl Borrow<str> for ManifestName {
17    fn borrow(&self) -> &str {
18        &self.0
19    }
20}
21
22impl From<SharedString> for ManifestName {
23    fn from(value: SharedString) -> Self {
24        Self(value)
25    }
26}
27
28impl From<ManifestName> for SharedString {
29    fn from(value: ManifestName) -> Self {
30        value.0
31    }
32}
33
34impl AsRef<SharedString> for ManifestName {
35    fn as_ref(&self) -> &SharedString {
36        &self.0
37    }
38}
39
40/// Represents a manifest query; given a path to a file, [ManifestSearcher] is tasked with finding a path to the directory containing the manifest for that file.
41///
42/// Since parts of the path might have already been explored, there's an additional `depth` parameter that indicates to what ancestry level a given path should be explored.
43/// For example, given a path like `foo/bar/baz`, a depth of 2 would explore `foo/bar/baz` and `foo/bar`, but not `foo`.
44pub struct ManifestQuery {
45    /// Path to the file, relative to worktree root.
46    pub path: Arc<RelPath>,
47    pub depth: usize,
48    pub delegate: Arc<dyn ManifestDelegate>,
49}
50
51pub trait ManifestProvider {
52    fn name(&self) -> ManifestName;
53    fn search(&self, query: ManifestQuery) -> Option<Arc<RelPath>>;
54}
55
56pub trait ManifestDelegate: Send + Sync {
57    fn worktree_id(&self) -> WorktreeId;
58    fn exists(&self, path: &RelPath, is_dir: Option<bool>) -> bool;
59}