ricecoder_lsp/code_actions/
adapters.rs1use crate::config::LanguageConfig;
7use crate::providers::{CodeActionProvider, ProviderResult};
8use crate::types::Diagnostic;
9
10pub struct RustCodeActionAdapter {
12 config: Option<LanguageConfig>,
13}
14
15impl RustCodeActionAdapter {
16 pub fn new() -> Self {
18 Self { config: None }
19 }
20
21 pub fn with_config(config: LanguageConfig) -> Self {
23 Self {
24 config: Some(config),
25 }
26 }
27}
28
29impl Default for RustCodeActionAdapter {
30 fn default() -> Self {
31 Self::new()
32 }
33}
34
35impl CodeActionProvider for RustCodeActionAdapter {
36 fn language(&self) -> &str {
37 "rust"
38 }
39
40 fn suggest_actions(
41 &self,
42 _diagnostic: &Diagnostic,
43 _code: &str,
44 ) -> ProviderResult<Vec<String>> {
45 Ok(vec![])
47 }
48
49 fn apply_action(&self, code: &str, _action: &str) -> ProviderResult<String> {
50 Ok(code.to_string())
52 }
53
54 fn config(&self) -> Option<&LanguageConfig> {
55 self.config.as_ref()
56 }
57}
58
59pub struct TypeScriptCodeActionAdapter {
61 config: Option<LanguageConfig>,
62}
63
64impl TypeScriptCodeActionAdapter {
65 pub fn new() -> Self {
67 Self { config: None }
68 }
69
70 pub fn with_config(config: LanguageConfig) -> Self {
72 Self {
73 config: Some(config),
74 }
75 }
76}
77
78impl Default for TypeScriptCodeActionAdapter {
79 fn default() -> Self {
80 Self::new()
81 }
82}
83
84impl CodeActionProvider for TypeScriptCodeActionAdapter {
85 fn language(&self) -> &str {
86 "typescript"
87 }
88
89 fn suggest_actions(
90 &self,
91 _diagnostic: &Diagnostic,
92 _code: &str,
93 ) -> ProviderResult<Vec<String>> {
94 Ok(vec![])
96 }
97
98 fn apply_action(&self, code: &str, _action: &str) -> ProviderResult<String> {
99 Ok(code.to_string())
101 }
102
103 fn config(&self) -> Option<&LanguageConfig> {
104 self.config.as_ref()
105 }
106}
107
108pub struct PythonCodeActionAdapter {
110 config: Option<LanguageConfig>,
111}
112
113impl PythonCodeActionAdapter {
114 pub fn new() -> Self {
116 Self { config: None }
117 }
118
119 pub fn with_config(config: LanguageConfig) -> Self {
121 Self {
122 config: Some(config),
123 }
124 }
125}
126
127impl Default for PythonCodeActionAdapter {
128 fn default() -> Self {
129 Self::new()
130 }
131}
132
133impl CodeActionProvider for PythonCodeActionAdapter {
134 fn language(&self) -> &str {
135 "python"
136 }
137
138 fn suggest_actions(
139 &self,
140 _diagnostic: &Diagnostic,
141 _code: &str,
142 ) -> ProviderResult<Vec<String>> {
143 Ok(vec![])
145 }
146
147 fn apply_action(&self, code: &str, _action: &str) -> ProviderResult<String> {
148 Ok(code.to_string())
150 }
151
152 fn config(&self) -> Option<&LanguageConfig> {
153 self.config.as_ref()
154 }
155}
156
157#[cfg(test)]
158mod tests {
159 use super::*;
160
161 #[test]
162 fn test_rust_code_action_adapter_language() {
163 let adapter = RustCodeActionAdapter::new();
164 assert_eq!(adapter.language(), "rust");
165 }
166
167 #[test]
168 fn test_typescript_code_action_adapter_language() {
169 let adapter = TypeScriptCodeActionAdapter::new();
170 assert_eq!(adapter.language(), "typescript");
171 }
172
173 #[test]
174 fn test_python_code_action_adapter_language() {
175 let adapter = PythonCodeActionAdapter::new();
176 assert_eq!(adapter.language(), "python");
177 }
178
179 #[test]
180 fn test_rust_code_action_adapter_no_config() {
181 let adapter = RustCodeActionAdapter::new();
182 assert!(adapter.config().is_none());
183 }
184}