nativeview_cli/hot_diff/workspace.rs
1//! Workspace root discovery and canonical workspace-relative path normalization shared by
2//! `WatchCache`, `hot_diff`, and `view_diff`.
3//!
4//! Single-sourced directly from [`nativeview_view_syntax::resolve_workspace_rel_file`] so
5//! `AnchorKey` hashes match `view-macros` 1-to-1 across crates, standalone examples, and OSes.
6
7use std::path::Path;
8
9/// Normalizes `path` to a workspace-relative (or standalone crate-relative) POSIX path matching
10/// `file!()` / `Span::call_site().file()` so `AnchorKey`s hash
11/// identically in `nv dev` (absolute paths from `notify`) and the compiled app.
12pub fn workspace_relative_path(path: &Path) -> String {
13 nativeview_view_syntax::resolve_workspace_rel_file(path, None)
14}
15
16/// Normalizes `path` relative to `explicit_root` (when `path` lies inside it) or falls back to
17/// Cargo manifest `[workspace]` / crate-root discovery.
18pub fn workspace_relative_path_in(path: &Path, explicit_root: Option<&Path>) -> String {
19 nativeview_view_syntax::resolve_workspace_rel_file(path, explicit_root)
20}