MCPcopy Create free account
hub / github.com/CodeBendKit/codeseek / _update_file

Method _update_file

rust-core/src/storage/incremental.rs:97–145  ·  view source on GitHub ↗

更新文件元数据

(
        &mut self,
        file_path: &PathBuf,
        current_md5: &str,
        entity_graph: &mut EntityGraph,
        call_graph: &mut PetCodeGraph,
    )

Source from the content-addressed store, hash-verified

95
96 /// 更新文件元数据
97 fn _update_file(
98 &mut self,
99 file_path: &PathBuf,
100 current_md5: &str,
101 entity_graph: &mut EntityGraph,
102 call_graph: &mut PetCodeGraph,
103 ) -> Result<(), String> {
104 // 1. 移除旧的实体和函数
105 self._remove_file_entities(file_path, entity_graph, call_graph);
106
107 // 2. 解析文件,提取新的实体和函数
108 let (classes, functions) = self._extract_entities_from_file(file_path)?;
109
110 // 3. 添加到图中
111 let class_ids: Vec<Uuid> = classes.iter().map(|c| c.id).collect();
112 let function_ids: Vec<Uuid> = functions.iter().map(|f| f.id).collect();
113
114 for class in classes {
115 entity_graph.add_class(class);
116 }
117
118 for function in functions {
119 call_graph.add_function(function);
120 }
121
122 // 4. 分析调用关系
123 self._analyze_file_calls(file_path, &function_ids, call_graph)?;
124
125 // 5. 更新索引
126 self.file_index.rebuild_for_file(file_path, class_ids.clone(), function_ids.clone());
127
128 // 6. 更新代码片段索引
129 self._update_snippet_index(file_path, &class_ids, &function_ids)?;
130
131 // 7. 更新文件元数据
132 let metadata = FileMetadata {
133 path: file_path.clone(),
134 md5: current_md5.to_string(),
135 last_updated: Utc::now(),
136 file_size: fs::metadata(file_path)
137 .map(|m| m.len())
138 .unwrap_or(0),
139 language: self._detect_language(file_path),
140 };
141 self.file_metadata.insert(file_path.clone(), metadata);
142
143 info!("Successfully updated file: {}", file_path.display());
144 Ok(())
145 }
146
147 /// 从文件提取实体
148 fn _extract_entities_from_file(&self, file_path: &PathBuf) -> Result<(Vec<ClassInfo>, Vec<FunctionInfo>), String> {

Callers 1

refresh_fileMethod · 0.80

Calls 10

add_classMethod · 0.80
rebuild_for_fileMethod · 0.80
to_stringMethod · 0.80
insertMethod · 0.80
_remove_file_entitiesMethod · 0.45
add_functionMethod · 0.45
_analyze_file_callsMethod · 0.45
_update_snippet_indexMethod · 0.45
_detect_languageMethod · 0.45

Tested by

no test coverage detected