Skip to main content

classify_hint

Function classify_hint 

Source
pub fn classify_hint(
    hint: &PatternHintInput,
    language: &str,
) -> Vec<&'static str>
Expand description

Classify a PatternHintInput using both node kind and callee-text inspection.

Returns a Vec of category name(s) the hint belongs to. In v0 the return is always 0 or 1 entries — the regex tables are designed to be disjoint per language. The Vec return is forward-looking: a future category that legitimately co-occurs with another (e.g. console.error(err) as both logging and error_handling) can be added without an API break.

§Dispatch order for call_expression / call

Priority: async_patterns > logging > data_access. The first match wins. The order is load-bearing only if the disjoint-regex invariant is ever relaxed.

§macro_invocation

Defaults to resource_management. Rust logging macros (tracing::*!, log::*!, println!, eprintln!, print!, eprint!, dbg!) are reclassified as logging via resource_management::excludes_callee.

§Other node kinds

Falls through to category_for_node_kind — the existing node-kind-only table.

§Examples

use sdivi_patterns::queries::classify_hint;
use sdivi_patterns::PatternHintInput;

let hint = PatternHintInput {
    node_kind: "call_expression".to_string(),
    text: "console.log(\"x\")".to_string(),
};
assert_eq!(classify_hint(&hint, "typescript"), vec!["logging"]);

let mac = PatternHintInput {
    node_kind: "macro_invocation".to_string(),
    text: "vec![1, 2, 3]".to_string(),
};
assert_eq!(classify_hint(&mac, "rust"), vec!["resource_management"]);