Skip to main content

pmpx_plugin/
context.rs

1//! What the host hands to a plugin: the project root and the matched files.
2
3use std::path::PathBuf;
4
5/// The context the host passes to the plugin. Read-only.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct Context {
8    /// Project root. For building log / error messages only -- it must not be used to read files,
9    /// see the constraint list in the crate docs.
10    pub project_root: PathBuf,
11
12    /// The files this detection matched, relative to `project_root`.
13    /// This is the plugin's only channel for learning "what the project looks like". Example: the
14    /// yarn plugin distinguishes classic from berry via `has_matched(".yarnrc.yml")` without
15    /// reading a single file.
16    pub matched: Vec<String>,
17}
18
19impl Context {
20    /// Whether one of the matched files is this one -- the standard way for a plugin to branch on
21    /// shape.
22    pub fn has_matched(&self, file: &str) -> bool {
23        self.matched.iter().any(|m| m == file)
24    }
25}