Extract a LET statement as a Const node.
(state: &mut ExtractionState, basic_line: &BasicLine<'_>)
| 233 | |
| 234 | /// Extract a LET statement as a Const node. |
| 235 | fn visit_let_statement(state: &mut ExtractionState, basic_line: &BasicLine<'_>) { |
| 236 | let Some(statement_list) = find_direct_child_by_kind(basic_line.node, "statement_list") |
| 237 | else { |
| 238 | return; |
| 239 | }; |
| 240 | let Some(statement) = find_direct_child_by_kind(statement_list, "statement") else { |
| 241 | return; |
| 242 | }; |
| 243 | let Some(let_stmt) = find_direct_child_by_kind(statement, "let_statement") else { |
| 244 | return; |
| 245 | }; |
| 246 | |
| 247 | // Extract the variable name from: let_statement -> variable -> identifier |
| 248 | let Some(var_node) = find_direct_child_by_kind(let_stmt, "variable") else { |
| 249 | return; |
| 250 | }; |
| 251 | let Some(id_node) = find_direct_child_by_kind(var_node, "identifier") else { |
| 252 | return; |
| 253 | }; |
| 254 | let name = state.node_text(id_node); |
| 255 | |
| 256 | let start_line = basic_line.node.start_position().row as u32; |
| 257 | let end_line = basic_line.node.end_position().row as u32; |
| 258 | let start_column = basic_line.node.start_position().column as u32; |
| 259 | let end_column = basic_line.node.end_position().column as u32; |
| 260 | let qualified_name = format!("{}::{}", state.qualified_prefix(), name); |
| 261 | let id = generate_node_id(&state.file_path, &NodeKind::Const, &name, start_line); |
| 262 | let text = state.node_text(basic_line.node); |
| 263 | |
| 264 | let graph_node = Node { |
| 265 | id: id.clone(), |
| 266 | kind: NodeKind::Const, |
| 267 | name, |
| 268 | qualified_name, |
| 269 | file_path: state.file_path.clone(), |
| 270 | start_line, |
| 271 | attrs_start_line: start_line, |
| 272 | end_line, |
| 273 | start_column, |
| 274 | end_column, |
| 275 | signature: Some(text.trim().to_string()), |
| 276 | docstring: None, |
| 277 | visibility: Visibility::Pub, |
| 278 | is_async: false, |
| 279 | branches: 0, |
| 280 | loops: 0, |
| 281 | returns: 0, |
| 282 | max_nesting: 0, |
| 283 | unsafe_blocks: 0, |
| 284 | unchecked_calls: 0, |
| 285 | assertions: 0, |
| 286 | updated_at: state.timestamp, |
| 287 | parent_id: None, |
| 288 | }; |
| 289 | state.nodes.push(graph_node); |
| 290 | |
| 291 | // Contains edge from parent. |
| 292 | if let Some(parent_id) = state.parent_node_id() { |
nothing calls this directly
no test coverage detected