codelens_engine/call_graph/
queries.rs1pub(super) const PYTHON_FUNC_QUERY: &str = r#"
2(function_definition name: (identifier) @func.name) @func.def
3"#;
4
5pub(super) const PYTHON_CALL_QUERY: &str = r#"
6(call function: (identifier) @callee)
7(call function: (attribute attribute: (identifier) @callee))
8(decorator (identifier) @callee)
9(decorator (call function: (identifier) @callee))
10(decorator (attribute attribute: (identifier) @callee))
11(decorator (call function: (attribute attribute: (identifier) @callee)))
12;; v1.11.1 (F1 follow-up): function-reference arguments. Python
13;; callback patterns include `register("evt", handler)`,
14;; `dispatcher.on(name, callback)`, `signal.connect(slot)`, plus
15;; decorator factories like `@retry(handler)`. The 6-stage
16;; resolution cascade filters identifier-arg captures against the
17;; project symbol DB; variable arguments fall to `unresolved` and
18;; genuine function references resolve via Stage 5 (`unique_name`)
19;; at confidence 0.5.
20(call arguments: (argument_list (identifier) @callee))
21(call arguments: (argument_list (attribute attribute: (identifier) @callee)))
22"#;
23
24pub(super) const JS_FUNC_QUERY: &str = r#"
25(function_declaration name: (identifier) @func.name) @func.def
26(method_definition name: (property_identifier) @func.name) @func.def
27(lexical_declaration
28 (variable_declarator
29 name: (identifier) @func.name
30 value: [(arrow_function) (function_expression)] @func.def))
31(variable_declaration
32 (variable_declarator
33 name: (identifier) @func.name
34 value: [(arrow_function) (function_expression)] @func.def))
35"#;
36
37pub(super) const JS_CALL_QUERY: &str = r#"
38(call_expression function: (identifier) @callee)
39(call_expression
40 function: (member_expression
41 object: (_) @callee.object
42 property: (property_identifier) @callee))
43;; v1.11.1 (F1 follow-up): function-reference arguments. JS/TS frequently
44;; pass functions as callbacks — `setTimeout(handler, 100)`,
45;; `arr.map(parseLine)`, `bus.on("evt", onEvent)`, `.then(success)`.
46;; The 6-stage resolution cascade in `resolve_call_edges` filters these
47;; against the symbol DB, so variable arguments fall to `unresolved`
48;; while genuine function references resolve via Stage 5
49;; (`unique_name`) at confidence 0.5.
50(arguments (identifier) @callee)
51(arguments
52 (member_expression
53 object: (_) @callee.object
54 property: (property_identifier) @callee))
55"#;
56
57pub(super) const JS_JSX_CALL_QUERY: &str = r#"
61(call_expression function: (identifier) @callee)
62(call_expression
63 function: (member_expression
64 object: (_) @callee.object
65 property: (property_identifier) @callee))
66(jsx_self_closing_element name: (identifier) @callee)
67(jsx_opening_element name: (identifier) @callee)
68(jsx_self_closing_element
69 name: (member_expression
70 object: (_) @callee.object
71 property: (property_identifier) @callee))
72(jsx_opening_element
73 name: (member_expression
74 object: (_) @callee.object
75 property: (property_identifier) @callee))
76;; v1.11.1: same function-reference patterns as JS_CALL_QUERY.
77(arguments (identifier) @callee)
78(arguments
79 (member_expression
80 object: (_) @callee.object
81 property: (property_identifier) @callee))
82"#;
83
84pub(super) const GO_FUNC_QUERY: &str = r#"
85(function_declaration name: (identifier) @func.name) @func.def
86(method_declaration name: (field_identifier) @func.name) @func.def
87"#;
88
89pub(super) const GO_CALL_QUERY: &str = r#"
90(call_expression function: (identifier) @callee)
91(call_expression function: (selector_expression field: (field_identifier) @callee))
92;; v1.11.2 (F1 follow-up): function-reference arguments in Go.
93;; Catches `http.HandleFunc("/", handler)`, `time.AfterFunc(d, callback)`,
94;; `runtime.SetFinalizer(p, finalizer)`, and worker-pool dispatch
95;; patterns where a function value is passed by name. Same resolution
96;; cascade gating: variable arguments fall to `unresolved`, named
97;; functions resolve via Stage 5 (`unique_name`) at confidence 0.5.
98(argument_list (identifier) @callee)
99(argument_list (selector_expression field: (field_identifier) @callee))
100"#;
101
102pub(super) const JAVA_FUNC_QUERY: &str = r#"
103(method_declaration name: (identifier) @func.name) @func.def
104(constructor_declaration name: (identifier) @func.name) @func.def
105"#;
106
107pub(super) const JAVA_CALL_QUERY: &str = r#"
108(method_invocation name: (identifier) @callee)
109(object_creation_expression type: (type_identifier) @callee)
110(method_reference (identifier) @callee)
111;; v1.11.2 (F1 follow-up): function-reference arguments in Java/Kotlin
112;; that are passed as bare identifiers (callbacks, executor.submit
113;; targets) rather than the explicit `Class::method` reference syntax
114;; already covered above. The same query is shared with Kotlin via
115;; the `KOTLIN_FUNC_QUERY` mapping; tree-sitter-kotlin reuses
116;; `argument_list` node names for the call grammar so the pattern
117;; below applies to Kotlin call sites as well.
118(method_invocation arguments: (argument_list (identifier) @callee))
119(method_invocation arguments: (argument_list (field_access field: (identifier) @callee)))
120"#;
121
122pub(super) const KOTLIN_FUNC_QUERY: &str = r#"
123(function_declaration (identifier) @func.name) @func.def
124"#;
125
126pub(super) const KOTLIN_CALL_QUERY: &str = r#"
127;; Direct call: prepare()
128(call_expression (identifier) @callee)
129
130;; Method/navigation call: exec.submit(...) — last identifier in
131;; navigation_expression is the method name (anchor `.` selects last child).
132(call_expression
133 (navigation_expression
134 (identifier) @callee .))
135
136;; v1.12.3: function-reference arguments — submit(onTick),
137;; register("err", onError). Same noise-filter behavior as Rust:
138;; non-function identifiers (variables) are dropped at resolution time.
139(call_expression
140 (value_arguments
141 (value_argument
142 (identifier) @callee)))
143
144;; v1.12.4 (Codex P1): Kotlin callable references.
145;; - bare form `::onTick` parses as
146;; value_argument > callable_reference > identifier.
147;; - qualified form `this::onTick` parses as
148;; value_argument > navigation_expression(`::`) > identifier
149;; (tree-sitter-kotlin-ng folds the `::` token into a
150;; navigation_expression rather than a dedicated callable_reference
151;; node). Both shapes are common in Executor / event-bus callbacks.
152(call_expression
153 (value_arguments
154 (value_argument
155 (callable_reference (identifier) @callee))))
156
157(call_expression
158 (value_arguments
159 (value_argument
160 (navigation_expression (identifier) @callee .))))
161"#;
162
163pub(super) const RUST_FUNC_QUERY: &str = r#"
164(function_item name: (identifier) @func.name) @func.def
165"#;
166
167pub(super) const RUST_CALL_QUERY: &str = r#"
168(call_expression function: (identifier) @callee)
169(call_expression function: (field_expression field: (field_identifier) @callee))
170(call_expression function: (scoped_identifier name: (identifier) @callee))
171(macro_invocation macro: (identifier) @callee)
172(macro_invocation macro: (scoped_identifier name: (identifier) @callee))
173;; v1.11.0 (F1): function-reference patterns. A function passed as an
174;; argument (closure construction, callback registration, builder
175;; accumulators) is a real caller→callee edge that the call_expression
176;; rules above miss. Examples:
177;; LazyLock::new(build_tools)
178;; OnceCell::get_or_init(make_state)
179;; iter.map(parse_line).collect()
180;; bus.register("evt", on_event)
181;; Many argument identifiers are variables, not functions. The
182;; resolution cascade in `resolve_call_edges` filters those: the name
183;; must exist in the symbol DB or the edge is dropped as `unresolved`
184;; (confidence 0). Genuine function references resolve via Stage 5
185;; (unique_name) at confidence 0.5 — honest, lower than import_map but
186;; higher than nothing.
187(arguments (identifier) @callee)
188(arguments (scoped_identifier name: (identifier) @callee))
189"#;