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

Method _update_snippet_index

rust-core/src/codegraph/parser.rs:332–374  ·  view source on GitHub ↗

更新代码片段索引

(
        &mut self,
        file_path: &PathBuf,
        class_ids: &[Uuid],
        function_ids: &[Uuid],
        entity_graph: &EntityGraph,
    )

Source from the content-addressed store, hash-verified

330
331 /// 更新代码片段索引
332 fn _update_snippet_index(
333 &mut self,
334 file_path: &PathBuf,
335 class_ids: &[Uuid],
336 function_ids: &[Uuid],
337 entity_graph: &EntityGraph,
338 ) -> Result<(), String> {
339 // 读取文件内容
340 let content = fs::read_to_string(file_path)
341 .map_err(|e| format!("Failed to read file for snippet indexing: {}", e))?;
342
343 let lines: Vec<&str> = content.lines().collect();
344
345 // 为类添加代码片段
346 for &class_id in class_ids {
347 if let Some(class) = entity_graph.get_class_by_id(&class_id) {
348 let snippet_content = self._extract_code_snippet(&lines, class.line_start, class.line_end);
349 let snippet_info = crate::codegraph::types::SnippetInfo {
350 file_path: file_path.clone(),
351 line_start: class.line_start,
352 line_end: class.line_end,
353 cached_content: Some(snippet_content),
354 };
355 self.snippet_index.add_snippet(class_id, snippet_info);
356 }
357 }
358
359 // 为函数添加代码片段
360 for &function_id in function_ids {
361 if let Some(function) = self._get_function_by_id(&function_id) {
362 let snippet_content = self._extract_code_snippet(&lines, function.line_start, function.line_end);
363 let snippet_info = crate::codegraph::types::SnippetInfo {
364 file_path: file_path.clone(),
365 line_start: function.line_start,
366 line_end: function.line_end,
367 cached_content: Some(snippet_content),
368 };
369 self.snippet_index.add_snippet(function_id, snippet_info);
370 }
371 }
372
373 Ok(())
374 }
375
376 /// 检测文件语言
377 fn _detect_language(&self, file_path: &Path) -> String {

Callers 1

refresh_fileMethod · 0.45

Calls 4

get_class_by_idMethod · 0.80
_extract_code_snippetMethod · 0.80
add_snippetMethod · 0.80
_get_function_by_idMethod · 0.80

Tested by

no test coverage detected