pub struct WorkspacePathDisplay { /* private fields */ }Expand description
Renders workspace-relative display paths for many entries under one root.
workspace_relative_display canonicalizes the workspace root on every
call. That is invisible for a single diagnostic, but directory listings and
tree walks render one path per entry, so the repeated realpath dominates
the loop while always producing the same answer. This type resolves the
root once and reuses it.
Implementations§
Source§impl WorkspacePathDisplay
impl WorkspacePathDisplay
Sourcepub fn new(workspace_root: &Path) -> Self
pub fn new(workspace_root: &Path) -> Self
Resolve the workspace root once, reusing it for every later Self::render.
Sourcepub fn render(&self, path: &Path) -> String
pub fn render(&self, path: &Path) -> String
Render path relative to the workspace, matching
workspace_relative_display exactly.
Sourcepub fn render_entry(&self, path: &Path, file_type: Option<FileType>) -> String
pub fn render_entry(&self, path: &Path, file_type: Option<FileType>) -> String
Render a path produced by a traversal that cannot cross a symlink.
§Preconditions
The caller must know both of the following, which hold for entries from
build_default_walker (it does not
follow links) and for direct children of an already canonical directory:
file_typeis the entry’s own type, orNonewhen unknown;- no ancestor between the workspace root and
pathis a symlink.
Under those conditions the resolved path equals the lexically stripped
path, so the per-entry realpath is redundant. Anything else — an
unknown type, or a symlinked leaf that may point outside the workspace —
falls back to Self::render, which stays authoritative.
Sourcepub fn relative_lexical(&self, path: &Path) -> Option<String>
pub fn relative_lexical(&self, path: &Path) -> Option<String>
Strip whichever known root path lexically sits under, without any syscall.
This is Self::render_entry’s core, exposed for callers that must
build keys rather than display strings (for example indexing children
by parent directory). It carries the same preconditions documented on
Self::render_entry: the caller must know the path came from a
traversal that cannot cross a symlink.
Returns None for relative paths and for any ./.. component, where
lexical stripping would disagree with the resolved form; callers fall
back to Self::render.