lean_ctx/core/editor_registry/writers/
mod.rs1use super::types::{ConfigType, EditorTarget};
5
6mod install;
7mod shared;
8mod uninstall;
9
10pub use shared::auto_approve_tools;
11pub use uninstall::remove_lean_ctx_mcp_server;
12#[allow(clippy::wildcard_imports)]
15use install::*;
16#[allow(clippy::wildcard_imports)]
17use uninstall::*;
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum WriteAction {
21 Created,
22 Updated,
23 Already,
24}
25
26#[derive(Debug, Clone, Copy, Default)]
27pub struct WriteOptions {
28 pub overwrite_invalid: bool,
29}
30
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct WriteResult {
33 pub action: WriteAction,
34 pub note: Option<String>,
35}
36
37pub fn write_config(target: &EditorTarget, binary: &str) -> Result<WriteResult, String> {
38 write_config_with_options(target, binary, WriteOptions::default())
39}
40
41pub fn write_config_with_options(
42 target: &EditorTarget,
43 binary: &str,
44 opts: WriteOptions,
45) -> Result<WriteResult, String> {
46 if let Some(parent) = target.config_path.parent() {
47 std::fs::create_dir_all(parent).map_err(|e| e.to_string())?;
48 }
49
50 match target.config_type {
51 ConfigType::McpJson => write_mcp_json(target, binary, opts),
52 ConfigType::Zed => write_zed_config(target, binary, opts),
53 ConfigType::Codex => write_codex_config(target, binary),
54 ConfigType::VsCodeMcp => write_vscode_mcp(target, binary, opts),
55 ConfigType::CopilotCli => write_copilot_cli(target, binary, opts),
56 ConfigType::OpenCode => write_opencode_config(target, binary, opts),
57 ConfigType::Crush => write_crush_config(target, binary, opts),
58 ConfigType::JetBrains => write_jetbrains_config(target, binary, opts),
59 ConfigType::Amp => write_amp_config(target, binary, opts),
60 ConfigType::HermesYaml => write_hermes_yaml(target, binary, opts),
61 ConfigType::GeminiSettings => write_gemini_settings(target, binary, opts),
62 ConfigType::QoderSettings => write_qoder_settings(target, binary, opts),
63 ConfigType::AugmentVsCode => write_augment_vscode(target, binary, opts),
64 ConfigType::OpenClaw => write_openclaw_config(target, binary, opts),
65 ConfigType::VibeToml => write_vibe_toml(target, binary, opts),
66 ConfigType::CommandCode => write_commandcode_config(target, binary, opts),
67 }
68}
69
70pub fn remove_lean_ctx_server(
71 target: &EditorTarget,
72 opts: WriteOptions,
73) -> Result<WriteResult, String> {
74 match target.config_type {
75 ConfigType::McpJson
76 | ConfigType::JetBrains
77 | ConfigType::GeminiSettings
78 | ConfigType::QoderSettings
79 | ConfigType::CommandCode => remove_lean_ctx_mcp_server(&target.config_path, opts),
80 ConfigType::VsCodeMcp | ConfigType::CopilotCli => {
81 remove_lean_ctx_vscode_server(&target.config_path, opts)
82 }
83 ConfigType::Codex => remove_lean_ctx_codex_server(&target.config_path),
84 ConfigType::OpenCode | ConfigType::Crush => {
85 remove_lean_ctx_named_json_server(&target.config_path, "mcp", opts)
86 }
87 ConfigType::Zed => {
88 remove_lean_ctx_named_json_server(&target.config_path, "context_servers", opts)
89 }
90 ConfigType::Amp => remove_lean_ctx_amp_server(&target.config_path, opts),
91 ConfigType::HermesYaml => remove_lean_ctx_hermes_yaml_server(&target.config_path),
92 ConfigType::AugmentVsCode => {
93 remove_lean_ctx_augment_vscode_server(&target.config_path, opts)
94 }
95 ConfigType::OpenClaw => remove_lean_ctx_openclaw_server(&target.config_path, opts),
96 ConfigType::VibeToml => remove_lean_ctx_vibe_toml_server(&target.config_path, opts),
97 }
98}
99
100#[cfg(test)]
101mod tests;