fluidattacks-blends-domain 0.4.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Counterpart of `blends/path_search/search/if_statement.py`.

use alloc::vec;
use alloc::vec::Vec;

use crate::path_search::search::{SearchArgs, SearchResult};
use crate::syntax::SyntaxNode;
use crate::CodeGraph;

pub fn search(args: &SearchArgs<'_>) -> Vec<SearchResult> {
    if args.def_only {
        return Vec::new();
    }
    let Some(SyntaxNode::If { condition_id, .. }) = args.graph.nodes.get(&args.n_id) else {
        return Vec::new();
    };
    let c_id = *condition_id;
    let matched = match args.graph.label_type(c_id) {
        Some("SymbolLookup") => {
            args.graph.nodes.get(&c_id).and_then(SyntaxNode::symbol) == Some(args.symbol)
        }
        Some("MethodInvocation") => args
            .graph
            .nodes
            .get(&c_id)
            .and_then(SyntaxNode::expression)
            .is_some_and(|expression| {
                !expression.is_empty()
                    && expression
                        .rsplit_once('.')
                        .map_or(expression, |(head, _)| head)
                        == args.symbol
            }),
        _ => false,
    };
    if matched {
        return vec![(false, c_id)];
    }
    Vec::new()
}