|
| 1 | +# Relation API |
| 2 | + |
| 3 | +The Relation API allows finding all call chains (paths) that connect two specific symbols. This is useful for understanding how one part of the system interacts with another, validating architectural dependencies, or impact analysis. |
| 4 | + |
| 5 | +It leverages the [Call Hierarchy API](call_hierarchy.md) to trace paths. |
| 6 | + |
| 7 | +## RelationRequest |
| 8 | + |
| 9 | +| Field | Type | Default | Description | |
| 10 | +| :---------- | :-------------------- | :------- | :----------------------------------------- | |
| 11 | +| `source` | [`Locate`](locate.md) | Required | The starting symbol for the path search. | |
| 12 | +| `target` | [`Locate`](locate.md) | Required | The ending symbol for the path search. | |
| 13 | +| `max_depth` | `number` | `10` | Maximum depth to search for connections. | |
| 14 | + |
| 15 | +## RelationResponse |
| 16 | + |
| 17 | +| Field | Type | Description | |
| 18 | +| :---------- | :---------------------- | :-------------------------------------------------------------------------- | |
| 19 | +| `source` | `CallHierarchyItem` | The resolved source symbol. | |
| 20 | +| `target` | `CallHierarchyItem` | The resolved target symbol. | |
| 21 | +| `chains` | `CallHierarchyItem[][]` | List of paths connecting source to target. Each path is a sequence of items.| |
| 22 | +| `max_depth` | `number` | The maximum depth used for the search. | |
| 23 | + |
| 24 | +## Example Usage |
| 25 | + |
| 26 | +### Scenario 1: How does `handle_request` reach `db.query`? |
| 27 | + |
| 28 | +#### Request |
| 29 | + |
| 30 | +```json |
| 31 | +{ |
| 32 | + "source": { |
| 33 | + "file_path": "src/controllers.py", |
| 34 | + "scope": { |
| 35 | + "symbol_path": ["handle_request"] |
| 36 | + } |
| 37 | + }, |
| 38 | + "target": { |
| 39 | + "file_path": "src/db.py", |
| 40 | + "scope": { |
| 41 | + "symbol_path": ["query"] |
| 42 | + } |
| 43 | + }, |
| 44 | + "max_depth": 5 |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +#### Markdown Rendered for LLM |
| 49 | + |
| 50 | +```markdown |
| 51 | +# Relation: `handle_request` → `query` |
| 52 | + |
| 53 | +Found 2 call chain(s): |
| 54 | + |
| 55 | +### Chain 1 |
| 56 | +1. **handle_request** (`Function`) - `src/controllers.py` |
| 57 | +2. **UserService.get_user** (`Method`) - `src/services/user.py` |
| 58 | +3. **db.query** (`Function`) - `src/db.py` |
| 59 | + |
| 60 | +### Chain 2 |
| 61 | +1. **handle_request** (`Function`) - `src/controllers.py` |
| 62 | +2. **AuthService.validate_token** (`Method`) - `src/services/auth.py` |
| 63 | +3. **SessionManager.get_session** (`Method`) - `src/services/session.py` |
| 64 | +4. **db.query** (`Function`) - `src/db.py` |
| 65 | +``` |
0 commit comments