codetether_rlm/oracle/tree_sitter_oracle/
structs.rs1use anyhow::Result;
2
3use super::{StructDefinition, TreeSitterOracle, extract};
4
5const STRUCTS_QUERY: &str = r#"
6(struct_item
7 name: (type_identifier) @name
8 body: (field_declaration_list)? @body)
9"#;
10
11impl TreeSitterOracle {
12 pub fn get_structs(&mut self) -> Result<Vec<StructDefinition>> {
14 let result = self.query(STRUCTS_QUERY)?;
15 result.matches.into_iter().map(struct_definition).collect()
16 }
17}
18
19fn struct_definition(m: super::AstMatch) -> Result<StructDefinition> {
20 let body = m.captures.get("body").cloned().unwrap_or_default();
21 Ok(StructDefinition {
22 name: m.captures.get("name").cloned().unwrap_or_default(),
23 fields: extract::struct_fields(&body)?,
24 line: m.line,
25 })
26}