MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / load_from_file

Method load_from_file

crates/opencode-config/src/loader.rs:38–61  ·  view source on GitHub ↗
(&mut self, path: P)

Source from the content-addressed store, hash-verified

36 }
37
38 pub fn load_from_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
39 let path = path.as_ref();
40 if !path.exists() {
41 return Ok(());
42 }
43
44 let content = fs::read_to_string(path)
45 .with_context(|| format!("Failed to read config file: {:?}", path))?;
46
47 // Apply {env:VAR} substitution
48 let content = substitute_env_vars(&content);
49
50 // Apply {file:path} substitution
51 let base_dir = path.parent().unwrap_or(Path::new("."));
52 let content = resolve_file_references(&content, base_dir)
53 .with_context(|| format!("Failed to resolve file references in: {:?}", path))?;
54
55 let config: Config = parse_jsonc(&content)
56 .with_context(|| format!("Failed to parse config file: {:?}", path))?;
57
58 self.config.merge(config);
59 self.config_paths.push(path.to_path_buf());
60 Ok(())
61 }
62
63 pub fn load_global(&mut self) -> Result<()> {
64 let global_config_path = get_global_config_path();

Callers 6

load_globalMethod · 0.45
load_projectMethod · 0.45
load_from_envMethod · 0.45
load_allMethod · 0.45
load_managed_configMethod · 0.45
loads_jsonc_config_fileFunction · 0.45

Calls 6

substitute_env_varsFunction · 0.85
newFunction · 0.85
resolve_file_referencesFunction · 0.85
parse_jsoncFunction · 0.85
existsMethod · 0.80
mergeMethod · 0.45

Tested by 1

loads_jsonc_config_fileFunction · 0.36