MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / scope

Function scope

atomic-semantic/src/source.rs:222–248  ·  view source on GitHub ↗
(mut node: Node<'_>, source: &str)

Source from the content-addressed store, hash-verified

220}
221
222fn scope(mut node: Node<'_>, source: &str) -> (Vec<String>, Option<String>) {
223 let (mut parts, mut receiver) = (Vec::new(), None);
224 let mut nested_function = false;
225 while let Some(parent) = node.parent() {
226 if let Some(name) = owner(parent, source) {
227 if receiver.is_none() && !nested_function {
228 receiver = Some(name.clone());
229 }
230 parts.push(name);
231 } else if callable(parent)
232 || matches!(
233 parent.kind(),
234 "mod_item" | "namespace_definition" | "internal_module"
235 )
236 {
237 if let Some(name) = parent.child_by_field_name("name") {
238 parts.push(text(name, source).into());
239 }
240 if callable(parent) {
241 nested_function = true;
242 }
243 }
244 node = parent;
245 }
246 parts.reverse();
247 (parts, receiver)
248}
249
250fn module_scope(mut node: Node<'_>, source: &str) -> Vec<String> {
251 let mut parts = Vec::new();

Calls 8

parentMethod · 0.80
is_noneMethod · 0.80
ownerFunction · 0.70
callableFunction · 0.70
textFunction · 0.70
cloneMethod · 0.45
pushMethod · 0.45
reverseMethod · 0.45