Skip to main content

lean_ctx/core/editor_registry/
paths.rs

1use std::path::{Path, PathBuf};
2
3pub fn zed_settings_path(home: &std::path::Path) -> PathBuf {
4    if cfg!(target_os = "macos") {
5        home.join("Library/Application Support/Zed/settings.json")
6    } else {
7        home.join(".config/zed/settings.json")
8    }
9}
10
11pub fn zed_config_dir(home: &std::path::Path) -> PathBuf {
12    if cfg!(target_os = "macos") {
13        home.join("Library/Application Support/Zed")
14    } else {
15        home.join(".config/zed")
16    }
17}
18
19pub fn vscode_mcp_path() -> PathBuf {
20    if let Some(home) = dirs::home_dir() {
21        #[cfg(target_os = "macos")]
22        {
23            return home.join("Library/Application Support/Code/User/mcp.json");
24        }
25        #[cfg(target_os = "linux")]
26        {
27            return home.join(".config/Code/User/mcp.json");
28        }
29        #[cfg(target_os = "windows")]
30        {
31            if let Ok(appdata) = std::env::var("APPDATA") {
32                return PathBuf::from(appdata).join("Code/User/mcp.json");
33            }
34        }
35        #[allow(unreachable_code)]
36        home.join(".config/Code/User/mcp.json")
37    } else {
38        PathBuf::from("/nonexistent")
39    }
40}
41
42pub fn qoder_mcp_path(home: &Path) -> PathBuf {
43    #[cfg(target_os = "windows")]
44    {
45        if let Ok(appdata) = std::env::var("APPDATA") {
46            return PathBuf::from(appdata)
47                .join("Qoder")
48                .join("SharedClientCache")
49                .join("mcp.json");
50        }
51    }
52    home.join(".qoder").join("mcp.json")
53}
54
55#[cfg(target_os = "macos")]
56pub fn qoder_mcp_paths(home: &Path) -> Vec<PathBuf> {
57    let mut paths = vec![qoder_mcp_path(home)];
58    paths.push(home.join("Library/Application Support/Qoder/User/mcp.json"));
59    paths.push(home.join("Library/Application Support/Qoder/SharedClientCache/mcp.json"));
60    paths
61}
62
63#[cfg(not(target_os = "macos"))]
64pub fn qoder_mcp_paths(home: &Path) -> Vec<PathBuf> {
65    vec![qoder_mcp_path(home)]
66}
67
68#[allow(unreachable_code)]
69pub fn cline_mcp_path() -> PathBuf {
70    #[cfg(target_os = "windows")]
71    {
72        if let Ok(appdata) = std::env::var("APPDATA") {
73            return PathBuf::from(appdata).join(
74                "Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json",
75            );
76        }
77        return PathBuf::from("/nonexistent");
78    }
79
80    let Some(home) = dirs::home_dir() else {
81        return PathBuf::from("/nonexistent");
82    };
83    #[cfg(target_os = "macos")]
84    {
85        return home.join("Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json");
86    }
87    #[cfg(target_os = "linux")]
88    {
89        return home.join(".config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json");
90    }
91    PathBuf::from("/nonexistent")
92}
93
94#[allow(unreachable_code)]
95pub fn roo_mcp_path() -> PathBuf {
96    #[cfg(target_os = "windows")]
97    {
98        if let Ok(appdata) = std::env::var("APPDATA") {
99            return PathBuf::from(appdata)
100                .join("Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json");
101        }
102        return PathBuf::from("/nonexistent");
103    }
104
105    let Some(home) = dirs::home_dir() else {
106        return PathBuf::from("/nonexistent");
107    };
108    #[cfg(target_os = "macos")]
109    {
110        return home.join("Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json");
111    }
112    #[cfg(target_os = "linux")]
113    {
114        return home.join(".config/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json");
115    }
116    PathBuf::from("/nonexistent")
117}
118
119pub fn qoder_settings_path(home: &Path) -> PathBuf {
120    #[cfg(target_os = "windows")]
121    {
122        if let Ok(appdata) = std::env::var("APPDATA") {
123            return PathBuf::from(appdata)
124                .join("Qoder")
125                .join("SharedClientCache")
126                .join("mcp.json");
127        }
128    }
129    home.join(".qoder/mcp.json")
130}
131
132pub fn qoder_all_mcp_paths(home: &Path) -> Vec<PathBuf> {
133    let paths = vec![qoder_settings_path(home)];
134    #[cfg(target_os = "macos")]
135    let paths = {
136        let mut paths = paths;
137        paths.push(home.join("Library/Application Support/Qoder/User/mcp.json"));
138        paths.push(home.join("Library/Application Support/Qoder/SharedClientCache/mcp.json"));
139        paths
140    };
141    paths
142}
143
144pub fn qoderwork_mcp_path(home: &Path) -> PathBuf {
145    home.join(".qoderwork/mcp.json")
146}
147
148pub fn claude_mcp_json_path(home: &Path) -> PathBuf {
149    if let Ok(dir) = std::env::var("CLAUDE_CONFIG_DIR") {
150        let dir = dir.trim();
151        if !dir.is_empty() {
152            return PathBuf::from(dir).join(".claude.json");
153        }
154    }
155    home.join(".claude.json")
156}
157
158pub fn claude_state_dir(home: &Path) -> PathBuf {
159    if let Ok(dir) = std::env::var("CLAUDE_CONFIG_DIR") {
160        let dir = dir.trim();
161        if !dir.is_empty() {
162            return PathBuf::from(dir);
163        }
164    }
165    home.join(".claude")
166}
167
168pub fn claude_rules_dir(home: &Path) -> PathBuf {
169    claude_state_dir(home).join("rules")
170}
171
172#[cfg(all(test, target_os = "macos"))]
173mod tests {
174    use super::*;
175
176    #[test]
177    #[cfg(target_os = "macos")]
178    fn qoder_mcp_paths_include_macos_user_and_shared_cache_locations() {
179        let home = Path::new("/Users/tester");
180        let paths = qoder_mcp_paths(home);
181
182        assert_eq!(
183            paths,
184            vec![
185                home.join(".qoder/mcp.json"),
186                home.join("Library/Application Support/Qoder/User/mcp.json"),
187                home.join("Library/Application Support/Qoder/SharedClientCache/mcp.json"),
188            ]
189        );
190    }
191}