MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / detect

Method detect

atomic-semantic/src/parsers/mod.rs:84–116  ·  view source on GitHub ↗

Detect language from a file path extension. Returns `None` for unsupported or unknown file types.

(path: &str)

Source from the content-addressed store, hash-verified

82 ///
83 /// Returns `None` for unsupported or unknown file types.
84 pub fn detect(path: &str) -> Option<Self> {
85 let lower = path.to_ascii_lowercase();
86
87 if lower.ends_with(".tsx") {
88 Some(Language::Tsx)
89 } else if lower.ends_with(".ts") || lower.ends_with(".mts") || lower.ends_with(".cts") {
90 Some(Language::TypeScript)
91 } else if lower.ends_with(".py") || lower.ends_with(".pyi") {
92 Some(Language::Python)
93 } else if lower.ends_with(".rs") {
94 Some(Language::Rust)
95 } else if lower.ends_with(".go") {
96 Some(Language::Go)
97 } else if lower.ends_with(".java") {
98 Some(Language::Java)
99 } else if lower.ends_with(".cpp")
100 || lower.ends_with(".cc")
101 || lower.ends_with(".cxx")
102 || lower.ends_with(".hpp")
103 || lower.ends_with(".hxx")
104 {
105 Some(Language::Cpp)
106 } else if lower.ends_with(".h") {
107 // .h could be C or C++ — default to C++ as it's a superset
108 Some(Language::Cpp)
109 } else if lower.ends_with(".c") {
110 Some(Language::C)
111 } else if lower.ends_with(".swift") {
112 Some(Language::Swift)
113 } else {
114 None
115 }
116 }
117
118 /// Returns the human-readable language name.
119 pub fn name(&self) -> &'static str {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected