code_analyze_mcp/languages/
typescript.rs1pub const ELEMENT_QUERY: &str = r#"
3(function_declaration) @function
4(class_declaration) @class
5(method_definition) @function
6(interface_declaration) @class
7(type_alias_declaration) @class
8(enum_declaration) @class
9(abstract_class_declaration) @class
10"#;
11
12pub const CALL_QUERY: &str = r#"
14(call_expression
15 function: (identifier) @call)
16(call_expression
17 function: (member_expression property: (property_identifier) @call))
18"#;
19
20pub const REFERENCE_QUERY: &str = r#"
22(type_identifier) @type_ref
23"#;
24
25pub const IMPORT_QUERY: &str = r#"
27(import_statement) @import_path
28"#;
29
30use tree_sitter::Node;
31
32pub fn extract_inheritance(node: &Node, source: &str) -> Vec<String> {
34 let mut inherits = Vec::new();
35
36 for i in 0..node.named_child_count() {
38 if let Some(child) = node.named_child(i as u32)
39 && child.kind() == "class_heritage"
40 {
41 for j in 0..child.named_child_count() {
43 if let Some(clause) = child.named_child(j as u32) {
44 if clause.kind() == "extends_clause" {
45 if let Some(value) = clause.child_by_field_name("value") {
47 let text = &source[value.start_byte()..value.end_byte()];
48 inherits.push(format!("extends {}", text));
49 }
50 } else if clause.kind() == "implements_clause" {
51 for k in 0..clause.named_child_count() {
53 if let Some(type_node) = clause.named_child(k as u32)
54 && type_node.kind() == "type_identifier"
55 {
56 let text = &source[type_node.start_byte()..type_node.end_byte()];
57 inherits.push(format!("implements {}", text));
58 }
59 }
60 }
61 }
62 }
63 }
64 }
65
66 inherits
67}