| 43 | } |
| 44 | |
| 45 | pub fn node_id(file_path: &str, kind: &str, name: &str, line: u32) -> String { |
| 46 | let mut hasher = Sha256::new(); |
| 47 | hasher.update(file_path.as_bytes()); |
| 48 | hasher.update(b":"); |
| 49 | hasher.update(kind.as_bytes()); |
| 50 | hasher.update(b":"); |
| 51 | hasher.update(name.as_bytes()); |
| 52 | hasher.update(b":"); |
| 53 | hasher.update(line.to_string().as_bytes()); |
| 54 | let digest = hasher.finalize(); |
| 55 | // 32 hex chars = first 16 bytes. |
| 56 | let mut hex = String::with_capacity(kind.len() + 1 + 32); |
| 57 | hex.push_str(kind); |
| 58 | hex.push(':'); |
| 59 | for b in &digest[..16] { |
| 60 | hex.push_str(&format!("{b:02x}")); |
| 61 | } |
| 62 | hex |
| 63 | } |
| 64 | |
| 65 | pub fn file_node_id(file_path: &str) -> String { |
| 66 | format!("file:{file_path}") |