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

Method extract_rust_route_macro

codegraph-kernel/src/rustlang.rs:1091–1143  ·  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

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

Callers 1

Calls 7

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

Tested by

no test coverage detected