Skip to content

Add formatter options to format multiple parameters with new lines #2483

Open

Description

@slezhnin

I'd like my code to be formatted with new lines for annotation, constructor or method call or declaration with multiple parameters.

For instance:

@Parameter(
    in = ParameterIn.PATH,
    name = "resourceName",
    description = "Resource Name",
    required = true,
    example = "1",
    schema = @Schema(type = SchemaType.STRING, minLength = 1)
)

Current formatter makes a one-liner like this:

@Parameter(in = ParameterIn.PATH, name = "resourceName", description = "Resource Name", required = true, example = "1", schema = @Schema(type = SchemaType.STRING, minLength = 1))

So the formatter should insert new line after the opening brace and comma and before the closing brace.

Environment
  • Operating System: MacOs Monterey 12.3
  • JDK version: openjdk version "11.0.15" 2022-04-19
  • Visual Studio Code version: 1.67.2
  • Java extension version: v1.6.0
Steps To Reproduce
  1. Add annotation with multiple parameters
  2. Format the code
  3. In my current formatter version it should compact it to one line
Current Result
@Parameter(in = ParameterIn.PATH, name = "resourceName", description = "Resource Name", required = true, example = "1", schema = @Schema(type = SchemaType.STRING, minLength = 1))
Expected Result
@Parameter(
    in = ParameterIn.PATH,
    name = "resourceName",
    description = "Resource Name",
    required = true,
    example = "1",
    schema = @Schema(type = SchemaType.STRING, minLength = 1)
)

Activity

  1. changed the title [-]Add formatter options to format parameters with new lines[/-] [+]Add formatter options to format multiple parameters with new lines[/+] on May 30, 2022
  2. rgrunber commented on May 31, 2022

    @rgrunber
    Member

    You could try what's referenced in eclipse-jdtls/eclipse.jdt.ls#1717 (comment) . There are many different formatting options supported.

    I found that I needed to set it to org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=49 (instead of 48) to force the setting. Otherwise it's optional.

    You could also create your own formatter as described in https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings . The option would be <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="49"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions