Extract a function definition.
(
&self,
node: &Node,
source: &str,
file_path: &str,
scope: Option<&str>,
in_class: bool,
)
| 223 | |
| 224 | /// Extract a function definition. |
| 225 | fn extract_function( |
| 226 | &self, |
| 227 | node: &Node, |
| 228 | source: &str, |
| 229 | file_path: &str, |
| 230 | scope: Option<&str>, |
| 231 | in_class: bool, |
| 232 | ) -> Option<Entity> { |
| 233 | let declarator = node.child_by_field_name("declarator")?; |
| 234 | let (name, is_scoped) = self.extract_function_name(&declarator, source); |
| 235 | let name = name?; |
| 236 | |
| 237 | if name.is_empty() { |
| 238 | return None; |
| 239 | } |
| 240 | |
| 241 | let line = node.start_position().row as u32 + 1; |
| 242 | let end_line = node.end_position().row as u32 + 1; |
| 243 | |
| 244 | // A function is a Method if: |
| 245 | // - it has a qualified name (e.g. ClassName::method), or |
| 246 | // - it's defined inside a class/struct body (in_class == true) |
| 247 | let kind = if is_scoped || in_class { |
| 248 | EntityKind::Method |
| 249 | } else { |
| 250 | EntityKind::Function |
| 251 | }; |
| 252 | |
| 253 | let signature = self.build_function_signature(node, source); |
| 254 | |
| 255 | // If the function has a qualified name (e.g., ClassName::method), use it |
| 256 | // directly. Otherwise, prepend the scope if we're inside a class body. |
| 257 | let full_name = if name.contains("::") { |
| 258 | name |
| 259 | } else if let Some(s) = scope { |
| 260 | format!("{}::{}", s, name) |
| 261 | } else { |
| 262 | name |
| 263 | }; |
| 264 | |
| 265 | let mut entity = Entity::new(full_name, kind, file_path, line, end_line); |
| 266 | if let Some(sig) = signature { |
| 267 | entity = entity.with_signature(sig); |
| 268 | } |
| 269 | // C/C++ doesn't have a simple export convention; default to true for |
| 270 | // non-static functions. For simplicity, mark all extracted entities |
| 271 | // as exported. |
| 272 | entity.exported = true; |
| 273 | |
| 274 | Some(entity) |
| 275 | } |
| 276 | |
| 277 | /// Extract the function name from a declarator node. |
| 278 | /// |
no test coverage detected