gobby_code/index/indexer/
types.rs1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5use crate::projection::sync::{ProjectionSyncStatus, ProjectionTarget};
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct IndexRequest {
9 pub project_root: PathBuf,
10 #[serde(default, skip_serializing_if = "Option::is_none")]
11 pub path_filter: Option<PathBuf>,
12 #[serde(default)]
13 pub explicit_files: Vec<PathBuf>,
14 pub full: bool,
15 pub require_cpp_semantics: bool,
16 pub sync_projections: bool,
17}
18
19#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
20pub struct IndexDurations {
21 pub discovery_ms: u64,
22 pub indexing_ms: u64,
23 pub stats_ms: u64,
24 pub total_ms: u64,
25}
26
27#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28#[serde(tag = "kind", rename_all = "snake_case")]
29pub enum IndexDegradation {
30 FileIndexError {
31 file_path: String,
32 message: String,
33 },
34 ProjectionSyncSkipped {
35 reason: String,
36 },
37 ProjectionCleanupFailed {
38 file_path: String,
39 target: ProjectionTarget,
40 message: String,
41 },
42}
43
44#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
45pub struct IndexOutcome {
46 pub project_id: String,
47 pub scanned_files: usize,
48 pub indexed_files: usize,
49 pub skipped_files: usize,
50 #[serde(default, skip_serializing_if = "Vec::is_empty")]
51 pub unsupported_file_types: Vec<UnsupportedFileType>,
52 pub symbols_indexed: usize,
53 pub imports_indexed: usize,
54 pub calls_indexed: usize,
55 pub unresolved_targets_indexed: usize,
56 pub chunks_indexed: usize,
57 #[serde(default, skip_serializing_if = "is_zero")]
58 pub tombstones_indexed: usize,
59 #[serde(default, skip_serializing_if = "Vec::is_empty")]
60 pub indexed_file_paths: Vec<String>,
61 pub durations: IndexDurations,
62 #[serde(default, skip_serializing_if = "Vec::is_empty")]
63 pub degraded: Vec<IndexDegradation>,
64 #[serde(default, skip_serializing_if = "Option::is_none")]
65 pub projection_sync: Option<ProjectionSyncStatus>,
66 #[serde(default, skip_serializing_if = "Option::is_none")]
67 pub overlay: Option<OverlayIndexMetadata>,
68}
69
70#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
71pub struct UnsupportedFileType {
72 pub extension: String,
73 pub files: usize,
74 #[serde(default, skip_serializing_if = "Vec::is_empty")]
75 pub examples: Vec<String>,
76}
77
78#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
79pub struct OverlayIndexMetadata {
80 pub overlay_project_id: String,
81 pub overlay_root: String,
82 pub parent_project_id: String,
83 pub parent_root: String,
84}
85
86impl IndexOutcome {
87 pub(super) fn new(project_id: &str) -> Self {
88 Self {
89 project_id: project_id.to_string(),
90 ..Self::default()
91 }
92 }
93
94 pub(super) fn add_counts(&mut self, counts: FileIndexCounts) {
95 self.indexed_files += counts.indexed_files;
96 self.symbols_indexed += counts.symbols_indexed;
97 self.imports_indexed += counts.imports_indexed;
98 self.calls_indexed += counts.calls_indexed;
99 self.unresolved_targets_indexed += counts.unresolved_targets_indexed;
100 self.chunks_indexed += counts.chunks_indexed;
101 if counts.indexed_files > 0 {
102 self.indexed_file_paths.push(counts.file_path);
103 }
104 }
105
106 pub(super) fn set_unsupported_file_types(&mut self, unsupported: Vec<UnsupportedFileType>) {
107 self.unsupported_file_types = unsupported;
108 }
109}
110
111fn is_zero(value: &usize) -> bool {
112 *value == 0
113}
114
115#[derive(Debug, Clone, Default, PartialEq, Eq)]
116pub(super) struct FileIndexCounts {
117 pub(super) file_path: String,
118 pub(super) indexed_files: usize,
119 pub(super) symbols_indexed: usize,
120 pub(super) imports_indexed: usize,
121 pub(super) calls_indexed: usize,
122 pub(super) unresolved_targets_indexed: usize,
123 pub(super) chunks_indexed: usize,
124}