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::MethodDeclaration {
name,
parameters_id,
..
}) = args.graph.nodes.get(&args.n_id)
else {
return Vec::new();
};
if name.as_deref() == Some(args.symbol) {
return vec![(true, args.n_id)];
}
let pl_id = parameters_id.unwrap_or(args.n_id);
if args.graph.label_type(pl_id) == Some("Parameter") {
if args.graph.nodes.get(&pl_id).and_then(SyntaxNode::variable) == Some(args.symbol) {
return vec![(true, pl_id)];
}
return Vec::new();
}
for c_id in adj_ast(args.graph, pl_id, None, &["Parameter"]) {
if args.graph.nodes.get(&c_id).and_then(SyntaxNode::variable) == Some(args.symbol) {
return vec![(true, c_id)];
}
}
Vec::new()
}