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 Body {
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 = "Option::is_none", default)]
19 pub diagnostic_groups: Option<Vec<(String, serde_json::Value)>>,
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/*
72#[derive(Debug, Clone)]
73pub struct SerializedJson<T> {
74 raw: Box<RawValue>,
75 _phantom: PhantomData<T>,
76}
77
78impl<T> SerializedJson<T>
79where
80 T: Serialize + for<'de> Deserialize<'de>,
81{
82 pub fn new(value: &T) -> Result<Self, serde_json::Error> {
83 Ok(SerializedJson {
84 raw: serde_json::value::to_raw_value(value)?,
85 _phantom: PhantomData,
86 })
87 }
88
89 pub fn deserialize(&self) -> Result<T, serde_json::Error> {
90 serde_json::from_str(self.raw.get())
91 }
92
93 pub fn as_raw(&self) -> &RawValue {
94 &self.raw
95 }
96
97 pub fn into_raw(self) -> Box<RawValue> {
98 self.raw
99 }
100}
101
102impl<T> Serialize for SerializedJson<T> {
103 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
104 where
105 S: Serializer,
106 {
107 self.raw.serialize(serializer)
108 }
109}
110
111impl<'de, T> Deserialize<'de> for SerializedJson<T> {
112 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
113 where
114 D: Deserializer<'de>,
115 {
116 let raw = Box::<RawValue>::deserialize(deserializer)?;
117 Ok(SerializedJson {
118 raw,
119 _phantom: PhantomData,
120 })
121 }
122}
123*/