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

Method normalize_fn_ref_value

codegraph-kernel/src/go.rs:1234–1292  ·  view source on GitHub ↗

normalizeValue with GO_SPEC's transparent layers (literal_element, expression_list — both fan out to named children).

(&mut self, v: Node<'t>, from: u32, depth: u32, container: Node<'t>)

Source from the content-addressed store, hash-verified

1232 /// normalizeValue with GO_SPEC's transparent layers (literal_element,
1233 /// expression_list — both fan out to named children).
1234 fn normalize_fn_ref_value(&mut self, v: Node<'t>, from: u32, depth: u32, container: Node<'t>) {
1235 stack_guard!();
1236 if depth > 4 {
1237 return;
1238 }
1239 match v.kind() {
1240 "identifier" => {
1241 let name = self.text(v).to_string();
1242 if name.is_empty() || is_stoplisted(&name) {
1243 return;
1244 }
1245 let p = v.start_position();
1246 self.fn_ref_cands.push(Cand {
1247 from,
1248 name,
1249 line: p.row as u32 + 1,
1250 column_byte: v.start_byte(),
1251 row: p.row,
1252 node: container,
1253 });
1254 }
1255 // #1820: preserve the receiver of a method value. The name is
1256 // rebuilt from operand and field, as normalizeSpecial does, so a
1257 // comment or line break beside the dot keeps the candidate.
1258 // NAME_STOPLIST applies to the whole name and holds no dotted
1259 // word, so it never drops one: `raft.None` is a candidate even
1260 // though a bare `None` is not.
1261 "selector_expression" => {
1262 let (Some(operand), Some(field)) =
1263 (v.child_by_field_name("operand"), v.child_by_field_name("field"))
1264 else {
1265 return;
1266 };
1267 let name = format!("{}.{}", self.text(operand), self.text(field));
1268 if !name.split('.').all(|part| {
1269 !part.is_empty() && part.chars().enumerate().all(|(i, c)| {
1270 c == '_' || c.is_ascii_alphabetic() || (i > 0 && c.is_ascii_digit())
1271 })
1272 }) { return; }
1273 let p = field.start_position();
1274 self.fn_ref_cands.push(Cand {
1275 from,
1276 name,
1277 line: p.row as u32 + 1,
1278 column_byte: field.start_byte(),
1279 row: p.row,
1280 node: container,
1281 });
1282 }
1283 "literal_element" | "expression_list" => {
1284 for i in 0..v.named_child_count() {
1285 if let Some(c) = v.named_child(i) {
1286 self.normalize_fn_ref_value(c, from, depth + 1, container);
1287 }
1288 }
1289 }
1290 _ => {}
1291 }

Callers 1

maybe_capture_fn_refsMethod · 0.45

Calls 4

pushMethod · 0.80
is_stoplistedFunction · 0.70
textMethod · 0.65
allMethod · 0.65

Tested by

no test coverage detected