use crate::query::adj_ast;
use crate::syntax::builders::member_access::build_member_access_node;
use crate::syntax::fields::python::attribute;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::utilities::text_nodes::node_to_str;
use crate::{CodeGraph, NodeId};
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let attr_id = args.required_field_alt(n_id, attribute::ATTRIBUTE)?;
let mut obj_id = args.required_field_alt(n_id, attribute::OBJECT)?;
if graph.label_type(obj_id) == Some("parenthesized_expression") {
let childs = adj_ast(graph, obj_id, Some(1), &[]);
if childs.len() == 3 {
obj_id = childs.get(1).copied().unwrap_or(obj_id);
}
}
let member = node_to_str(graph, attr_id);
let expression = node_to_str(graph, obj_id);
build_member_access_node(args, n_id, member, expression, obj_id).map(Some)
}