ricecoder_storage/completion/languages/
mod.rs

1//! Built-in language configurations for code completion
2//!
3//! This module provides built-in language configurations that are embedded
4//! in the ricecoder-storage crate and available as fallback when no
5//! user or project configurations are found.
6//!
7//! Supported languages:
8//! - Rust (rs)
9//! - TypeScript (ts, tsx, js, jsx)
10//! - Python (py)
11//! - Go (go)
12//! - Java (java)
13//! - Kotlin (kt, kts)
14//! - Dart (dart)
15
16/// Get all built-in completion language configurations
17pub fn get_builtin_completion_configs() -> Vec<(&'static str, &'static str)> {
18    vec![
19        ("rust", include_str!("rust.yaml")),
20        ("typescript", include_str!("typescript.yaml")),
21        ("python", include_str!("python.yaml")),
22        ("go", include_str!("go.yaml")),
23        ("java", include_str!("java.yaml")),
24        ("kotlin", include_str!("kotlin.yaml")),
25        ("dart", include_str!("dart.yaml")),
26    ]
27}
28
29/// Get a specific built-in completion language configuration
30pub fn get_completion_config(language: &str) -> Option<&'static str> {
31    match language {
32        "rust" => Some(include_str!("rust.yaml")),
33        "typescript" | "ts" | "tsx" | "js" | "jsx" => Some(include_str!("typescript.yaml")),
34        "python" | "py" => Some(include_str!("python.yaml")),
35        "go" => Some(include_str!("go.yaml")),
36        "java" => Some(include_str!("java.yaml")),
37        "kotlin" | "kt" | "kts" => Some(include_str!("kotlin.yaml")),
38        "dart" => Some(include_str!("dart.yaml")),
39        _ => None,
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_get_builtin_completion_configs() {
49        let configs = get_builtin_completion_configs();
50        assert_eq!(configs.len(), 7);
51        assert!(configs.iter().any(|(lang, _)| *lang == "rust"));
52        assert!(configs.iter().any(|(lang, _)| *lang == "typescript"));
53        assert!(configs.iter().any(|(lang, _)| *lang == "python"));
54        assert!(configs.iter().any(|(lang, _)| *lang == "go"));
55        assert!(configs.iter().any(|(lang, _)| *lang == "java"));
56        assert!(configs.iter().any(|(lang, _)| *lang == "kotlin"));
57        assert!(configs.iter().any(|(lang, _)| *lang == "dart"));
58    }
59
60    #[test]
61    fn test_get_completion_config_rust() {
62        let config = get_completion_config("rust");
63        assert!(config.is_some());
64        assert!(!config.unwrap().is_empty());
65    }
66
67    #[test]
68    fn test_get_completion_config_typescript() {
69        let config = get_completion_config("typescript");
70        assert!(config.is_some());
71        assert!(!config.unwrap().is_empty());
72    }
73
74    #[test]
75    fn test_get_completion_config_python() {
76        let config = get_completion_config("python");
77        assert!(config.is_some());
78        assert!(!config.unwrap().is_empty());
79    }
80
81    #[test]
82    fn test_get_completion_config_go() {
83        let config = get_completion_config("go");
84        assert!(config.is_some());
85        assert!(!config.unwrap().is_empty());
86    }
87
88    #[test]
89    fn test_get_completion_config_java() {
90        let config = get_completion_config("java");
91        assert!(config.is_some());
92        assert!(!config.unwrap().is_empty());
93    }
94
95    #[test]
96    fn test_get_completion_config_kotlin() {
97        let config = get_completion_config("kotlin");
98        assert!(config.is_some());
99        assert!(!config.unwrap().is_empty());
100    }
101
102    #[test]
103    fn test_get_completion_config_dart() {
104        let config = get_completion_config("dart");
105        assert!(config.is_some());
106        assert!(!config.unwrap().is_empty());
107    }
108
109    #[test]
110    fn test_get_completion_config_aliases() {
111        assert!(get_completion_config("ts").is_some());
112        assert!(get_completion_config("tsx").is_some());
113        assert!(get_completion_config("js").is_some());
114        assert!(get_completion_config("jsx").is_some());
115        assert!(get_completion_config("py").is_some());
116        assert!(get_completion_config("kt").is_some());
117        assert!(get_completion_config("kts").is_some());
118    }
119
120    #[test]
121    fn test_get_completion_config_unknown() {
122        let config = get_completion_config("unknown");
123        assert!(config.is_none());
124    }
125}