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 Borrow<str> for ManifestName {
16 fn borrow(&self) -> &str {
17 &self.0
18 }
19}
20
21impl From<SharedString> for ManifestName {
22 fn from(value: SharedString) -> Self {
23 Self(value)
24 }
25}
26
27impl From<ManifestName> for SharedString {
28 fn from(value: ManifestName) -> Self {
29 value.0
30 }
31}
32
33impl AsRef<SharedString> for ManifestName {
34 fn as_ref(&self) -> &SharedString {
35 &self.0
36 }
37}
38
39/// 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.
40///
41/// 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.
42/// For example, given a path like `foo/bar/baz`, a depth of 2 would explore `foo/bar/baz` and `foo/bar`, but not `foo`.
43pub struct ManifestQuery {
44 /// Path to the file, relative to worktree root.
45 pub path: Arc<Path>,
46 pub depth: usize,
47 pub delegate: Arc<dyn ManifestDelegate>,
48}
49
50pub trait ManifestProvider {
51 fn name(&self) -> ManifestName;
52 fn search(&self, query: ManifestQuery) -> Option<Arc<Path>>;
53}
54
55pub trait ManifestDelegate: Send + Sync {
56 fn worktree_id(&self) -> WorktreeId;
57 fn exists(&self, path: &Path, is_dir: Option<bool>) -> bool;
58}