Skip to main content

vs_shell/
path.rs

1//! Path helpers for locating runtime bins and scope-specific links.
2
3use std::path::{Path, PathBuf};
4
5/// Common filesystem paths used by `vs`.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct HomePaths {
8    /// Root home directory.
9    pub home: PathBuf,
10    /// Registry state directory.
11    pub registry_dir: PathBuf,
12    /// Installed plugin metadata directory.
13    pub plugins_dir: PathBuf,
14    /// Home-local cache directory used for command metadata.
15    pub cache_dir: PathBuf,
16    /// Installed runtime directory.
17    pub runtime_dir: PathBuf,
18    /// Global shim directory.
19    pub shims_dir: PathBuf,
20    /// Session state directory.
21    pub sessions_dir: PathBuf,
22    /// Global scope state directory.
23    pub global_dir: PathBuf,
24}
25
26/// Returns the canonical home layout.
27pub fn home_paths(home: &Path, runtime_root: &Path) -> HomePaths {
28    HomePaths {
29        home: home.to_path_buf(),
30        registry_dir: home.join("registry"),
31        plugins_dir: home.join("plugins"),
32        cache_dir: home.join("cache"),
33        runtime_dir: runtime_root.to_path_buf(),
34        shims_dir: home.join("shims"),
35        sessions_dir: home.join("sessions"),
36        global_dir: home.join("global"),
37    }
38}
39
40/// Returns the directory where a plugin version is installed.
41pub fn install_dir(runtime_root: &Path, plugin: &str, version: &str) -> PathBuf {
42    runtime_root.join(plugin).join("versions").join(version)
43}
44
45/// Returns the global `current` directory path for a plugin.
46pub fn global_current_dir(runtime_root: &Path, plugin: &str) -> PathBuf {
47    runtime_root.join(plugin).join("current")
48}
49
50/// Returns the project-local SDK link directory.
51pub fn project_sdk_dir(project_root: &Path, plugin: &str) -> PathBuf {
52    project_root.join(".vs").join("sdks").join(plugin)
53}
54
55/// Returns the default binary directory inside an installed runtime.
56pub fn bin_dir(install_dir: &Path) -> PathBuf {
57    install_dir.join("bin")
58}