splice 2.6.4

Span-safe refactoring kernel for 7 languages with Magellan code graph integration
Documentation
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# Cross-File Rename Examples

This document provides comprehensive examples for using Splice's cross-file rename functionality across different programming languages and scenarios.

## Example 1: Simple Function Rename (Rust)

### Setup

Create test project:

```bash
mkdir rename_example && cd rename_example
cargo init --lib
```

**src/lib.rs:**
```rust
pub mod utils;

pub fn main() {
    utils::helper_function();
}
```

**src/utils.rs:**
```rust
pub fn helper_function() {
    println!("Helper called");
}

pub fn caller() {
    helper_function();
}
```

### Ingest and Rename

```bash
# Ingest codebase
splice ingest --root ./src --db .magellan/splice.db

# Find symbol
splice find --name "helper_function" --path "src/utils.rs"

# Output:
# Found symbol "helper_function" in src/utils.rs
# ID: 1a2b3c4d5e6f7g8h
# Kind: function
# Span: (0, 24)

# Preview rename
splice rename \
  --symbol 1a2b3c4d5e6f7g8h \
  --file src/utils.rs \
  --to new_helper_name \
  --preview

# Output:
# Will rename "helper_function" to "new_helper_name"
# Found 2 references:
#   src/lib.rs:3:10
#   src/utils.rs:7:5

# Perform rename
splice rename \
  --symbol 1a2b3c4d5e6f7g8h \
  --file src/utils.rs \
  --to new_helper_name
```

### Result

**src/lib.rs:**
```rust
pub mod utils;

pub fn main() {
    utils::new_helper_name();
}
```

**src/utils.rs:**
```rust
pub fn new_helper_name() {
    println!("Helper called");
}

pub fn caller() {
    new_helper_name();
}
```

## Example 2: Cross-Language Rename (Python)

### Setup

**main.py:**
```python
from utils import process_data

def main():
    result = process_data()
    return result
```

**utils.py:**
```python
def process_data():
    return "processed"

def another_function():
    data = process_data()
    return data
```

### Rename

```bash
# Ingest the project
splice ingest --root . --db .magellan/splice.db

# Find the symbol
splice find --name "process_data" --path "utils.py"

# Rename across all Python files
splice rename \
  --symbol <id> \
  --file utils.py \
  --to transform_data
```

### Result

Both `main.py` and `utils.py` will have `process_data` replaced with `transform_data` at all reference locations.

## Example 3: Rename with Proof

Generate a machine-checkable proof during rename for audit trail:

```bash
# Generate proof during rename
splice rename \
  --symbol <id> \
  --file src/utils.rs \
  --to new_name \
  --proof

# Proof written to .splice/proofs/rename-<timestamp>.json

# Validate proof later
splice validate-proof --proof .splice/proofs/rename-<timestamp>.json
```

### Proof Output

```json
{
  "metadata": {
    "operation": "rename",
    "timestamp": 1736035200,
    "splice_version": "2.4.0",
    "git_commit": "abc123..."
  },
  "before": {
    "symbols": {
      "1a2b3c4d5e6f7g8h": {
        "name": "helper_function",
        "file_path": "src/utils.rs",
        "kind": "function",
        "fan_in": 2,
        "fan_out": 1
      }
    }
  },
  "after": {
    "symbols": {
      "1a2b3c4d5e6f7g8h": {
        "name": "new_name",
        "file_path": "src/utils.rs",
        "kind": "function",
        "fan_in": 2,
        "fan_out": 1
      }
    }
  },
  "invariants": [
    {
      "invariant_name": "reference_count_preservation",
      "passed": true,
      "violations": []
    },
    {
      "invariant_name": "no_orphaned_symbols",
      "passed": true,
      "violations": []
    }
  ],
  "checksums": {
    "before_hash": "sha256:...",
    "after_hash": "sha256:...",
    "proof_hash": "sha256:..."
  }
}
```

## Example 4: Handling Ambiguity

When multiple symbols with the same name exist across different files:

### Scenario

You have `helper_function` in both `src/utils.rs` and `src/other.rs`.

```bash
splice rename \
  --symbol helper_function \
  --file src/utils.rs \
  --to new_helper_name
```

### Error Output

```
Error: Multiple symbols found
Please disambiguate:
  src/utils.rs:helper_function:function
  src/other.rs:helper_function:function

Use symbol ID instead:
splice rename \
  --symbol 1a2b3c4d5e6f7g8h \
  --file src/utils.rs \
  --to new_helper_name
```

### Solution

```bash
# Use the exact symbol ID from find command
splice find --name "helper_function" --path "src/utils.rs"

# Then rename with the ID
splice rename \
  --symbol 1a2b3c4d5e6f7g8h \
  --file src/utils.rs \
  --to new_helper_name
```

## Example 5: Batch Renames with Preview

Before performing multiple renames, use preview mode to verify changes:

```bash
# Preview all renames first
splice rename \
  --symbol func_a \
  --file src/lib.rs \
  --to function_a \
  --preview

# Review the diff output
# If satisfied, apply without --preview flag
splice rename \
  --symbol func_a \
  --file src/lib.rs \
  --to function_a
```

## Example 6: Rename in TypeScript Projects

### Setup

**src/utils.ts:**
```typescript
export function calculateTotal(price: number, tax: number): number {
    return price + tax;
}

export function displayTotal(total: number): void {
    console.log(`Total: ${total}`);
}
```

**src/main.ts:**
```typescript
import { calculateTotal, displayTotal } from './utils';

const total = calculateTotal(100, 10);
displayTotal(total);
```

### Rename

```bash
# Ingest TypeScript files
splice ingest --root ./src --db .magellan/splice.db

# Find and rename
splice find --name "calculateTotal" --path "src/utils.ts"
splice rename \
  --symbol <id> \
  --file src/utils.ts \
  --to computeTotal
```

### Result

Both the export in `utils.ts` and the import in `main.ts` are updated.

## Example 7: Rename Class Names (Java)

### Setup

**Calculator.java:**
```java
public class Calculator {
    public int add(int a, int b) {
        return a + b;
    }
}

**Main.java:**
```java
public class Main {
    public static void main(String[] args) {
        Calculator calc = new Calculator();
        System.out.println(calc.add(5, 3));
    }
}
```

### Rename

```bash
splice ingest --root . --db .magellan/splice.db
splice find --name "Calculator" --path "Calculator.java"
splice rename \
  --symbol <id> \
  --file Calculator.java \
  --to MathCalculator
```

## Example 8: CI/CD Integration

### GitHub Actions Workflow

```yaml
name: Rename Validation

on: [pull_request]

jobs:
  validate-rename:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Splice
        run: cargo install splice
      - name: Ingest codebase
        run: splice ingest --root ./src --db .magellan/splice.db
      - name: Preview rename
        run: |
          splice rename \
            --symbol old_name \
            --file src/lib.rs \
            --to new_name \
            --preview
      - name: Validate no breaking changes
        run: cargo check
```

## Common Workflows

### Finding Symbol IDs

```bash
# List all symbols in a file
splice query --db .magellan/splice.db --file src/lib.rs

# Find specific symbol by name
splice find --name "my_function" --path "src/lib.rs"

# Get references to understand impact
splice refs --symbol <id> --db .magellan/splice.db
```

### Impact Analysis Before Rename

```bash
# See what will be affected
splice reachable \
  --symbol my_function \
  --path src/lib.rs \
  --max-depth 3 \
  --db .magellan/splice.db

# Check for circular dependencies
splice cycles --db .magellan/splice.db
```

### Rollback After Failed Rename

If a rename causes issues, restore from backup:

```bash
# Backups are created automatically at:
# .splice/backups/rename-<timestamp>/

# Restore manually if needed
cp -r .splice/backups/rename-<timestamp>/src/* ./src/
```

## Troubleshooting

### UTF-8 Character Handling

Splice validates UTF-8 boundaries to ensure safe multi-byte character handling:

```bash
# Rename with special characters
splice rename \
  --symbol old_name \
  --file src/lib.rs \
  --to "new_name_with_special_chars"

# UTF-8 validation is automatic
```

### Large Codebases

For large projects, use reachability analysis first:

```bash
# Check impact scope before renaming
splice reachable \
  --symbol api_function \
  --path src/api.rs \
  --max-depth 10 \
  --db .magellan/splice.db

# If impact is large, consider phased approach
```

## See Also

- [docs/manual.md]../manual.md - Complete CLI reference
- [docs/examples/graph_algorithm_examples.md]graph_algorithm_examples.md - Impact analysis with graph algorithms
- [docs/examples/proof_examples.md]proof_examples.md - Proof-based refactoring