- The tool uses 1-based line numbering (not 0-based)
- Always verify line numbers match exactly what's in the file
- When in doubt, use
Readormcp__language-server__hoverto confirm
- The tool is sensitive to whitespace and indentation
- Copy indentation exactly as it appears in the original
- Don't add or remove blank lines unless intentional
When making multiple edits to the same file:
- Edits are applied sequentially from top to bottom
- Later edits must account for line number changes from earlier edits
- Consider using multiple separate edit calls for complex changes
- Problem: Accidentally included duplicate lines or sections
- Solution: Always check the exact range being replaced
- Example: If replacing lines 10-15, make sure not to include line 16
- Problem: Removed necessary closing braces or delimiters
- Solution: Always include complete logical blocks in edits
- Example: When editing a function, include both opening and closing braces
- Problem: Edit ranges were off by one or more lines
- Solution: Use
Readwith line numbers to verify exact positions - Better: Use
mcp__language-server__hoverfor precise location info
{
"startLine": 10,
"endLine": 10,
"newText": "single line replacement"
}{
"startLine": 20,
"endLine": 30,
"newText": "multi-line\nreplacement\ntext"
}- To insert after line N: use startLine: N+1, endLine: N
- To insert at beginning: use startLine: 1, endLine: 0
Use Edit or MultiEdit instead when:
- Making string-based replacements
- Need to ensure unique matches
- Working with smaller, targeted changes
Use Write when:
- Rewriting entire files
- File structure is completely broken
- Starting fresh is cleaner than many edits
When edits fail or produce unexpected results:
- Read the specific section with line numbers
- Verify the exact content and formatting
- Check for:
- Unclosed delimiters
- Missing imports
- Duplicate definitions
- Syntax errors in the newText
The LSP tools provide:
- Real-time diagnostics to catch errors early
- Hover information for type checking
- Reference finding before refactoring
- Symbol renaming across files
But remember:
- LSP edits are line-based, not AST-based
- Syntax errors can break LSP functionality
- Always verify edits with
cargo checkor equivalent
- Module definitions: Be careful not to duplicate
pub modstatements - Struct fields: Watch for duplicate field definitions when merging edits
- Import statements: Use the correct import style (
use sqlx::types::chrono) - Feature gates: Ensure optional dependencies are properly gated
- Error types: Check that custom error types are properly defined before use
When files get badly mangled (like happened with config.rs and db.rs):
- Start with
Writeto create a clean version - Use
cargo checkto identify all issues - Fix systematically from top to bottom
- Group related fixes together
- Test frequently with
cargo check