-
Notifications
You must be signed in to change notification settings - Fork 0
🧹 Add struct and class extraction to metadata pipeline #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e19465c
6b9f0bd
f2b61ab
7cf27fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,13 @@ pub fn extract_basic_metadata<D: Doc>( | |
| } | ||
| } | ||
|
|
||
| // Extract class and struct definitions | ||
| if let Ok(class_matches) = extract_classes(&root_node) { | ||
| for (name, info) in class_matches { | ||
| metadata.defined_symbols.insert(name, info); | ||
| } | ||
| } | ||
|
Comment on lines
+70
to
+75
|
||
|
|
||
| // Extract import statements | ||
| if let Ok(imports) = extract_imports(&root_node, &document.language) { | ||
| for (name, info) in imports { | ||
|
|
@@ -117,6 +124,43 @@ fn extract_functions<D: Doc>(root_node: &Node<D>) -> ServiceResult<RapidMap<Stri | |
| Ok(functions) | ||
| } | ||
|
|
||
| /// Extract class and struct definitions using ast-grep patterns | ||
| #[cfg(feature = "matching")] | ||
| fn extract_classes<D: Doc>(root_node: &Node<D>) -> ServiceResult<RapidMap<String, SymbolInfo>> { | ||
| let mut classes = thread_utilities::get_map(); | ||
|
|
||
| // Try different class/struct patterns based on common languages | ||
| let patterns = [ | ||
| "struct $NAME { $$$BODY }", // Rust, C++, C# | ||
| "class $NAME { $$$BODY }", // TypeScript, JavaScript, Java, C#, C++ | ||
| "class $NAME: $$$BODY", // Python | ||
| "class $NAME($$$PARAMS): $$$BODY", // Python | ||
| "type $NAME struct { $$$BODY }", // Go | ||
| "interface $NAME { $$$BODY }", // TypeScript, Java, C# | ||
| ]; | ||
|
Comment on lines
+132
to
+140
|
||
|
|
||
| for pattern in &patterns { | ||
| for node_match in root_node.find_all(pattern) { | ||
| if let Some(name_node) = node_match.get_env().get_match("NAME") { | ||
| let class_name = name_node.text().to_string(); | ||
| let position = name_node.start_pos(); | ||
|
|
||
| let symbol_info = SymbolInfo { | ||
| name: class_name.clone(), | ||
| kind: SymbolKind::Class, | ||
| position, | ||
| scope: "global".to_string(), // Simplified for now | ||
| visibility: Visibility::Public, // Simplified for now | ||
| }; | ||
|
Comment on lines
+148
to
+154
|
||
|
|
||
| classes.insert(class_name, symbol_info); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(classes) | ||
| } | ||
|
|
||
| /// Extract import statements using language-specific patterns | ||
| #[cfg(feature = "matching")] | ||
| fn extract_imports<D: Doc>( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Strengthen the test to explicitly assert that struct symbols (e.g.,
UserandRole) are present, not just any one of the union of names.Because the assertion passes if any of those names are present, the test can still succeed even if struct/class extraction is broken as long as functions are found. To verify the new behavior, add a distinct assertion that checks specifically for
User/Role(e.g., keep the existing function check and add a separateany/containsjust for struct names) so the test fails if struct extraction regresses.