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

Method build_function_signature

atomic-semantic/src/parsers/swift.rs:431–471  ·  view source on GitHub ↗

Build `func name(params) -> ReturnType`.

(&self, node: &Node, source: &str)

Source from the content-addressed store, hash-verified

429
430 /// Build `func name(params) -> ReturnType`.
431 fn build_function_signature(&self, node: &Node, source: &str) -> Option<String> {
432 // Try named field, fall back to first simple_identifier
433 let name = if let Some(n) = node.child_by_field_name("name") {
434 self.node_text(&n, source)
435 } else {
436 self.find_first_simple_identifier(node, source)?
437 };
438
439 // Try named field for params, fall back to first parenthesized group
440 let params = if let Some(p) = node.child_by_field_name("parameters") {
441 self.node_text(&p, source)
442 } else {
443 let mut found = "()".to_string();
444 let mut c = node.walk();
445 for child in node.children(&mut c) {
446 let text = self.node_text(&child, source);
447 if text.starts_with('(') {
448 found = text;
449 break;
450 }
451 }
452 found
453 };
454
455 // function_result is a child node (not a named field) containing `-> Type`
456 let mut return_type: Option<String> = None;
457 let mut c = node.walk();
458 for child in node.children(&mut c) {
459 if child.kind() == "function_result" {
460 return_type = Some(format!(" {}", self.node_text(&child, source).trim()));
461 break;
462 }
463 }
464
465 Some(format!(
466 "func {}{}{}",
467 name,
468 params,
469 return_type.unwrap_or_default()
470 ))
471 }
472
473 /// Build `init(params)` (with optional `?`/`!` for failable initializers).
474 fn build_init_signature(&self, node: &Node, source: &str) -> Option<String> {

Callers 1

extract_functionMethod · 0.45

Calls 5

walkMethod · 0.80
childrenMethod · 0.80
node_textMethod · 0.45
kindMethod · 0.45

Tested by

no test coverage detected