WIP: Start adding more logs
This commit is contained in:
parent
799b32c8a9
commit
63fdf1398a
2 changed files with 38 additions and 2 deletions
|
@ -3,7 +3,13 @@ use anyhow::{anyhow, Result};
|
|||
use collections::{hash_map::Entry, BTreeMap, HashMap, HashSet};
|
||||
use rpc::{proto, ConnectionId, Receipt};
|
||||
use serde::Serialize;
|
||||
use std::{collections::hash_map, mem, path::PathBuf};
|
||||
use std::{
|
||||
collections::hash_map,
|
||||
ffi::{OsStr, OsString},
|
||||
mem,
|
||||
path::{Path, PathBuf},
|
||||
str,
|
||||
};
|
||||
use tracing::instrument;
|
||||
|
||||
#[derive(Default, Serialize)]
|
||||
|
@ -43,6 +49,8 @@ pub struct Worktree {
|
|||
#[serde(skip)]
|
||||
pub entries: HashMap<u64, proto::Entry>,
|
||||
#[serde(skip)]
|
||||
pub extension_counts: HashMap<OsString, usize>,
|
||||
#[serde(skip)]
|
||||
pub diagnostic_summaries: BTreeMap<PathBuf, proto::DiagnosticSummary>,
|
||||
pub scan_id: u64,
|
||||
}
|
||||
|
@ -575,9 +583,22 @@ impl Store {
|
|||
let metadata_changed = worktree_root_name != worktree.root_name;
|
||||
worktree.root_name = worktree_root_name.to_string();
|
||||
for entry_id in removed_entries {
|
||||
worktree.entries.remove(&entry_id);
|
||||
if let Some(entry) = worktree.entries.remove(&entry_id) {
|
||||
if let Some(extension) = extension_for_entry(&entry) {
|
||||
if let Some(count) = worktree.extension_counts.get_mut(extension) {
|
||||
*count = count.saturating_sub(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for entry in updated_entries {
|
||||
if let Some(extension) = extension_for_entry(&entry) {
|
||||
if let Some(count) = worktree.extension_counts.get_mut(extension) {
|
||||
*count += 1;
|
||||
} else {
|
||||
worktree.extension_counts.insert(extension.into(), 1);
|
||||
}
|
||||
}
|
||||
worktree.entries.insert(entry.id, entry.clone());
|
||||
}
|
||||
worktree.scan_id = scan_id;
|
||||
|
@ -732,3 +753,10 @@ impl Channel {
|
|||
self.connection_ids.iter().copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
fn extension_for_entry(entry: &proto::Entry) -> Option<&OsStr> {
|
||||
str::from_utf8(&entry.path)
|
||||
.ok()
|
||||
.map(Path::new)
|
||||
.and_then(|p| p.extension())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue