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

Method resolve_config_path

crates/opencode-session/src/instruction.rs:409–461  ·  view source on GitHub ↗

Resolve a single config instruction entry to concrete file paths.

(
        &self,
        instruction: &str,
        project_dir: &Path,
        worktree: &Path,
    )

Source from the content-addressed store, hash-verified

407 }
408 /// Resolve a single config instruction entry to concrete file paths.
409 fn resolve_config_path(
410 &self,
411 instruction: &str,
412 project_dir: &Path,
413 worktree: &Path,
414 ) -> Vec<PathBuf> {
415 let mut expanded = instruction.to_string();
416
417 // Expand ~/
418 if expanded.starts_with("~/") {
419 if let Some(home) = dirs::home_dir() {
420 expanded = home.join(&expanded[2..]).to_string_lossy().to_string();
421 }
422 }
423
424 let path = Path::new(&expanded);
425
426 if path.is_absolute() {
427 if is_glob_pattern(&expanded) {
428 expand_glob(&expanded, Path::new("/"))
429 } else if path.is_file() {
430 vec![path.to_path_buf()]
431 } else {
432 Vec::new()
433 }
434 } else if is_glob_pattern(&expanded) {
435 // Relative glob: walk up from project_dir to worktree
436 if !is_project_config_disabled() {
437 glob_up(&expanded, project_dir, worktree)
438 } else if let Some(dir) = opencode_config_dir_env() {
439 glob_up(&expanded, Path::new(&dir), Path::new(&dir))
440 } else {
441 warn!(
442 "Skipping relative instruction \"{}\" - no OPENCODE_CONFIG_DIR set while project config is disabled",
443 instruction
444 );
445 Vec::new()
446 }
447 } else {
448 // Relative plain path: walk up from project_dir to worktree
449 if !is_project_config_disabled() {
450 find_up(&expanded, project_dir, worktree)
451 } else if let Some(dir) = opencode_config_dir_env() {
452 find_up(&expanded, Path::new(&dir), Path::new(&dir))
453 } else {
454 warn!(
455 "Skipping relative instruction \"{}\" - no OPENCODE_CONFIG_DIR set while project config is disabled",
456 instruction
457 );
458 Vec::new()
459 }
460 }
461 }
462 // -----------------------------------------------------------------------
463 // Backward-compatible helpers (kept from original API)
464 // -----------------------------------------------------------------------

Callers 1

Calls 9

home_dirFunction · 0.85
newFunction · 0.85
is_glob_patternFunction · 0.85
expand_globFunction · 0.85
glob_upFunction · 0.85
opencode_config_dir_envFunction · 0.85
is_fileMethod · 0.80
find_upFunction · 0.70

Tested by

no test coverage detected