sourcekit-lsp icon indicating copy to clipboard operation
sourcekit-lsp copied to clipboard

Add CodeAction to invert if condition and swap branches

Open PhantomInTheWire opened this issue 1 month ago • 2 comments

Description

SourceKit-LSP lacks a refactoring to invert a negated if condition while preserving semantics. I propose a syntax-only refactor that rewrites:

if !cond {
  thenBranch()
} else {
  elseBranch()
}

into:

if cond {
  elseBranch()
} else {
  thenBranch()
}

The refactoring should only apply when the condition is syntactically negated and an else branch exists.

PhantomInTheWire avatar Jan 01 '26 08:01 PhantomInTheWire