pub mod async_patterns;
pub mod class_hierarchy;
pub mod collection_pipelines;
pub mod comprehensions;
pub mod concurrency;
pub mod data_access;
pub mod decorators;
pub mod error_handling;
pub mod framework_hooks;
pub mod http_routing;
pub mod logging;
pub mod null_safety;
pub mod resource_management;
pub mod schema_validation;
pub mod serialization;
pub mod state_management;
pub mod state_store;
pub mod testing;
pub mod type_assertions;
use crate::hint_input::PatternHintInput;
pub const ALL_CATEGORIES: &[&str] = &[
"async_patterns",
"class_hierarchy",
"collection_pipelines",
"comprehensions",
"concurrency",
"data_access",
"decorators",
"error_handling",
"framework_hooks",
"http_routing",
"logging",
"null_safety",
"resource_management",
"schema_validation",
"serialization",
"state_management",
"state_store",
"testing",
"type_assertions",
];
pub fn category_for_node_kind(node_kind: &str, _language: &str) -> Option<&'static str> {
if async_patterns::NODE_KINDS.contains(&node_kind) {
Some("async_patterns")
} else if class_hierarchy::NODE_KINDS.contains(&node_kind) {
Some("class_hierarchy")
} else if comprehensions::NODE_KINDS.contains(&node_kind) {
Some("comprehensions")
} else if concurrency::NODE_KINDS.contains(&node_kind) {
Some("concurrency")
} else if data_access::NODE_KINDS.contains(&node_kind) {
Some("data_access")
} else if decorators::NODE_KINDS.contains(&node_kind) {
Some("decorators")
} else if error_handling::NODE_KINDS.contains(&node_kind) {
Some("error_handling")
} else if null_safety::NODE_KINDS.contains(&node_kind) {
Some("null_safety")
} else if resource_management::NODE_KINDS.contains(&node_kind) {
Some("resource_management")
} else if state_management::NODE_KINDS.contains(&node_kind) {
Some("state_management")
} else if type_assertions::NODE_KINDS.contains(&node_kind) {
Some("type_assertions")
} else {
None
}
}
#[allow(clippy::type_complexity)] const CALL_DISPATCH: &[(&str, fn(&str, &str) -> bool)] = &[
("async_patterns", async_patterns::matches_callee),
("testing", testing::matches_callee),
("serialization", serialization::matches_callee),
("schema_validation", schema_validation::matches_callee),
("state_store", state_store::matches_callee),
("framework_hooks", framework_hooks::matches_callee),
("http_routing", http_routing::matches_callee),
("logging", logging::matches_callee),
("data_access", data_access::matches_callee),
("collection_pipelines", collection_pipelines::matches_callee),
("concurrency", concurrency::matches_callee),
];
pub fn classify_hint(hint: &PatternHintInput, language: &str) -> Vec<&'static str> {
match hint.node_kind.as_str() {
"call_expression" | "call" => {
for &(category, matches) in CALL_DISPATCH {
if matches(&hint.text, language) {
return vec![category];
}
}
vec![]
}
"macro_invocation" => {
if resource_management::excludes_callee(&hint.text, language)
&& logging::matches_callee(&hint.text, language)
{
return vec!["logging"];
}
vec!["resource_management"]
}
other => category_for_node_kind(other, language)
.map(|c| vec![c])
.unwrap_or_default(),
}
}
#[cfg(test)]
mod tests;
#[cfg(test)]
mod tests_m45_2;