1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct IdeIntegrationConfig {
9 pub vscode: Option<VsCodeConfig>,
11 pub terminal: Option<TerminalConfig>,
13 pub providers: ProviderChainConfig,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct VsCodeConfig {
20 pub enabled: bool,
22 pub port: u16,
24 pub features: Vec<String>,
26 #[serde(default)]
28 pub settings: serde_json::Value,
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct TerminalConfig {
34 pub vim: Option<VimConfig>,
36 pub emacs: Option<EmacsConfig>,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct VimConfig {
43 pub enabled: bool,
45 pub plugin_manager: String,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct EmacsConfig {
52 pub enabled: bool,
54 pub package_manager: String,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct ProviderChainConfig {
61 pub external_lsp: ExternalLspConfig,
63 pub configured_rules: Option<ConfiguredRulesConfig>,
65 pub builtin_providers: BuiltinProvidersConfig,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct ExternalLspConfig {
72 pub enabled: bool,
74 pub servers: HashMap<String, LspServerConfig>,
76 pub health_check_interval_ms: u64,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct LspServerConfig {
83 pub language: String,
85 pub command: String,
87 pub args: Vec<String>,
89 pub timeout_ms: u64,
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct ConfiguredRulesConfig {
96 pub enabled: bool,
98 pub rules_path: String,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct BuiltinProvidersConfig {
105 pub enabled: bool,
107 pub languages: Vec<String>,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct CompletionParams {
114 pub language: String,
116 pub file_path: String,
118 pub position: Position,
120 pub context: String,
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
126pub struct DiagnosticsParams {
127 pub language: String,
129 pub file_path: String,
131 pub source: String,
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize)]
137pub struct HoverParams {
138 pub language: String,
140 pub file_path: String,
142 pub position: Position,
144}
145
146#[derive(Debug, Clone, Serialize, Deserialize)]
148pub struct DefinitionParams {
149 pub language: String,
151 pub file_path: String,
153 pub position: Position,
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct Diagnostic {
160 pub range: Range,
162 pub severity: DiagnosticSeverity,
164 pub message: String,
166 pub source: String,
168}
169
170#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
172#[serde(rename_all = "lowercase")]
173pub enum DiagnosticSeverity {
174 Error,
176 Warning,
178 Information,
180 Hint,
182}
183
184#[derive(Debug, Clone, Serialize, Deserialize)]
186pub struct CompletionItem {
187 pub label: String,
189 pub kind: CompletionItemKind,
191 pub detail: Option<String>,
193 pub documentation: Option<String>,
195 pub insert_text: String,
197}
198
199#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
201#[serde(rename_all = "lowercase")]
202pub enum CompletionItemKind {
203 Text,
205 Method,
207 Function,
209 Constructor,
211 Field,
213 Variable,
215 Class,
217 Interface,
219 Module,
221 Property,
223 Unit,
225 Value,
227 Enum,
229 Keyword,
231 Snippet,
233 Color,
235 File,
237 Reference,
239 Folder,
241 EnumMember,
243 Constant,
245 Struct,
247 Event,
249 Operator,
251 TypeParameter,
253}
254
255#[derive(Debug, Clone, Serialize, Deserialize)]
257pub struct Hover {
258 pub contents: String,
260 pub range: Option<Range>,
262}
263
264#[derive(Debug, Clone, Serialize, Deserialize)]
266pub struct Location {
267 pub file_path: String,
269 pub range: Range,
271}
272
273#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
275pub struct Position {
276 pub line: u32,
278 pub character: u32,
280}
281
282#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
284pub struct Range {
285 pub start: Position,
287 pub end: Position,
289}
290
291#[cfg(test)]
292mod tests {
293 use super::*;
294
295 #[test]
296 fn test_position_creation() {
297 let pos = Position {
298 line: 10,
299 character: 5,
300 };
301 assert_eq!(pos.line, 10);
302 assert_eq!(pos.character, 5);
303 }
304
305 #[test]
306 fn test_range_creation() {
307 let range = Range {
308 start: Position {
309 line: 1,
310 character: 0,
311 },
312 end: Position {
313 line: 1,
314 character: 10,
315 },
316 };
317 assert_eq!(range.start.line, 1);
318 assert_eq!(range.end.character, 10);
319 }
320
321 #[test]
322 fn test_completion_item_serialization() {
323 let item = CompletionItem {
324 label: "test".to_string(),
325 kind: CompletionItemKind::Function,
326 detail: Some("test function".to_string()),
327 documentation: None,
328 insert_text: "test()".to_string(),
329 };
330
331 let json = serde_json::to_string(&item).unwrap();
332 let deserialized: CompletionItem = serde_json::from_str(&json).unwrap();
333 assert_eq!(deserialized.label, "test");
334 assert_eq!(deserialized.kind, CompletionItemKind::Function);
335 }
336
337 #[test]
338 fn test_diagnostic_severity_serialization() {
339 let severity = DiagnosticSeverity::Error;
340 let json = serde_json::to_string(&severity).unwrap();
341 assert_eq!(json, "\"error\"");
342
343 let deserialized: DiagnosticSeverity = serde_json::from_str(&json).unwrap();
344 assert_eq!(deserialized, DiagnosticSeverity::Error);
345 }
346}