1#[derive(Debug, Clone)]
8pub struct LspParseResult {
9 pub variables: Vec<String>,
11 pub blocks: Vec<TemplateBlock>,
13 pub filters: Vec<String>,
15 pub macros: Vec<String>,
17}
18
19#[derive(Debug, Clone)]
21pub struct TemplateBlock {
22 pub block_type: String,
24 pub start_line: usize,
26 pub start_column: usize,
28 pub end_line: usize,
30 pub end_column: usize,
32 pub content: String,
34}
35
36#[derive(Debug, Clone)]
38pub struct CompletionItem {
39 pub label: String,
41 pub completion_type: String,
43 pub detail: String,
45 pub documentation: Option<String>,
47 pub insert_text: Option<String>,
49}
50
51#[derive(Debug, Clone)]
53pub struct SyntaxToken {
54 pub content: String,
56 pub token_type: String,
58 pub start_position: usize,
60 pub end_position: usize,
62 pub line: usize,
64 pub column: usize,
66}
67
68#[derive(Debug, Clone)]
70pub struct Diagnostic {
71 pub message: String,
73 pub severity: String,
75 pub line: usize,
77 pub column: usize,
79 pub end_line: usize,
81 pub end_column: usize,
83 pub code: Option<String>,
85}
86
87#[derive(Debug, Clone)]
89pub struct HoverInfo {
90 pub variable_name: String,
92 pub variable_type: String,
94 pub current_value: String,
96 pub description: String,
98}
99
100#[derive(Debug, Clone)]
102pub struct DefinitionInfo {
103 pub definition_type: String,
105 pub name: String,
107 pub line: usize,
109 pub column: usize,
111 pub file_path: Option<String>,
113}
114
115impl Default for LspParseResult {
116 fn default() -> Self {
117 Self::new()
118 }
119}
120
121impl LspParseResult {
122 pub fn new() -> Self {
124 Self {
125 variables: Vec::new(),
126 blocks: Vec::new(),
127 filters: Vec::new(),
128 macros: Vec::new(),
129 }
130 }
131
132 pub fn add_variable(&mut self, name: &str) {
134 if !self.variables.contains(&name.to_string()) {
135 self.variables.push(name.to_string());
136 }
137 }
138
139 pub fn add_block(&mut self, block: TemplateBlock) {
141 self.blocks.push(block);
142 }
143
144 pub fn add_filter(&mut self, name: &str) {
146 if !self.filters.contains(&name.to_string()) {
147 self.filters.push(name.to_string());
148 }
149 }
150}
151
152impl TemplateBlock {
153 pub fn new(block_type: &str, start_line: usize, start_column: usize, content: &str) -> Self {
155 Self {
156 block_type: block_type.to_string(),
157 start_line,
158 start_column,
159 end_line: start_line, end_column: start_column,
161 content: content.to_string(),
162 }
163 }
164}
165
166impl CompletionItem {
167 pub fn new(label: &str, completion_type: &str, detail: &str) -> Self {
169 Self {
170 label: label.to_string(),
171 completion_type: completion_type.to_string(),
172 detail: detail.to_string(),
173 documentation: None,
174 insert_text: None,
175 }
176 }
177
178 pub fn with_documentation(mut self, doc: &str) -> Self {
180 self.documentation = Some(doc.to_string());
181 self
182 }
183
184 pub fn with_insert_text(mut self, text: &str) -> Self {
186 self.insert_text = Some(text.to_string());
187 self
188 }
189}
190
191impl SyntaxToken {
192 pub fn new(content: &str, token_type: &str, start_pos: usize, line: usize, column: usize) -> Self {
194 Self {
195 content: content.to_string(),
196 token_type: token_type.to_string(),
197 start_position: start_pos,
198 end_position: start_pos + content.len(),
199 line,
200 column,
201 }
202 }
203}
204
205impl Diagnostic {
206 pub fn new(message: &str, severity: &str, line: usize, column: usize) -> Self {
208 Self {
209 message: message.to_string(),
210 severity: severity.to_string(),
211 line,
212 column,
213 end_line: line,
214 end_column: column,
215 code: None,
216 }
217 }
218
219 pub fn with_range(mut self, end_line: usize, end_column: usize) -> Self {
221 self.end_line = end_line;
222 self.end_column = end_column;
223 self
224 }
225
226 pub fn with_code(mut self, code: &str) -> Self {
228 self.code = Some(code.to_string());
229 self
230 }
231}