1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Edge extraction module for code relationships.
//!
//! This module provides language-specific extraction of code edges (relationships
//! between symbols) such as function calls, imports, and other dependencies.
//!
//! # Architecture
//!
//! - `extract_edges()` - Public API dispatcher by language
//! - `common` - Shared utilities for all extractors
//! - `typescript` - TypeScript/JavaScript call extraction
//!
//! # Usage
//!
//! ```no_run
//! use maproom::indexer::edges::{extract_edges, ChunkWithId};
//!
//! let source = "function foo() { bar(); }";
//! let chunks = vec![
//! ChunkWithId {
//! id: 1,
//! symbol_name: Some("foo".to_string()),
//! kind: "function".to_string(),
//! start_line: 1,
//! end_line: 1,
//! file_id: 100,
//! }
//! ];
//!
//! let edges = extract_edges(source, "typescript", &chunks)?;
//! # Ok::<(), anyhow::Error>(())
//! ```
use Result;
// Re-export Edge and EdgeType from edge_updater (shared types)
pub use crate;
/// Chunk with database ID (after insertion).
///
/// This struct represents a chunk that has been inserted into the database
/// and has a unique ID. It includes the file_id for Phase 2 cross-file resolution.
/// Extract edges from source code.
///
/// Dispatches to language-specific extractors based on the language parameter.
/// Returns an empty vector for unsupported languages (graceful degradation).
///
/// # Arguments
///
/// * `source` - Source code text
/// * `language` - Language identifier ("typescript", "tsx", "javascript", "jsx", etc.)
/// * `chunks` - Chunks with database IDs from the same file
///
/// # Returns
///
/// * `Ok(Vec<Edge>)` - Extracted edges (may be empty for unsupported languages)
/// * `Err(_)` - Critical failure (parsing error, etc.)
///
/// # Reused Types
///
/// This function reuses `Edge` and `EdgeType` from the `crate::incremental::edge_updater`
/// module. These types are made public in edge_updater.rs for shared use.
///
/// # Example
///
/// ```no_run
/// use maproom::indexer::edges::{extract_edges, ChunkWithId};
///
/// let source = "function foo() { bar(); }";
/// let chunks = vec![
/// ChunkWithId {
/// id: 1,
/// symbol_name: Some("foo".to_string()),
/// kind: "function".to_string(),
/// start_line: 1,
/// end_line: 1,
/// file_id: 100,
/// }
/// ];
///
/// let edges = extract_edges(source, "typescript", &chunks)?;
/// # Ok::<(), anyhow::Error>(())
/// ```