ricecoder_ide/
types.rs

1//! Core data types for IDE integration
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// IDE Integration Configuration
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct IdeIntegrationConfig {
9    /// VS Code configuration
10    pub vscode: Option<VsCodeConfig>,
11    /// Terminal editor configuration
12    pub terminal: Option<TerminalConfig>,
13    /// Provider chain configuration
14    pub providers: ProviderChainConfig,
15}
16
17/// VS Code specific configuration
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct VsCodeConfig {
20    /// Whether VS Code integration is enabled
21    pub enabled: bool,
22    /// Port for communication
23    pub port: u16,
24    /// Enabled features
25    pub features: Vec<String>,
26    /// VS Code settings
27    #[serde(default)]
28    pub settings: serde_json::Value,
29}
30
31/// Terminal editor configuration
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct TerminalConfig {
34    /// Vim/Neovim configuration
35    pub vim: Option<VimConfig>,
36    /// Emacs configuration
37    pub emacs: Option<EmacsConfig>,
38}
39
40/// Vim/Neovim configuration
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct VimConfig {
43    /// Whether vim integration is enabled
44    pub enabled: bool,
45    /// Plugin manager (vim-plug, packer, etc.)
46    pub plugin_manager: String,
47}
48
49/// Emacs configuration
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct EmacsConfig {
52    /// Whether emacs integration is enabled
53    pub enabled: bool,
54    /// Package manager (use-package, straight.el, etc.)
55    pub package_manager: String,
56}
57
58/// Provider chain configuration
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct ProviderChainConfig {
61    /// External LSP configuration
62    pub external_lsp: ExternalLspConfig,
63    /// Configured rules configuration
64    pub configured_rules: Option<ConfiguredRulesConfig>,
65    /// Built-in providers configuration
66    pub builtin_providers: BuiltinProvidersConfig,
67}
68
69/// External LSP configuration
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct ExternalLspConfig {
72    /// Whether external LSP is enabled
73    pub enabled: bool,
74    /// LSP server configurations by language
75    pub servers: HashMap<String, LspServerConfig>,
76    /// Health check interval in milliseconds
77    pub health_check_interval_ms: u64,
78}
79
80/// LSP server configuration
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct LspServerConfig {
83    /// Language this server supports
84    pub language: String,
85    /// Command to start the server
86    pub command: String,
87    /// Arguments for the command
88    pub args: Vec<String>,
89    /// Timeout in milliseconds
90    pub timeout_ms: u64,
91}
92
93/// Configured rules configuration
94#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct ConfiguredRulesConfig {
96    /// Whether configured rules are enabled
97    pub enabled: bool,
98    /// Path to rules file (resolved via ricecoder_storage::PathResolver)
99    pub rules_path: String,
100}
101
102/// Built-in providers configuration
103#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct BuiltinProvidersConfig {
105    /// Whether built-in providers are enabled
106    pub enabled: bool,
107    /// Languages supported by built-in providers
108    pub languages: Vec<String>,
109}
110
111/// Completion request parameters
112#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct CompletionParams {
114    /// Programming language
115    pub language: String,
116    /// File path (resolved via ricecoder_storage::PathResolver)
117    pub file_path: String,
118    /// Cursor position
119    pub position: Position,
120    /// Context around cursor
121    pub context: String,
122}
123
124/// Diagnostics request parameters
125#[derive(Debug, Clone, Serialize, Deserialize)]
126pub struct DiagnosticsParams {
127    /// Programming language
128    pub language: String,
129    /// File path (resolved via ricecoder_storage::PathResolver)
130    pub file_path: String,
131    /// Source code
132    pub source: String,
133}
134
135/// Hover request parameters
136#[derive(Debug, Clone, Serialize, Deserialize)]
137pub struct HoverParams {
138    /// Programming language
139    pub language: String,
140    /// File path (resolved via ricecoder_storage::PathResolver)
141    pub file_path: String,
142    /// Cursor position
143    pub position: Position,
144}
145
146/// Definition request parameters
147#[derive(Debug, Clone, Serialize, Deserialize)]
148pub struct DefinitionParams {
149    /// Programming language
150    pub language: String,
151    /// File path (resolved via ricecoder_storage::PathResolver)
152    pub file_path: String,
153    /// Cursor position
154    pub position: Position,
155}
156
157/// Diagnostic information
158#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct Diagnostic {
160    /// Range of the diagnostic
161    pub range: Range,
162    /// Severity level
163    pub severity: DiagnosticSeverity,
164    /// Diagnostic message
165    pub message: String,
166    /// Source of the diagnostic
167    pub source: String,
168}
169
170/// Diagnostic severity
171#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
172#[serde(rename_all = "lowercase")]
173pub enum DiagnosticSeverity {
174    /// Error severity
175    Error,
176    /// Warning severity
177    Warning,
178    /// Information severity
179    Information,
180    /// Hint severity
181    Hint,
182}
183
184/// Completion item
185#[derive(Debug, Clone, Serialize, Deserialize)]
186pub struct CompletionItem {
187    /// Display label
188    pub label: String,
189    /// Completion kind
190    pub kind: CompletionItemKind,
191    /// Additional details
192    pub detail: Option<String>,
193    /// Documentation
194    pub documentation: Option<String>,
195    /// Text to insert
196    pub insert_text: String,
197}
198
199/// Completion item kind
200#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
201#[serde(rename_all = "lowercase")]
202pub enum CompletionItemKind {
203    /// Text completion
204    Text,
205    /// Method completion
206    Method,
207    /// Function completion
208    Function,
209    /// Constructor completion
210    Constructor,
211    /// Field completion
212    Field,
213    /// Variable completion
214    Variable,
215    /// Class completion
216    Class,
217    /// Interface completion
218    Interface,
219    /// Module completion
220    Module,
221    /// Property completion
222    Property,
223    /// Unit completion
224    Unit,
225    /// Value completion
226    Value,
227    /// Enum completion
228    Enum,
229    /// Keyword completion
230    Keyword,
231    /// Snippet completion
232    Snippet,
233    /// Color completion
234    Color,
235    /// File completion
236    File,
237    /// Reference completion
238    Reference,
239    /// Folder completion
240    Folder,
241    /// Enum member completion
242    EnumMember,
243    /// Constant completion
244    Constant,
245    /// Struct completion
246    Struct,
247    /// Event completion
248    Event,
249    /// Operator completion
250    Operator,
251    /// Type parameter completion
252    TypeParameter,
253}
254
255/// Hover information
256#[derive(Debug, Clone, Serialize, Deserialize)]
257pub struct Hover {
258    /// Hover contents
259    pub contents: String,
260    /// Range of the hover
261    pub range: Option<Range>,
262}
263
264/// Location in a file
265#[derive(Debug, Clone, Serialize, Deserialize)]
266pub struct Location {
267    /// File path (resolved via ricecoder_storage::PathResolver)
268    pub file_path: String,
269    /// Range in the file
270    pub range: Range,
271}
272
273/// Position in a file
274#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
275pub struct Position {
276    /// Line number (0-based)
277    pub line: u32,
278    /// Character position (0-based)
279    pub character: u32,
280}
281
282/// Range in a file
283#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
284pub struct Range {
285    /// Start position
286    pub start: Position,
287    /// End position
288    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}