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

Method _extract_namespace_from_content

rust-core/src/codegraph/parser.rs:566–616  ·  view source on GitHub ↗
(&self, content: &str, file_path: &PathBuf)

Source from the content-addressed store, hash-verified

564 }
565
566 fn _extract_namespace_from_content(&self, content: &str, file_path: &PathBuf) -> String {
567 let language = self._detect_language(file_path);
568
569 match language.as_str() {
570 "rust" => {
571 // 查找mod声明
572 for line in content.lines() {
573 if line.trim().starts_with("mod ") {
574 if let Some(name) = line.trim().split_whitespace().nth(1) {
575 return name.to_string();
576 }
577 }
578 }
579 "crate".to_string()
580 },
581 "python" => {
582 // 查找包名或模块名
583 for line in content.lines() {
584 if line.trim().starts_with("__package__") {
585 if let Some(name) = line.split('=').nth(1) {
586 return name.trim().trim_matches('"').trim_matches('\'').to_string();
587 }
588 }
589 }
590 "global".to_string()
591 },
592 "java" => {
593 // 查找package声明
594 for line in content.lines() {
595 if line.trim().starts_with("package ") {
596 if let Some(package) = line.trim().split_whitespace().nth(1) {
597 return package.trim_end_matches(';').to_string();
598 }
599 }
600 }
601 "default".to_string()
602 },
603 "cpp" => {
604 // 查找namespace声明
605 for line in content.lines() {
606 if line.trim().starts_with("namespace ") {
607 if let Some(name) = line.trim().split_whitespace().nth(1) {
608 return name.to_string();
609 }
610 }
611 }
612 "global".to_string()
613 },
614 _ => "global".to_string(),
615 }
616 }
617
618 /// 更新代码片段索引(包含真实代码内容)
619 fn _update_snippet_index_with_content(

Callers 2

_extract_namespaceMethod · 0.45
parse_fileMethod · 0.45

Calls 2

to_stringMethod · 0.80
_detect_languageMethod · 0.45

Tested by

no test coverage detected