fluidattacks-blends-domain 0.3.0

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

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

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

pub fn search(args: &SearchArgs<'_>) -> Vec<SearchResult> {
    let Some(SyntaxNode::ForStatement {
        initializer_id: Some(init_id),
        ..
    }) = args.graph.nodes.get(&args.n_id)
    else {
        return Vec::new();
    };
    let init_id = *init_id;

    let matches_directly = args.graph.label_type(init_id) == Some("SymbolLookup")
        && args.graph.nodes.get(&init_id).and_then(SyntaxNode::symbol) == Some(args.symbol);
    if matches_directly {
        return vec![(true, args.n_id)];
    }

    for c_id in adj_ast(args.graph, init_id, None, &["SymbolLookup"]) {
        if args.graph.nodes.get(&c_id).and_then(SyntaxNode::symbol) == Some(args.symbol) {
            return vec![(true, args.n_id)];
        }
    }
    Vec::new()
}