vtcode_core/code/code_completion/engine/
suggestions.rs1use super::CompletionKind;
2use crate::code::code_completion::context::CompletionContext;
3use crate::code::code_completion::learning::CompletionLearningData;
4use std::collections::HashMap;
5
6#[derive(Debug, Clone)]
8pub struct CompletionSuggestion {
9 pub acceptance_rate: f64,
11 pub learning_data: CompletionLearningData,
13 pub text: String,
14 pub kind: CompletionKind,
15 pub confidence: f64,
16 pub context: CompletionContext,
17 pub metadata: HashMap<String, String>,
18 pub accepted_count: usize,
19 pub rejected_count: usize,
20}
21
22impl CompletionSuggestion {
23 pub fn new(text: String, kind: CompletionKind, context: CompletionContext) -> Self {
24 Self {
25 acceptance_rate: 0.0,
26 learning_data: CompletionLearningData::default(),
27 text,
28 kind,
29 confidence: 0.5,
30 context,
31 metadata: HashMap::new(),
32 accepted_count: 0,
33 rejected_count: 0,
34 }
35 }
36
37 pub fn update_acceptance_rate(&mut self, accepted: bool) {
39 if accepted {
40 self.accepted_count += 1;
41 } else {
42 self.rejected_count += 1;
43 }
44
45 let total = self.accepted_count + self.rejected_count;
46 if total > 0 {
47 self.acceptance_rate = self.accepted_count as f64 / total as f64;
48 }
49 }
50}