use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SymbolKind {
Function,
Method,
Class,
Struct,
Interface,
Trait,
Enum,
Module,
Variable,
Constant,
Test,
Section,
Route,
Field,
}
impl SymbolKind {
pub fn as_str(&self) -> &'static str {
match self {
Self::Function => "Function",
Self::Method => "Method",
Self::Class => "Class",
Self::Struct => "Struct",
Self::Interface => "Interface",
Self::Trait => "Trait",
Self::Enum => "Enum",
Self::Module => "Module",
Self::Variable => "Variable",
Self::Constant => "Constant",
Self::Test => "Test",
Self::Section => "Section",
Self::Route => "Route",
Self::Field => "Field",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Span {
pub file: String,
pub start_line: u32,
pub start_col: u32,
pub end_line: u32,
pub end_col: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Symbol {
pub id: String,
pub name: String,
pub kind: SymbolKind,
pub span: Span,
pub signature_hash: String,
pub parent: Option<String>,
pub language: String,
pub visibility: Option<String>,
pub docstring: Option<String>,
pub complexity: u32,
pub parameters: Option<String>,
pub return_type: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum RelationKind {
Calls,
CalledBy,
Imports,
ImportedBy,
Contains,
ContainedBy,
Inherits,
InheritedBy,
Implements,
ImplementedBy,
Reads,
Writes,
TestedBy,
Tests,
Custom(String),
}
impl RelationKind {
pub fn as_str(&self) -> &str {
match self {
Self::Calls => "CALLS",
Self::CalledBy => "CALLED_BY",
Self::Imports => "IMPORTS",
Self::ImportedBy => "IMPORTED_BY",
Self::Contains => "CONTAINS",
Self::ContainedBy => "CONTAINED_BY",
Self::Inherits => "INHERITS",
Self::InheritedBy => "INHERITED_BY",
Self::Implements => "IMPLEMENTS",
Self::ImplementedBy => "IMPLEMENTED_BY",
Self::Reads => "READS",
Self::Writes => "WRITES",
Self::TestedBy => "TESTED_BY",
Self::Tests => "TESTS",
Self::Custom(name) => name.as_str(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Relation {
pub source_id: String,
pub target_id: String,
pub kind: RelationKind,
pub span: Option<Span>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub receiver: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum BridgeKind {
Ffi,
Jni,
Cgo,
Grpc,
PInvoke,
Ctypes,
Wasm,
Com,
Other(String),
}
impl BridgeKind {
pub fn as_str(&self) -> &str {
match self {
Self::Ffi => "FFI",
Self::Jni => "JNI",
Self::Cgo => "CGO",
Self::Grpc => "GRPC",
Self::PInvoke => "P_INVOKE",
Self::Ctypes => "CTYPES",
Self::Wasm => "WASM",
Self::Com => "COM",
Self::Other(s) => s,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Bridge {
pub file: String,
pub line: u32,
pub kind: BridgeKind,
pub foreign_symbol: String,
pub source_language: String,
pub target_language: Option<String>,
pub detail: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum StatementKind {
If,
ElseIf,
Else,
For,
While,
DoWhile,
Loop,
Match,
Case,
Try,
Catch,
Ternary,
Guard,
}
impl StatementKind {
pub fn as_str(&self) -> &'static str {
match self {
Self::If => "If",
Self::ElseIf => "ElseIf",
Self::Else => "Else",
Self::For => "For",
Self::While => "While",
Self::DoWhile => "DoWhile",
Self::Loop => "Loop",
Self::Match => "Match",
Self::Case => "Case",
Self::Try => "Try",
Self::Catch => "Catch",
Self::Ternary => "Ternary",
Self::Guard => "Guard",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Statement {
pub id: String,
pub kind: StatementKind,
pub condition: String,
pub start_line: u32,
pub end_line: u32,
pub depth: u32,
pub parent_symbol: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileExtraction {
pub file: String,
pub language: String,
pub content_hash: String,
pub symbols: Vec<Symbol>,
pub relations: Vec<Relation>,
pub statements: Vec<Statement>,
}