Skip to main content

shape_runtime/metadata/
types.rs

1//! Core type definitions for language metadata
2
3use serde::{Deserialize, Serialize};
4
5/// Information about a language keyword
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct KeywordInfo {
8    pub keyword: String,
9    pub description: String,
10    pub category: KeywordCategory,
11}
12
13/// Category of keyword
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub enum KeywordCategory {
16    Declaration, // let, var, const, function
17    ControlFlow, // if, else, while, for, return, break, continue
18    Query,       // find, scan, analyze, simulate, alert
19    Module,      // import, export, from, module
20    Type,        // type, interface, enum, extend
21    Literal,     // true, false, None, Some
22    Operator,    // and, or, not, in
23    Temporal,    // on
24    Other,
25}
26
27/// Information about a built-in function
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct FunctionInfo {
30    pub name: String,
31    pub signature: String,
32    pub description: String,
33    pub category: FunctionCategory,
34    pub parameters: Vec<ParameterInfo>,
35    pub return_type: String,
36    pub example: Option<String>,
37    /// Whether this function is fully implemented (default: true for backwards compat)
38    #[serde(default = "default_true")]
39    pub implemented: bool,
40    /// Whether this function is only valid inside `comptime { }` blocks
41    #[serde(default)]
42    pub comptime_only: bool,
43}
44
45fn default_true() -> bool {
46    true
47}
48
49impl Default for FunctionInfo {
50    fn default() -> Self {
51        Self {
52            name: String::new(),
53            signature: String::new(),
54            description: String::new(),
55            category: FunctionCategory::Utility,
56            parameters: Vec::new(),
57            return_type: String::new(),
58            example: None,
59            implemented: true,
60            comptime_only: false,
61        }
62    }
63}
64
65/// Category of function
66#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
67pub enum FunctionCategory {
68    Simulation, // Event-driven simulations
69    Math,       // Mathematical functions
70    Array,      // Array operations
71    Column,     // Column operations
72    Statistics, // Statistical functions
73    Data,       // Data loading/access
74    Utility,    // Utility functions
75}
76
77/// Information about a function parameter
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct ParameterInfo {
80    pub name: String,
81    pub param_type: String,
82    pub optional: bool,
83    pub description: String,
84    /// Semantic constraints for LSP intelligent completions
85    #[serde(default, skip_serializing_if = "Option::is_none")]
86    pub constraints: Option<ParameterConstraints>,
87}
88
89/// Semantic constraints on parameters for LSP intelligent completions
90#[derive(Debug, Clone, Serialize, Deserialize, Default)]
91pub struct ParameterConstraints {
92    /// Parameter expects a data provider name (e.g., "data")
93    #[serde(default)]
94    pub is_provider_name: bool,
95
96    /// Parameter expects a symbol with a specific annotation (e.g., "strategy")
97    #[serde(default, skip_serializing_if = "Option::is_none")]
98    pub requires_annotation: Option<String>,
99
100    /// Parameter accepts only specific string values (enum-like)
101    #[serde(default, skip_serializing_if = "Option::is_none")]
102    pub allowed_values: Option<Vec<String>>,
103
104    /// Parameter expects an object with specific properties
105    #[serde(default, skip_serializing_if = "Option::is_none")]
106    pub object_properties: Option<Vec<PropertyConstraint>>,
107}
108
109/// Constraint on an object property
110#[derive(Debug, Clone, Serialize, Deserialize)]
111pub struct PropertyConstraint {
112    pub name: String,
113    pub value_type: String,
114    pub required: bool,
115    /// Recursive constraints for nested objects
116    #[serde(default, skip_serializing_if = "Option::is_none")]
117    pub constraint: Option<ParameterConstraints>,
118}
119
120/// Information about a built-in type
121#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct TypeInfo {
123    pub name: String,
124    pub description: String,
125}
126
127/// Information about an object property
128#[derive(Debug, Clone, Serialize, Deserialize)]
129pub struct PropertyInfo {
130    pub name: String,
131    pub property_type: String,
132    pub description: String,
133}
134
135/// Information about a method
136#[derive(Debug, Clone, Serialize, Deserialize)]
137pub struct MethodInfo {
138    pub name: String,
139    pub signature: String,
140    pub description: String,
141    pub return_type: String,
142    /// Whether this method is fully implemented (default: true for backwards compat)
143    #[serde(default = "default_true")]
144    pub implemented: bool,
145}