Skip to content

Remove redundant parentheses code action #2451

@PhantomInTheWire

Description

@PhantomInTheWire

Description

I Propose adding a code action to remove redundant parentheses in Swift expressions.

Originally discussed here:
#2406 (comment)

Although it was originally discussed as a improvement to the existing demorgan implementation. I figured this was something that could be more generalized.

The action would detect parentheses that do not affect meaning and safely remove them, improving readability while preserving operator precedence and evaluation order.

Example:

Before:

let x = (a + b)
let y = ((foo()))

After:

let x = a + b
let y = foo()

Open question: should the core detection logic live in swift-syntax so it can be reused by other tools(formatters or linters maybe), or should this be implemented locally in SourceKit-LSP?

If so i think this can be broken down into a couple PRs.

  1. Implement the core upstream in swift-syntax
  2. Use that in demorgan implemenation in sourcekit-lsp
  3. Make a full code action for it in sourcekit-lsp

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions