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

Method extract_rust_route_macro

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

1064 /// identifiers only (`rocket::routes![…]` is skipped); identifier runs in
1065 /// the token tree join with `::`, flushed on `,` and at end.
1066 fn extract_rust_route_macro(&mut self, node: Node<'t>) {
1067 let Some(macro_name) = node.named_child(0) else { return };
1068 let name = self.text(macro_name);
1069 if name != "routes" && name != "catchers" {
1070 return;
1071 }
1072 let token_tree = (0..node.named_child_count())
1073 .filter_map(|i| node.named_child(i))
1074 .find(|c| c.kind() == "token_tree");
1075 let Some(token_tree) = token_tree else { return };
1076 if self.stack.is_empty() {
1077 return;
1078 }
1079 let from = self.top_row();
1080 let refs_kind = edge_kind_index("references").unwrap();
1081
1082 let mut parts: Vec<&str> = Vec::new();
1083 let mut line = 0u32;
1084 let mut column_byte = 0usize;
1085 let mut row = 0usize;
1086 macro_rules! flush {
1087 () => {
1088 if !parts.is_empty() {
1089 let joined = parts.join("::");
1090 let column = util::col16(self.src, &self.line_starts, row, column_byte);
1091 let name_ref = self.arena.put(&joined);
1092 self.tables.push_ref(&RefRow {
1093 from_idx: from,
1094 kind: refs_kind,
1095 line,
1096 column,
1097 reference_name: name_ref,
1098 candidates: NONE_STR,
1099 from_id_str: NONE_STR,
1100 });
1101 parts.clear();
1102 }
1103 };
1104 }
1105 for t in token_tree.children(&mut token_tree.walk()) {
1106 if t.kind() == "identifier" {
1107 if parts.is_empty() {
1108 line = t.start_position().row as u32 + 1;
1109 column_byte = t.start_byte();
1110 row = t.start_position().row;
1111 }
1112 parts.push(self.text(t));
1113 } else if t.kind() == "," {
1114 flush!();
1115 }
1116 }
1117 flush!();
1118 }
1119
1120 /// extractInheritance — the rust-reachable cases: trait_bounds
1121 /// (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