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 }
66}
67
68pub fn remove_lean_ctx_server(
69 target: &EditorTarget,
70 opts: WriteOptions,
71) -> Result<WriteResult, String> {
72 match target.config_type {
73 ConfigType::McpJson
74 | ConfigType::JetBrains
75 | ConfigType::GeminiSettings
76 | ConfigType::QoderSettings => remove_lean_ctx_mcp_server(&target.config_path, opts),
77 ConfigType::VsCodeMcp | ConfigType::CopilotCli => {
78 remove_lean_ctx_vscode_server(&target.config_path, opts)
79 }
80 ConfigType::Codex => remove_lean_ctx_codex_server(&target.config_path),
81 ConfigType::OpenCode | ConfigType::Crush => {
82 remove_lean_ctx_named_json_server(&target.config_path, "mcp", opts)
83 }
84 ConfigType::Zed => {
85 remove_lean_ctx_named_json_server(&target.config_path, "context_servers", opts)
86 }
87 ConfigType::Amp => remove_lean_ctx_amp_server(&target.config_path, opts),
88 ConfigType::HermesYaml => remove_lean_ctx_hermes_yaml_server(&target.config_path),
89 ConfigType::AugmentVsCode => {
90 remove_lean_ctx_augment_vscode_server(&target.config_path, opts)
91 }
92 ConfigType::OpenClaw => remove_lean_ctx_openclaw_server(&target.config_path, opts),
93 }
94}
95
96#[cfg(test)]
97mod tests;