pub struct MarkerResolver { /* private fields */ }Expand description
The built-in ProjectResolver: walk up for a marker, else pwd.
§Examples
use lattice_core::{MarkerResolver, ProjectKind, ProjectResolver};
let root = std::env::temp_dir().join(format!("lattice-doc-project-{}", std::process::id()));
std::fs::create_dir_all(root.join("src"))?;
std::fs::write(root.join("Cargo.toml"), "")?;
let resolver = MarkerResolver::with_default_markers(std::env::temp_dir());
// A file that does not exist yet still resolves, via its parent.
let project = resolver.for_path(&root.join("src/main.rs"));
assert_eq!(project.root, root);
assert_eq!(project.kind, ProjectKind::Marker("Cargo.toml".into()));
assert!(project.is_rooted());Implementations§
Source§impl MarkerResolver
impl MarkerResolver
Sourcepub fn new(markers: Vec<String>, pwd: PathBuf) -> Self
pub fn new(markers: Vec<String>, pwd: PathBuf) -> Self
Build a resolver over markers, falling back to pwd.
The marker list arrives as a parameter rather than being read
from a typed option here because lattice-config depends on
this crate — core cannot name the option type. The host reads
project.root-markers and passes it in, which is also what
keeps this crate free of a config dependency for one
Vec<String>.
Sourcepub fn with_default_markers(pwd: PathBuf) -> Self
pub fn with_default_markers(pwd: PathBuf) -> Self
The default marker set (DEFAULT_ROOT_MARKERS) over pwd.
Trait Implementations§
Source§impl Debug for MarkerResolver
impl Debug for MarkerResolver
Source§impl ProjectResolver for MarkerResolver
impl ProjectResolver for MarkerResolver
Source§fn for_path(&self, path: &Path) -> Project
fn for_path(&self, path: &Path) -> Project
The project containing
path, which may be a file or a
directory. Total — see the module docs.Source§fn set_pwd(&self, pwd: PathBuf)
fn set_pwd(&self, pwd: PathBuf)
Re-point the working directory the
ProjectKind::Pwd fallback
uses. Called on :cd. Drops the cache, because entries that
fell back to the old pwd are now wrong.Source§fn set_markers(&self, markers: Vec<String>)
fn set_markers(&self, markers: Vec<String>)
Replace the marker set. Called when
project.root-markers
changes, and at boot once config has been applied. Read moreSource§fn invalidate(&self)
fn invalidate(&self)
Drop every cached answer —
:project-refresh, after a git init
mid-session. The cache is an optimisation and never a source of
truth, so this changes latency and nothing else.Auto Trait Implementations§
impl !Freeze for MarkerResolver
impl RefUnwindSafe for MarkerResolver
impl Send for MarkerResolver
impl Sync for MarkerResolver
impl Unpin for MarkerResolver
impl UnsafeUnpin for MarkerResolver
impl UnwindSafe for MarkerResolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more