use std::path::PathBuf;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::util::path_guard::PathGuard;
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct LspNote {
pub path: String,
pub line: u32,
pub message: String,
pub source: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
pub struct LspNotes {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub errors: Vec<LspNote>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub warnings: Vec<LspNote>,
}
#[derive(Debug, Deserialize, JsonSchema)]
pub struct Target {
pub path: String,
pub line: Option<usize>,
pub symbol: Option<String>,
pub line_range: Option<String>,
pub offset: Option<usize>,
pub limit: Option<usize>,
}
#[derive(Default, Debug, Deserialize, JsonSchema)] pub struct FsRead {
pub targets: Vec<Target>,
}
#[derive(Clone, Default, Debug, Deserialize, JsonSchema)]
pub struct TargetFile {
#[serde(alias = "content")]
pub text: String,
pub path: String,
#[serde(default)]
pub file_hash: Option<String>,
}
#[derive(Default, Debug, Deserialize, JsonSchema)]
pub struct FsWrite {
pub targets: Vec<TargetFile>,
}
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct FsMetadata {
pub root: PathBuf,
pub allowlist: Option<Vec<PathBuf>>,
pub blocklist: Option<Vec<PathBuf>>,
}
#[derive(Debug, Clone, Default, Deserialize, JsonSchema)]
pub struct EditTarget {
pub path: String,
pub file_hash: String,
pub ops: String,
}
#[derive(Debug, Clone, Default, Deserialize, JsonSchema)]
pub struct FsEdit {
pub targets: Vec<EditTarget>,
#[serde(default)]
pub dry_run: bool,
}
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct ReplaceEdit {
pub path: String,
#[serde(default)]
pub file_hash: Option<String>,
pub old_string: String,
pub new_string: String,
#[serde(default)]
pub replace_all: bool,
}
#[derive(Debug, Clone, Default, Deserialize, JsonSchema)]
pub struct FsContentEdit {
pub edits: Vec<ReplaceEdit>,
#[serde(default)]
pub dry_run: bool,
}
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct AstEditOp {
pub pat: String,
pub out: String,
}
#[derive(Debug, Clone, Default, Deserialize, JsonSchema)]
pub struct FsAstEdit {
pub ops: Vec<AstEditOp>,
pub paths: Vec<String>,
#[serde(default)]
pub max_files: Option<usize>,
}
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct FsRollbackInput {
pub path: String,
pub hash: String,
}
#[derive(Default)]
pub struct FsRollback;
impl FsMetadata {
pub(crate) fn fs_guard(&self, path: &str) -> Result<PathBuf, String> {
let guard = PathGuard::new(
&self.root,
self.allowlist.as_deref(),
self.blocklist.as_deref(),
);
guard.resolve(path)
}
}