1use serde::{Deserialize, Serialize};
2use std::ops::Range;
3
4use crate::PredictEditsGitInfo;
5
6// TODO: snippet ordering within file / relative to excerpt
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct PredictEditsRequest {
10 pub excerpt: String,
11 /// Within `signatures`
12 pub excerpt_parent: Option<usize>,
13 pub signatures: Vec<Signature>,
14 pub referenced_declarations: Vec<ReferencedDeclaration>,
15 pub events: Vec<Event>,
16 #[serde(default)]
17 pub can_collect_data: bool,
18 #[serde(skip_serializing_if = "Vec::is_empty", default)]
19 pub diagnostic_groups: Vec<DiagnosticGroup>,
20 /// Info about the git repository state, only present when can_collect_data is true.
21 #[serde(skip_serializing_if = "Option::is_none", default)]
22 pub git_info: Option<PredictEditsGitInfo>,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub enum Event {}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct Signature {
30 pub text: String,
31 pub text_is_truncated: bool,
32 #[serde(skip_serializing_if = "Option::is_none", default)]
33 pub parent_index: Option<usize>,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct ReferencedDeclaration {
38 pub text: String,
39 pub text_is_truncated: bool,
40 /// Range within `text`
41 pub signature_range: Range<usize>,
42 /// Index within `signatures`.
43 #[serde(skip_serializing_if = "Option::is_none", default)]
44 pub parent_index: Option<usize>,
45 pub score_components: ScoreComponents,
46 pub signature_score: f32,
47 pub declaration_score: f32,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct ScoreComponents {
52 pub is_same_file: bool,
53 pub is_referenced_nearby: bool,
54 pub is_referenced_in_breadcrumb: bool,
55 pub reference_count: usize,
56 pub same_file_declaration_count: usize,
57 pub declaration_count: usize,
58 pub reference_line_distance: u32,
59 pub declaration_line_distance: u32,
60 pub declaration_line_distance_rank: usize,
61 pub containing_range_vs_item_jaccard: f32,
62 pub containing_range_vs_signature_jaccard: f32,
63 pub adjacent_vs_item_jaccard: f32,
64 pub adjacent_vs_signature_jaccard: f32,
65 pub containing_range_vs_item_weighted_overlap: f32,
66 pub containing_range_vs_signature_weighted_overlap: f32,
67 pub adjacent_vs_item_weighted_overlap: f32,
68 pub adjacent_vs_signature_weighted_overlap: f32,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct DiagnosticGroup {
73 pub language_server: String,
74 pub diagnostic_group: serde_json::Value,
75}
76
77/*
78#[derive(Debug, Clone)]
79pub struct SerializedJson<T> {
80 raw: Box<RawValue>,
81 _phantom: PhantomData<T>,
82}
83
84impl<T> SerializedJson<T>
85where
86 T: Serialize + for<'de> Deserialize<'de>,
87{
88 pub fn new(value: &T) -> Result<Self, serde_json::Error> {
89 Ok(SerializedJson {
90 raw: serde_json::value::to_raw_value(value)?,
91 _phantom: PhantomData,
92 })
93 }
94
95 pub fn deserialize(&self) -> Result<T, serde_json::Error> {
96 serde_json::from_str(self.raw.get())
97 }
98
99 pub fn as_raw(&self) -> &RawValue {
100 &self.raw
101 }
102
103 pub fn into_raw(self) -> Box<RawValue> {
104 self.raw
105 }
106}
107
108impl<T> Serialize for SerializedJson<T> {
109 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
110 where
111 S: Serializer,
112 {
113 self.raw.serialize(serializer)
114 }
115}
116
117impl<'de, T> Deserialize<'de> for SerializedJson<T> {
118 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
119 where
120 D: Deserializer<'de>,
121 {
122 let raw = Box::<RawValue>::deserialize(deserializer)?;
123 Ok(SerializedJson {
124 raw,
125 _phantom: PhantomData,
126 })
127 }
128}
129*/