vtcode_core/code/code_completion/languages/
rust.rs

1use super::LanguageProvider;
2use crate::code::code_completion::context::CompletionContext;
3use crate::code::code_completion::engine::{CompletionKind, CompletionSuggestion};
4
5/// Rust-specific completion provider
6pub struct RustProvider;
7
8impl RustProvider {
9    pub fn new() -> Self {
10        Self
11    }
12}
13
14impl Default for RustProvider {
15    fn default() -> Self {
16        Self::new()
17    }
18}
19
20impl LanguageProvider for RustProvider {
21    fn get_completions(&self, context: &CompletionContext) -> Vec<CompletionSuggestion> {
22        let mut suggestions = Vec::new();
23
24        // Add Rust-specific keywords
25        if context.prefix.is_empty() || "fn".starts_with(&context.prefix) {
26            suggestions.push(CompletionSuggestion::new(
27                "fn".to_string(),
28                CompletionKind::Keyword,
29                context.clone(),
30            ));
31        }
32
33        if context.prefix.is_empty() || "struct".starts_with(&context.prefix) {
34            suggestions.push(CompletionSuggestion::new(
35                "struct".to_string(),
36                CompletionKind::Keyword,
37                context.clone(),
38            ));
39        }
40
41        if context.prefix.is_empty() || "impl".starts_with(&context.prefix) {
42            suggestions.push(CompletionSuggestion::new(
43                "impl".to_string(),
44                CompletionKind::Keyword,
45                context.clone(),
46            ));
47        }
48
49        suggestions
50    }
51
52    fn language_name(&self) -> &str {
53        "rust"
54    }
55
56    fn supports_language(&self, language: &str) -> bool {
57        language == "rust" || language == "rs"
58    }
59}