MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_rust_route_macro

Method extract_rust_route_macro

codegraph-kernel/src/rustlang.rs:1082–1135  ·  view source on GitHub ↗

extractRustRouteMacro — body-walker-only; bare `routes`/`catchers` identifiers only (`rocket::routes![…]` is skipped); identifier runs in the token tree join with `::`, flushed on `,` and at end.

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1080 /// identifiers only (`rocket::routes![…]` is skipped); identifier runs in
1081 /// the token tree join with `::`, flushed on `,` and at end.
1082 fn extract_rust_route_macro(&mut self, node: Node<'t>) {
1083 let Some(macro_name) = node.named_child(0) else { return };
1084 let name = self.text(macro_name);
1085 if name != "routes" && name != "catchers" {
1086 return;
1087 }
1088 let token_tree = (0..node.named_child_count())
1089 .filter_map(|i| node.named_child(i))
1090 .find(|c| c.kind() == "token_tree");
1091 let Some(token_tree) = token_tree else { return };
1092 if self.stack.is_empty() {
1093 return;
1094 }
1095 let from = self.top_row();
1096 let refs_kind = edge_kind_index("references").unwrap();
1097
1098 let mut parts: Vec<&str> = Vec::new();
1099 let mut line = 0u32;
1100 let mut column_byte = 0usize;
1101 let mut row = 0usize;
1102 macro_rules! flush {
1103 () => {
1104 if !parts.is_empty() {
1105 let joined = parts.join("::");
1106 let column = util::col16(self.src, &self.line_starts, row, column_byte);
1107 let name_ref = self.arena.put(&joined);
1108 self.tables.push_ref(&RefRow {
1109 from_idx: from,
1110 kind: refs_kind,
1111 line,
1112 column,
1113 reference_name: name_ref,
1114 candidates: NONE_STR,
1115 from_id_str: NONE_STR,
1116 });
1117 parts.clear();
1118 }
1119 };
1120 }
1121 for i in 0..token_tree.child_count() {
1122 let Some(t) = token_tree.child(i) else { continue };
1123 if t.kind() == "identifier" {
1124 if parts.is_empty() {
1125 line = t.start_position().row as u32 + 1;
1126 column_byte = t.start_byte();
1127 row = t.start_position().row;
1128 }
1129 parts.push(self.text(t));
1130 } else if t.kind() == "," {
1131 flush!();
1132 }
1133 }
1134 flush!();
1135 }
1136
1137 /// extractInheritance — the rust-reachable cases: trait_bounds
1138 /// (supertraits; a scoped `fmt::Debug` bound matches NO case and is

Callers 1

Calls 5

edge_kind_indexFunction · 0.85
pushMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45

Tested by

no test coverage detected