MCPcopy Create free account
hub / github.com/concensure/Semantic / start

Method start

watcher/src/lib.rs:13–42  ·  view source on GitHub ↗
(repo_root: PathBuf, indexer: Arc<Mutex<Indexer>>)

Source from the content-addressed store, hash-verified

11
12impl RepoWatcher {
13 pub fn start(repo_root: PathBuf, indexer: Arc<Mutex<Indexer>>) -> Result<Self> {
14 let root_for_cb = repo_root.clone();
15 let mut watcher = RecommendedWatcher::new(
16 move |res: notify::Result<notify::Event>| {
17 let event = match res {
18 Ok(ev) => ev,
19 Err(_) => return,
20 };
21
22 for path in &event.paths {
23 if let Some(relative) = to_relative(&root_for_cb, path) {
24 let mut idx = indexer.lock();
25 match event.kind {
26 EventKind::Remove(_) => {
27 let _ = idx.delete_file(&relative);
28 }
29 EventKind::Modify(_) | EventKind::Create(_) => {
30 let _ = idx.index_file(&root_for_cb, &relative);
31 }
32 _ => {}
33 }
34 }
35 }
36 },
37 Config::default(),
38 )?;
39
40 watcher.watch(&repo_root, RecursiveMode::Recursive)?;
41 Ok(Self { _watcher: watcher })
42 }
43}
44
45fn to_relative(root: &Path, path: &Path) -> Option<String> {

Callers

nothing calls this directly

Calls 3

to_relativeFunction · 0.85
delete_fileMethod · 0.80
index_fileMethod · 0.80

Tested by

no test coverage detected