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

Method normalize_fn_ref_value

codegraph-kernel/src/go.rs:1215–1271  ·  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

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

Callers 1

maybe_capture_fn_refsMethod · 0.45

Calls 5

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

Tested by

no test coverage detected