Mountain/Environment/Utility/
LanguageDetection.rs

1//! # Language Detection Utilities
2//!
3//! Functions for inferring language identifiers from file paths and content.
4
5use std::{ffi::OsStr, path::Path};
6
7/// A simple utility to detect a language identifier string from a file path's
8/// extension.
9pub fn DetectLanguageIdentifierFromFilePath(Path:&Path) -> String {
10	match Path.extension().and_then(OsStr::to_str) {
11		Some("js") | Some("mjs") | Some("cjs") => "javascript",
12		Some("ts") | Some("mts") | Some("cts") => "typescript",
13		Some("jsx") => "javascriptreact",
14		Some("tsx") => "typescriptreact",
15		Some("rs") => "rust",
16		Some("md") => "markdown",
17		Some("json") => "json",
18		Some("html") => "html",
19		Some("css") => "css",
20		_ => "plaintext",
21	}
22	.to_string()
23}