apollo-language-server 0.7.0

A GraphQL language server with first-class support for Apollo Federation
Documentation
use apollo_parser::{SyntaxKind, SyntaxNode};

pub(crate) fn get_ancestor_node_of_kind(
    node: &SyntaxNode,
    kind: SyntaxKind,
    ignore: Option<Vec<SyntaxKind>>,
) -> Option<SyntaxNode> {
    if node.kind() == kind {
        return Some(node.clone());
    }
    if let Some(ignore) = &ignore {
        if ignore.contains(&node.kind()) {
            return None;
        }
    }
    let parent = node.parent()?;
    if parent.kind() == kind {
        Some(parent)
    } else {
        get_ancestor_node_of_kind(&parent, kind, ignore)
    }
}