Skip to content

Commit

Permalink
feat: Support query is_struct attribute in classes table
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed May 1, 2024
1 parent ed94c19 commit 83dd0cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ fn select_classes(
continue;
}

if field_name == "is_struct" {
values.push(Value::Boolean(class.is_struct));
continue;
}

if field_name == "file" {
values.push(Value::Text(class.location.file.to_string()));
continue;
Expand Down
6 changes: 5 additions & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ lazy_static! {
map.insert("access_modifier", DataType::Integer);
map.insert("is_variadic", DataType::Boolean);
map.insert("is_volatile", DataType::Boolean);
map.insert("is_struct", DataType::Boolean);

// Source code location columns
map.insert("file", DataType::Text);
Expand All @@ -33,7 +34,10 @@ lazy_static! {
lazy_static! {
pub static ref TABLES_FIELDS_NAMES: HashMap<&'static str, Vec<&'static str>> = {
let mut map = HashMap::new();
map.insert("classes", vec!["name", "line", "column", "offset"]);
map.insert(
"classes",
vec!["name", "is_struct", "line", "column", "offset"],
);
map.insert(
"functions",
vec![
Expand Down
4 changes: 4 additions & 0 deletions src/visitor/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::visitor::location;

pub struct ClassNode {
pub name: String,
pub is_struct: bool,
pub location: location::SourceLocation,
}

Expand Down Expand Up @@ -60,8 +61,11 @@ extern "C" fn visit_children(
let location = location::visit_source_location(cursor);

let classes = &mut *(data as *mut Vec<ClassNode>);
let is_struct = cursor_kind == CXCursor_StructDecl;

classes.push(ClassNode {
name: class_name.to_string(),
is_struct,
location,
});

Expand Down

0 comments on commit 83dd0cf

Please sign in to comment.