1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Node-kind and callee-text classification for async-concurrency patterns.
//!
//! ## Node-kind detection
//!
//! - `await_expression` — `.await` on a `Future` (Rust) or `await expr` (TS/JS)
//!
//! ## Callee-text detection (TypeScript / JavaScript only)
//!
//! Promise-chain call shapes registered at CALL_DISPATCH slot P1:
//! - `.then(…)`, `.catch(…)`, `.finally(…)`
//!
//! Both paths together make `async_patterns` a **hybrid** category: `await_expression`
//! nodes arrive via [`category_for_node_kind`](super::category_for_node_kind), and
//! Promise-chain `call_expression` nodes arrive via [`matches_callee`] in
//! [`super::classify_hint`]'s CALL_DISPATCH.
use LazyLock;
use Regex;
/// Tree-sitter node kinds for async-concurrency patterns.
///
/// - `await_expression`: `.await` on a `Future`
pub const NODE_KINDS: & = &;
// TypeScript / JavaScript:
// \.(then|catch|finally)\( — Promise chain calls.
// No ^ anchor: the receiver expression precedes the dot, so the match is
// suffix-anchored to the method name. This deliberately matches
// "promise.then(" and "fetch(...).then(" without matching "getNextValue(".
static TS_JS_RE: = new;
/// Return `true` when `text` looks like an async-pattern call callee for `language`.
///
/// Covers Promise-chain `call_expression` shapes (`.then`, `.catch`, `.finally`)
/// in TypeScript and JavaScript. `await_expression` nodes are routed via
/// [`NODE_KINDS`] already; this function handles the remaining callee shapes.
/// Other languages return `false` — their async primitives are node-kind-routed.
///
/// # Examples
///
/// ```rust
/// use sdivi_patterns::queries::async_patterns::matches_callee;
///
/// assert!(matches_callee("promise.then(resolve)", "typescript"));
/// assert!(matches_callee("fetch(url).catch(err => {})", "javascript"));
/// assert!(!matches_callee("Math.max(a, b)", "typescript"));
/// assert!(!matches_callee("promise.then(resolve)", "rust"));
/// ```