Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/codegraph-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,11 +1424,14 @@ fn cmd_serve(
return serve_direct(project, &project_root, no_watch, explicit_path);
}
ServeMode::BeDaemon => {
let cfg = codegraph_core::config::get_config();
return codegraph_daemon::run_foreground(
&project_root,
codegraph_daemon::DaemonOptions {
run_mcp: true,
host_pid: codegraph_daemon::host_pid_from_env(),
include: cfg.indexing.include.clone(),
exclude: cfg.indexing.exclude.clone(),
..Default::default()
},
)
Expand Down Expand Up @@ -2096,6 +2099,9 @@ fn start_direct_watcher(
) -> Option<codegraph_watch::ProjectWatcher> {
let mut opts = codegraph_watch::WatchOptions::default();
opts.no_watch = no_watch;
let cfg = codegraph_core::config::get_config();
opts.include = cfg.indexing.include.clone();
opts.exclude = cfg.indexing.exclude.clone();
opts.on_sync_complete = Some(std::sync::Arc::new(
|outcome: codegraph_watch::SyncOutcome| {
tracing::info!(
Expand Down Expand Up @@ -3244,6 +3250,7 @@ fn index_project_inner(
ignore_dirs: config.indexing.ignore_dirs.clone(),
ignore_paths: config.indexing.ignore_paths.clone(),
exclude: config.indexing.exclude.clone(),
include: config.indexing.include.clone(),
parallel: true,
};
if !quiet {
Expand Down
38 changes: 38 additions & 0 deletions crates/codegraph-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ pub struct IndexingConfig {
/// `docs/gen`, `gen*`); honored by index and sync. Off by default.
#[serde(default)]
pub exclude: Vec<String>,
/// Root-relative path patterns for first-party source to force INTO the
/// index even when `.gitignore` (or the default `ignore_paths`) would drop
/// it — the case being a project under a second VCS (SVN, Perforce) that
/// `.gitignore`s its own real source out of Git yet still wants it indexed.
/// Same matcher as `.gitignore`/`exclude` (`Tools/`, `Local/ts/`, `gen*`),
/// matched against root-relative paths. Complements `exclude` (its
/// opposite). Precedence: a built-in `ignore_dirs` skip
/// (`node_modules`/`dist`/…) is NEVER re-included, and an explicit
/// `exclude` still wins over `include`. Off by default (empty = today's
/// behavior byte-identical). #1063.
#[serde(default)]
pub include: Vec<String>,
}

fn default_max_file_size() -> u64 {
Expand Down Expand Up @@ -187,6 +199,7 @@ impl Default for IndexingConfig {
ignore_dirs: default_ignore_dirs(),
ignore_paths: default_ignore_paths(),
exclude: Vec::new(),
include: Vec::new(),
}
}
}
Expand Down Expand Up @@ -357,6 +370,31 @@ max_file_size = 2097152
assert!(cfg.indexing.exclude.is_empty());
}

#[test]
fn test_include_parses_and_defaults_empty() {
let with_include = r#"
[app]
name = "p"

[indexing]
include = ["Tools/", "Local/ts/"]
"#;
let cfg: Config = toml::from_str(with_include).expect("should parse");
assert_eq!(cfg.indexing.include, vec!["Tools/", "Local/ts/"]);

let without = r#"
[app]
name = "p"

[indexing]
max_file_size = 2097152
"#;
let cfg: Config = toml::from_str(without).expect("should parse");
assert!(cfg.indexing.include.is_empty());

assert!(IndexingConfig::default().include.is_empty());
}

#[test]
fn test_missing_file_returns_defaults() {
let cfg = Config::discover(None, Path::new("/tmp/nonexistent"))
Expand Down
9 changes: 9 additions & 0 deletions crates/codegraph-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ pub struct DaemonOptions {
/// project (N client inotify sets collapse to 1). Honors
/// `watch_disabled_reason` (e.g. `CODEGRAPH_NO_WATCH=1`).
pub watch: bool,
/// `config.toml` `include`/`exclude` path patterns (#1063), passed through
/// to the shared `ProjectWatcher` so its scope matches the scan's. The CLI
/// (which owns the config singleton) populates these; empty = pre-#1063.
pub include: Vec<String>,
pub exclude: Vec<String>,
}

impl Default for DaemonOptions {
Expand All @@ -176,6 +181,8 @@ impl Default for DaemonOptions {
watchdog_interval: DEFAULT_WATCHDOG_INTERVAL,
run_mcp: true,
watch: true,
include: Vec::new(),
exclude: Vec::new(),
}
}
}
Expand Down Expand Up @@ -555,6 +562,8 @@ fn start_project_watcher(
let counter = Arc::new(AtomicUsize::new(0));
let mut watch_options = codegraph_watch::WatchOptions::default();
watch_options.no_watch = !options.watch;
watch_options.include = options.include.clone();
watch_options.exclude = options.exclude.clone();
watch_options.on_sync_complete =
Some(Arc::new(move |outcome: codegraph_watch::SyncOutcome| {
let n = counter.fetch_add(1, Ordering::SeqCst) + 1;
Expand Down
Loading
Loading