use std::fs;
use std::path::Path;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct NeighborEntry {
pub file_path: String,
pub line_start: u32,
pub line_end: u32,
pub name: Option<String>,
pub score: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct ChangeNeighborsMarker {
pub edited_path: String,
pub neighbors: Vec<NeighborEntry>,
}
pub(crate) fn write(marker_path: &Path, marker: &ChangeNeighborsMarker) {
if let Ok(json) = serde_json::to_string(marker) {
let _ = fs::write(marker_path, json);
}
}
pub(crate) fn read(marker_path: &Path) -> Option<ChangeNeighborsMarker> {
let content = fs::read_to_string(marker_path).ok()?;
serde_json::from_str(&content).ok()
}
pub(crate) fn read_and_remove(marker_path: &Path) -> Option<ChangeNeighborsMarker> {
let marker = read(marker_path)?;
let _ = fs::remove_file(marker_path);
Some(marker)
}