Skip to content

Incorrect Indentation When Formatting Injected SQL #421

@xterao

Description

@xterao

Describe the bug
When code formatting is executed on SQL injected via the @SQL annotation, the base indentation of the SQL ends up further to the right than expected.

Example (before formatting):

@Select
@Sql(
    """
       SELECT *
            FROM emp
           WHERE id = /* employee.employeeId */0
       """)
Employee selectInjection(Employee employee);

After formatting (current behavior):

@Select
@Sql(
    """
          SELECT *
            FROM emp
           WHERE id = /* employee.employeeId */0
          """)
Employee selectInjection(Employee employee);

Problem
The SQL is indented too far, because the formatter is applying extra spaces beyond the expected base indentation.

Expected behavior
The SQL should be formatted with its base indentation calculated as:

  • The current indent size, plus
  • The indentation width of @SQL("""
  • This ensures that injected SQL aligns correctly with the annotation’s starting point.

Screenshots

Image Image

Desktop :

  • IDEA Version 2024.3.6
  • Doma Tools Version 2.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions