Swift edits that tree-sitter wrongly flags as invalid are kept if swiftc -parse confirms their syntax, instead of being rolled back. The pre-edit content is now also run through swiftc when tree-sitter flags it invalid, so edits made after a compiler-confirmed original keep rollback protection.
Runs swiftc -parse (syntax only, no typechecking or imports) only when a Swift edit is flagged invalid by tree-sitter.
If swiftc accepts the edited content, the edit is kept; if it rejects or is unavailable, the existing rollback behavior is unchanged.
A tree-sitter-invalid original that swiftc accepts counts as valid, so a later invalid edit on it still rolls back; genuinely invalid or unconfirmable originals and new files keep the prior no-rollback behavior.
The parser lookup is cached, runs with a 5-second timeout, and falls back to xcrun --find swiftc on macOS.
Confidence Score: 5/5
The PR appears safe to merge; no blocking issue remains.
Summary
Swift edits rejected by tree-sitter are kept when swiftc -parse accepts them.
Swift edits tree-sitter rejects can stay when swiftc accepts their syntax.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Tree-sitter rejects Swift edit] --> B{Original known valid?}
B -->|No| C[Try compiler on existing original]
C --> D{Compiler accepts original?}
D -->|No| E[Keep prior no-rollback behavior]
D -->|Yes| F[Parse edited source with compiler]
B -->|Yes| F
F --> G{Compiler accepts edit?}
G -->|Yes| H[Keep edit]
G -->|No or unavailable| I[Restore original]