manifest.rs

 1use std::{borrow::Borrow, path::Path, sync::Arc};
 2
 3use gpui::SharedString;
 4
 5use crate::LspAdapterDelegate;
 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 From<SharedString> for ManifestName {
17    fn from(value: SharedString) -> Self {
18        Self(value)
19    }
20}
21
22impl From<ManifestName> for SharedString {
23    fn from(value: ManifestName) -> Self {
24        value.0
25    }
26}
27
28impl AsRef<SharedString> for ManifestName {
29    fn as_ref(&self) -> &SharedString {
30        &self.0
31    }
32}
33
34/// 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.
35///
36/// 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.
37/// For example, given a path like `foo/bar/baz`, a depth of 2 would explore `foo/bar/baz` and `foo/bar`, but not `foo`.
38pub struct ManifestQuery {
39    /// Path to the file, relative to worktree root.
40    pub path: Arc<Path>,
41    pub depth: usize,
42    pub delegate: Arc<dyn LspAdapterDelegate>,
43}
44
45pub trait ManifestProvider {
46    fn name(&self) -> ManifestName;
47    fn search(&self, query: ManifestQuery) -> Option<Arc<Path>>;
48}