Build a function signature string.
(&self, node: &Node, source: &str)
| 284 | |
| 285 | /// Build a function signature string. |
| 286 | fn build_function_signature(&self, node: &Node, source: &str) -> Option<String> { |
| 287 | let name_node = node.child_by_field_name("name")?; |
| 288 | let name = self.node_text(&name_node, source); |
| 289 | |
| 290 | // Check if async |
| 291 | let is_async = node |
| 292 | .parent() |
| 293 | .map(|p| { |
| 294 | let mut cursor = p.walk(); |
| 295 | let children: Vec<_> = p.children(&mut cursor).collect(); |
| 296 | children |
| 297 | .iter() |
| 298 | .any(|c| c.kind() == "async" || self.node_text(c, source) == "async") |
| 299 | }) |
| 300 | .unwrap_or(false) |
| 301 | || { |
| 302 | let mut cursor = node.walk(); |
| 303 | let children: Vec<_> = node.children(&mut cursor).collect(); |
| 304 | children |
| 305 | .iter() |
| 306 | .any(|c| self.node_text(c, source) == "async") |
| 307 | }; |
| 308 | |
| 309 | let params = node |
| 310 | .child_by_field_name("parameters") |
| 311 | .map(|n| self.node_text(&n, source)) |
| 312 | .unwrap_or_else(|| "()".to_string()); |
| 313 | |
| 314 | let return_type = node |
| 315 | .child_by_field_name("return_type") |
| 316 | .map(|n| format!(" -> {}", self.node_text(&n, source))); |
| 317 | |
| 318 | let prefix = if is_async { "async def" } else { "def" }; |
| 319 | |
| 320 | Some(format!( |
| 321 | "{} {}{}{}", |
| 322 | prefix, |
| 323 | name, |
| 324 | params, |
| 325 | return_type.unwrap_or_default() |
| 326 | )) |
| 327 | } |
| 328 | |
| 329 | /// Build a class signature string. |
| 330 | fn build_class_signature(&self, node: &Node, source: &str) -> Option<String> { |