Extract a using directive as a Use node.
(state: &mut ExtractionState, node: TsNode<'_>)
| 242 | |
| 243 | /// Extract a using directive as a Use node. |
| 244 | fn visit_using(state: &mut ExtractionState, node: TsNode<'_>) { |
| 245 | let text = state.node_text(node); |
| 246 | // Strip "using " prefix and trailing ";" |
| 247 | let path = text |
| 248 | .trim() |
| 249 | .strip_prefix("using ") |
| 250 | .unwrap_or(&text) |
| 251 | .trim() |
| 252 | .strip_prefix("static ") |
| 253 | .unwrap_or(text.trim().strip_prefix("using ").unwrap_or(&text).trim()) |
| 254 | .trim_end_matches(';') |
| 255 | .trim() |
| 256 | .to_string(); |
| 257 | |
| 258 | let start_line = node.start_position().row as u32; |
| 259 | let end_line = node.end_position().row as u32; |
| 260 | let start_column = node.start_position().column as u32; |
| 261 | let end_column = node.end_position().column as u32; |
| 262 | let qualified_name = format!("{}::{}", state.qualified_prefix(), path); |
| 263 | let id = generate_node_id(&state.file_path, &NodeKind::Use, &path, start_line); |
| 264 | |
| 265 | let graph_node = Node { |
| 266 | id: id.clone(), |
| 267 | kind: NodeKind::Use, |
| 268 | name: path.clone(), |
| 269 | qualified_name, |
| 270 | file_path: state.file_path.clone(), |
| 271 | start_line, |
| 272 | attrs_start_line: start_line, |
| 273 | end_line, |
| 274 | start_column, |
| 275 | end_column, |
| 276 | signature: Some(text.trim().to_string()), |
| 277 | docstring: None, |
| 278 | visibility: Visibility::Private, |
| 279 | is_async: false, |
| 280 | branches: 0, |
| 281 | loops: 0, |
| 282 | returns: 0, |
| 283 | max_nesting: 0, |
| 284 | unsafe_blocks: 0, |
| 285 | unchecked_calls: 0, |
| 286 | assertions: 0, |
| 287 | updated_at: state.timestamp, |
| 288 | parent_id: None, |
| 289 | }; |
| 290 | state.nodes.push(graph_node); |
| 291 | |
| 292 | // Contains edge from parent. |
| 293 | if let Some(parent_id) = state.parent_node_id() { |
| 294 | state.edges.push(Edge { |
| 295 | source: parent_id.to_string(), |
| 296 | target: id.clone(), |
| 297 | kind: EdgeKind::Contains, |
| 298 | line: Some(start_line), |
| 299 | }); |
| 300 | } |
| 301 |
nothing calls this directly
no test coverage detected