Skip to main content

vs_shell/
path.rs

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