use crate::types::{Type, Value};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SourceLocation {
pub file: String,
pub line: u32,
pub column: u32,
#[serde(default)]
pub length: Option<u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Constant {
pub name: String,
pub doc: Option<String>,
#[serde(rename = "type")]
pub typ: Type,
pub value: Value,
pub source: SourceLocation,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnumDef {
pub name: String,
pub namespace: String,
pub doc: Option<String>,
pub variants: Vec<EnumVariant>,
#[serde(rename = "backingType")]
pub backing_type: String,
pub source: SourceLocation,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnumVariant {
pub name: String,
pub value: Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Module {
pub namespace: String,
#[serde(rename = "sourceFile")]
pub source_file: String,
pub doc: Option<String>,
pub constants: Vec<Constant>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypeAliasDef {
pub name: String,
pub namespace: String,
pub doc: Option<String>,
pub target: crate::types::Type,
pub source: SourceLocation,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CodeGenRequest {
pub version: u32,
#[serde(rename = "outputPath")]
pub output_path: String,
#[serde(default)]
pub options: HashMap<String, serde_json::Value>,
pub modules: Vec<Module>,
pub enums: Vec<EnumDef>,
#[serde(default)]
pub aliases: Vec<TypeAliasDef>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GeneratedFile {
pub path: String,
pub content: String,
#[serde(default)]
pub mappings: Vec<SymbolMapping>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SymbolMapping {
pub symbol: String,
pub line: u32,
#[serde(default)]
pub column: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginError {
pub message: String,
pub source: Option<SourceLocation>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CodeGenResponse {
pub files: Vec<GeneratedFile>,
#[serde(default)]
pub errors: Vec<PluginError>,
}
impl CodeGenRequest {
pub fn new(output_path: String, options: HashMap<String, serde_json::Value>) -> Self {
Self {
version: 1,
output_path,
options,
modules: Vec::new(),
enums: Vec::new(),
aliases: Vec::new(),
}
}
}