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

Function capture

codegraph-kernel/src/tsjs/fnref.rs:52–119  ·  view source on GitHub ↗

captureFnRefCandidates for the TS/JS spec. Returns (candidate, mode) pairs.

(container: Node, mode: Mode, src: &str)

Source from the content-addressed store, hash-verified

50
51/// captureFnRefCandidates for the TS/JS spec. Returns (candidate, mode) pairs.
52pub fn capture(container: Node, mode: Mode, src: &str) -> Vec<(Candidate, Mode)> {
53 let mut value_nodes: Vec<Node> = Vec::new();
54
55 match mode {
56 Mode::Args | Mode::List => {
57 for i in 0..container.named_child_count() {
58 if let Some(c) = container.named_child(i) {
59 value_nodes.push(c);
60 }
61 }
62 }
63 Mode::Rhs => {
64 if let Some(rhs) = container.child_by_field_name("right") {
65 // Param-storage skip: `this.status = status` — LHS's trailing
66 // identifier equals the RHS text ⇒ a stored local/parameter.
67 let lhs_text = container
68 .child_by_field_name("left")
69 .map(|l| &src[l.byte_range()])
70 .unwrap_or("");
71 let lhs_last = super::util::lhs_last_name()
72 .captures(lhs_text)
73 .and_then(|c| c.get(1))
74 .map(|m| m.as_str());
75 let rhs_text = src[rhs.byte_range()].trim();
76 if !(lhs_last.is_some() && lhs_last == Some(rhs_text)) {
77 value_nodes.push(rhs);
78 }
79 }
80 }
81 Mode::Value => {
82 if let Some(v) = container.child_by_field_name("value") {
83 value_nodes.push(v);
84 }
85 }
86 Mode::VarInit => {
87 // Destructuring extracts DATA, never a function alias.
88 let name_node = container.child_by_field_name("name");
89 let is_pattern = name_node
90 .map(|n| matches!(n.kind(), "object_pattern" | "array_pattern"))
91 .unwrap_or(false);
92 if !is_pattern {
93 if let Some(v) = container.child_by_field_name("value") {
94 value_nodes.push(v);
95 }
96 }
97 }
98 }
99
100 let mut out = Vec::new();
101 for v in value_nodes {
102 for (name, node) in normalize(v, src) {
103 if name.is_empty() || stoplisted(&name) {
104 continue;
105 }
106 let p = node.start_position();
107 out.push((
108 Candidate {
109 name,

Callers 2

maybe_capture_fn_refsMethod · 0.70

Calls 5

stoplistedFunction · 0.85
pushMethod · 0.80
mapMethod · 0.80
normalizeFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected