Skip to main content

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        let keywords = [("fn", true), ("struct", true), ("impl", true)];
24
25        for (keyword, _) in &keywords {
26            if context.prefix.is_empty() || keyword.starts_with(&context.prefix) {
27                suggestions.push(CompletionSuggestion::new(
28                    keyword.to_string(),
29                    CompletionKind::Keyword,
30                    context.clone(),
31                ));
32            }
33        }
34
35        suggestions
36    }
37
38    fn language_name(&self) -> &str {
39        "rust"
40    }
41
42    fn supports_language(&self, language: &str) -> bool {
43        language == "rust" || language == "rs"
44    }
45}