1use std::{borrow::Borrow, path::Path, sync::Arc};
2
3use gpui::SharedString;
4use settings::WorktreeId;
5
6#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
7pub struct ManifestName(SharedString);
8
9impl Borrow<SharedString> for ManifestName {
10 fn borrow(&self) -> &SharedString {
11 &self.0
12 }
13}
14
15impl From<SharedString> for ManifestName {
16 fn from(value: SharedString) -> Self {
17 Self(value)
18 }
19}
20
21impl From<ManifestName> for SharedString {
22 fn from(value: ManifestName) -> Self {
23 value.0
24 }
25}
26
27impl AsRef<SharedString> for ManifestName {
28 fn as_ref(&self) -> &SharedString {
29 &self.0
30 }
31}
32
33/// 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.
34///
35/// 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.
36/// For example, given a path like `foo/bar/baz`, a depth of 2 would explore `foo/bar/baz` and `foo/bar`, but not `foo`.
37pub struct ManifestQuery {
38 /// Path to the file, relative to worktree root.
39 pub path: Arc<Path>,
40 pub depth: usize,
41 pub delegate: Arc<dyn ManifestDelegate>,
42}
43
44pub trait ManifestProvider {
45 fn name(&self) -> ManifestName;
46 fn search(&self, query: ManifestQuery) -> Option<Arc<Path>>;
47}
48
49pub trait ManifestDelegate: Send + Sync {
50 fn worktree_id(&self) -> WorktreeId;
51 fn exists(&self, path: &Path, is_dir: Option<bool>) -> bool;
52}