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    /// Installed runtime cache directory.
15    pub cache_dir: PathBuf,
16    /// Global shim directory.
17    pub shims_dir: PathBuf,
18    /// Session state directory.
19    pub sessions_dir: PathBuf,
20    /// Global scope state directory.
21    pub global_dir: PathBuf,
22}
23
24/// Returns the canonical home layout.
25pub fn home_paths(home: &Path) -> HomePaths {
26    HomePaths {
27        home: home.to_path_buf(),
28        registry_dir: home.join("registry"),
29        plugins_dir: home.join("plugins"),
30        cache_dir: home.join("cache"),
31        shims_dir: home.join("shims"),
32        sessions_dir: home.join("sessions"),
33        global_dir: home.join("global"),
34    }
35}
36
37/// Returns the directory where a plugin version is installed.
38pub fn install_dir(home: &Path, plugin: &str, version: &str) -> PathBuf {
39    home.join("cache")
40        .join(plugin)
41        .join("versions")
42        .join(version)
43}
44
45/// Returns the global `current` directory path for a plugin.
46pub fn global_current_dir(home: &Path, plugin: &str) -> PathBuf {
47    home.join("cache").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}