Skip to main content

code_ranker_plugin_api/
detection.rs

1//! Generic, language-agnostic project-detection helpers shared by plugins.
2//!
3//! These answer "is this a project of kind X on disk?" — a concern distinct from
4//! the parsing contract in [`plugin`](crate::plugin). Keeping them here lets every
5//! plugin reuse the helper without depending on a sibling plugin or pulling
6//! detection logic into the contract.
7
8use std::path::Path;
9
10/// Return `true` when `workspace` contains the given marker file. A generic,
11/// language-agnostic detection helper for marker-based plugins (e.g. JS →
12/// `"package.json"`, TS → `"tsconfig.json"`).
13pub fn detect_with_marker(workspace: &Path, marker: &str) -> bool {
14    workspace.join(marker).exists()
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20
21    #[test]
22    fn detect_with_marker_checks_file_presence() {
23        let dir = std::env::temp_dir();
24        // a marker that (almost certainly) does not exist
25        assert!(!detect_with_marker(&dir, "code-ranker-no-such-marker.xyz"));
26    }
27}